<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dynamic Menu</title>
    <style>
        :root 
        {
            --primary-dark-purple: #4a3b4f;
            --header-gradient-start: #3a2d3f;
            --header-gradient-end: #5c4a61;
            --form-bg: #f4f4f7;
            --input-focus-bg: #f0e6c8;
            --text-light: #ffffff;
            --text-dark: #333333;
            --border-color: #d1d1d1;
        }

        .ok 
        {
            background-color: green;
            color: white;
        }
        .error 
        {
            background-color: red;
            color: white;
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
        }

        html, body 
        {
            height: 100%;
        }

        dialog 
        {
            border: none; /* Remove default border */
            border-radius: 8px;
            padding: 20px;
            height: 80%;
            width: 50%;
        }

        .close-button 
        {
            cursor: pointer;
            color: var(--text-light);
            font-size: 18px;
            float: right; /* Position close button */
        }

        .dialog-content 
        {
            margin-top: 20px;
        }
        
        .main-panel 
        {
            width: 100%;
            max-width: 550px;
            border-radius: 8px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
            display: flex;
            flex-direction: column;
        }

        /* --- Header --- */
        .header 
        {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 12px 20px;
            background: linear-gradient(90deg, var(--header-gradient-start), var(--header-gradient-end));
            color: var(--text-light);
        }

        .logo 
        {
            display: flex;
            align-items: center;
            font-weight: bold;
            font-size: 1.1em;
        }

        .logo-icon {
            font-weight: 900;
            font-style: italic;
            border: 2px solid var(--text-light);
            padding: 2px 5px;
            margin-right: 10px;
            transform: skewX(-10deg);
        }

        .header-controls {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .logon-button, .admin-button {
            background: none;
            border: none;
            color: var(--text-light);
            font-size: 0.9em;
            font-weight: bold;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 8px;
        }
        
        .admin-icon {
            width: 24px;
            height: 24px;
            border: 1.5px solid var(--text-light);
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            font-size: 0.8em;
        }

        /* --- Form Body --- */
        .form-group {
            display: flex;
            align-items: center;
            border-bottom: 1px solid var(--border-color);
            padding: 10px 10px;
            transition: background-color 0.3s ease;
        }

        .form-group.focused {
            background-color: var(--input-focus-bg);
        }

        .form-group label {
            flex-shrink: 0;
            width: 70px; /* Adjusted width */
            color: var(--text-dark);
            font-size: 1em; /* Responsive font size */
        }

        .form-group input {
            flex-grow: 1;
            border: none;
            background: transparent;
            outline: none;
            font-size: 1.1em;
            padding: 10px 5px;
            color: var(--text-dark);
        }

        .form-group .arrow-icon {
            font-size: 1.5em;
            color: var(--text-dark);
            font-weight: bold;
        }

        #preview {
            margin-top: 20px;
            border: 1px solid #ccc;
            padding: 10px;
            display: none; /* Initially hidden */
            background-color: #fff; /* Ensure it's visible */
            overflow: auto; /* Handle overflow if content is large */
        }

        /* Additional styles for better layout */
        .login-form-container {
            display: flex;
            flex-direction: column;
            gap: 20px; /* Space between input elements and preview */
        }
        
        #alert
        {
            position: fixed;
            visibility: hidden;
            transform: translate(-50%, 0px);
            z-index: 1000;
            width:auto;
            text-align:center;
            background:red;
            color: white;
            font-size: 1.4em;
            font-weight: 800;
            overflow-wrap: break-word;
            box-sizing: border-box;
            position: absolute;
            left: 50%;
            top: 65%;
        }
        
        #alert.show {
            visibility: visible;
            animation: slide-up 5s ease forwards;
        }
        
        @keyframes slide-up {
          0% {
            opacity: 0;
            top: 99%;
          }
          10% {
            opacity: 1;
          }
          90% {
            opacity: 1;
          }
          100% {
            opacity: 0;
            top: 5%;
          }
        }
        .menu {
            list-style-type: none;
            padding: 0;
            background-color: var(--form-bg);
            background-image: url("data:image/svg+xml,%3Csvg width='600' height='600' viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' stroke='%23e5e5e5' stroke-width='1.5'%3E%3Cpath d='M -50,150 C -25,150 0,100 50,100 C 100,100 125,150 150,150 C 175,150 200,100 250,100' /%3E%3Cpath d='M -50,120 C -25,120 0,70 50,70 C 100,70 125,120 150,120 C 175,120 200,70 250,70' /%3E%3C/g%3E%3C/svg%3E");
            background-repeat: no-repeat;
        }
        .menu-item {
            margin: 10px 0;
        }
        .menu-item img {
            width: 20px;
            height: 20px;
            margin-right: 5px;
        }
    </style>
</head>
<body>
    <dialog id="mainDialog">
        <div class="dialog-content">
            <div class="main-panel">
                <header class="header">
                    <div class="logo"><span>VANTEC</span></div>
                    <div class="header-controls">
                        <div class="admin-icon">
                            <!-- Admin Icon SVG -->
                        </div>
                        <span class="close-button" id="closeDialog">&times;</span>
                    </div>
                </header>
                <ul class="menu" id="menu"></ul>
                <dialog id="contentArea"></dialog>
            </div>
        </div>
    </dialog>

    <script>
        const dialog = document.getElementById('mainDialog');

        // Close the main dialog
        closeDialogButton.addEventListener('click', () => {
            dialog.close();
        });

        let openedWindow; // Reference to the opened window

window.onload = function() {
    dialog.showModal();
    fetch('jsonMenu/mainMenu.json')
        .then(response => response.json())
        .then(data => {
            const menu = document.getElementById('menu');
            data.forEach(item => {
                const menuItem = document.createElement('li');
                menuItem.className = 'menu-item';

                const anchor = document.createElement('a');
                anchor.href = item.url; // Set the URL
                anchor.innerHTML = `<img src="${item.icon}" alt="${item.menu_description} icon"> ${item.menu_description}`;

                // Open new window on click
                anchor.addEventListener('click', (event) => {
                    event.preventDefault(); // Prevent default navigation
                    openedWindow = window.open(item.url, '_blank'); // Open URL in a new window
                });

                menuItem.appendChild(anchor);
                menu.appendChild(menuItem);
            });
        })
        .catch(error => console.error('Error fetching menu items:', error));
}

const closeDialogButton = document.getElementById('closeDialog');
closeDialogButton.addEventListener('click', () => {
    dialog.close(); // Close the dialog
    if (openedWindow) {
        openedWindow.close(); // Close the opened window
    }
});
    </script>
</body>
</html>