<?php
session_start();

include ("conexion.php");


if ($conectado->connect_error) {
    die("Error de conexi贸n: " . $conectado->connect_error);
}
function eliminarmsj($id) {
    global $conectado;
    $query = "DELETE FROM contactos WHERE id = '$id'";
    $conectado->query($query);
    // Redireccionar a la página actual después de eliminar la factura
    header("Location: ".$_SERVER['PHP_SELF']);
    exit();
}
if(isset($_POST['eliminar_factura'])) {
    eliminarmsj($_POST['factura_id']);
}

$query = $conectado->prepare("SELECT * FROM contactos");
$query->execute();
$result = $query->get_result();

$datos = [];

if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $datos[] = $row;
    }
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Editar Registro</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/css/uikit.min.css" />
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit.min.js"></script>
    <link rel="stylesheet" type="text/css" href="Estilos/index.css">
    <script src="https://unpkg.com/feather-icons"></script>
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" 
    integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/uikit@3.18.1/dist/js/uikit-icons.min.js"></script>
    <style>
        .klk{
            margin-top: 150px;
        }

        .chat-icon {
    position: fixed;
    bottom: 20px; /* Distancia desde la parte inferior */
    right: 20px; /* Distancia desde el lado derecho */
    background-color: #3056C4;
    color: #ffffff;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    transition: transform 0.3s ease;
}

.chat-icon:hover {
    transform: scale(1.1); /* Efecto de escala al pasar el mouse */
}
    </style>
</head>
<body>
    <?php include "menu2.php";?>
    <div class="uk-container uk-margin-top uk-margin-bottom">
        <div class="uk-card uk-card-body">
            <h3 class="uk-card-title uk-text-center klk">Mensajes y opiniones:</h3>
            <div class="uk-grid uk-child-width-1-1@s uk-child-width-1-2@m uk-child-width-1-3@l uk-margin-large-top" uk-grid>
                <?php foreach($datos as $row): ?>
                    <div>
                        <div class="uk-card uk-card-default uk-card-body">
                            <h4 class="uk-card-title"><?php echo $row["nombre"]; ?></h4>
                            <p><?php echo $row["email"]; ?></p>
                          
                            <p><?php echo $row["asunto"]; ?></p>
                            <form method="post">
                                <input type="hidden" name="factura_id" value="<?php echo $row['id']; ?>">
                                <button type="submit" name="eliminar_factura" class="uk-button uk-button-danger">Eliminar Factura</button>
                            </form>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
    <div class="chat-icon">
    <?php include("boticon.php") ?>
    </div>
</body>
</html>