<?php
declare(strict_types=1);

require_once __DIR__ . '/sesion.php';
require_once __DIR__ . '/concha.php';

if (!isset($conn) || !($conn instanceof mysqli)) {
    die('Error: la conexión $conn no está definida correctamente en concha.php');
}

$ID = isset($_GET['ID']) ? (int) $_GET['ID'] : 0;
$eliminado = false;
$error = '';

if ($ID > 0) {
    $stmt = $conn->prepare("DELETE FROM menu WHERE ID = ? LIMIT 1");

    if ($stmt) {
        $stmt->bind_param('i', $ID);

        if ($stmt->execute()) {
            $eliminado = ($stmt->affected_rows > 0);
            if (!$eliminado) {
                $error = 'No se encontró el botón de menú a eliminar.';
            }
        } else {
            $error = 'No se pudo ejecutar la eliminación.';
        }

        $stmt->close();
    } else {
        $error = 'No se pudo preparar la consulta.';
    }
} else {
    $error = 'ID inválido.';
}
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="utf-8">
    <meta name="description" content="Panel de Administracion">
    <meta name="author" content="<?php echo htmlspecialchars($nombresitio ?? '', ENT_QUOTES, 'UTF-8'); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title><?php echo htmlspecialchars($nombresitio ?? '', ENT_QUOTES, 'UTF-8'); ?> - Panel de Administracion</title>

    <link href="https://fonts.googleapis.com/css?family=Oswald" rel="stylesheet" type="text/css">
    <link rel="shortcut icon" href="" type="image/x-icon">
    <link rel="apple-touch-icon" href="">

    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <link rel="stylesheet" href="">
    <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>

    <style type="text/css">
        *{
            border-radius: 0 !important;
        }

        body{
            background-image: url(../fondeux.jpg);
        }

        .navbar{
            position: relative;
            min-height: 50px;
            padding-bottom: 20px;
        }

        .btn-primary{
            color: #fff !important;
            background-color: #0066FF;
            border-color: #0066FF;
        }

        .page-header{
            margin: 0;
            padding: 1em;
            background-color: #0066FF;
            border: 0;
            text-align: center;
        }

        .page-header h2{
            color: #ffffff;
            font-weight: bold;
            margin: 0;
        }

        .bloqueAzul{
            text-align: center;
        }

        .bloqueAzul .div{
            border: 1px solid #e4e4e4;
            background-color: #fff;
        }

        ul{
            list-style: none;
            padding: 0;
        }

        .far,
        .faso{
            color: #0066FF;
        }

        .colorAzul h3{
            color: #0066FF;
        }
    </style>

    <script>
        function ventanaSecundaria(URL){
            window.open(URL, "ventana1", "width=550,height=450,scrollbars=NO");
        }
    </script>
</head>
<body>

<div class="container" style="background-color:#F1F2ED;max-width:960px;">
    <?php include 'menu.php'; ?>
</div>

<div role="main" style="background-color:#fff;max-width:960px;" class="container pt-3">
    <div class="page-header" style="text-align:center;">
        <h2><?php echo htmlspecialchars($idioma_100778 ?? 'Eliminar botón del menú', ENT_QUOTES, 'UTF-8'); ?></h2>
    </div>

    <div class="row">
        <div class="col-12 text-center p-3">
            <?php if ($eliminado): ?>
                <h3><?php echo htmlspecialchars($idioma_100779 ?? 'Botón eliminado correctamente', ENT_QUOTES, 'UTF-8'); ?></h3>
            <?php else: ?>
                <h3><?php echo htmlspecialchars($error, ENT_QUOTES, 'UTF-8'); ?></h3>
            <?php endif; ?>
        </div>

        <div class="col-12 text-center p-3">
            <a class="btn btn-primary" href="config_menu.php">
                <?php echo htmlspecialchars($idioma_volver ?? 'Volver', ENT_QUOTES, 'UTF-8'); ?>
            </a>
        </div>
    </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>

<script src="https://unpkg.com/isotope-layout@3/dist/isotope.pkgd.js"></script>
<script type="text/javascript">
window.setInterval(function(){
    $('.grid').isotope({
        itemSelector: '.grid-item'
    });
}, 500);
</script>

<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>
</body>
</html>