<?php
require_once __DIR__ . '/config/session.php';

$currentUser = function_exists('getCurrentUser') ? getCurrentUser() : null;
$isUserLoggedIn = function_exists('isLoggedIn') ? isLoggedIn() : false;

$displayName = 'Guest';
$displayEmail = '';
$avatarInitials = 'G';
$dashboardUrl = 'dashboard.php'; // Default dashboard for guests

if ($isUserLoggedIn && is_array($currentUser)) {
    $firstName = trim((string)($currentUser['first_name'] ?? ''));
    $lastName = trim((string)($currentUser['last_name'] ?? ''));
    $displayEmail = trim((string)($currentUser['email'] ?? ''));
    $displayName = trim($firstName . ' ' . $lastName);
    if ($displayName === '') {
        $displayName = $displayEmail !== '' ? $displayEmail : 'User';
    }

    $initialsSource = trim(($firstName !== '' ? $firstName[0] : '') . ($lastName !== '' ? $lastName[0] : ''));
    if ($initialsSource !== '') {
        $avatarInitials = strtoupper($initialsSource);
    } else {
        $avatarInitials = strtoupper(substr($displayName, 0, 1));
    }

    // Determine dashboard URL based on user type
    $userType = trim((string)($currentUser['user_type'] ?? 'guest'));
    if ($userType === 'staff') {
        $dashboardUrl = 'staff-dashboard.php';
    } else {
        $dashboardUrl = 'dashboard.php';
    }
}
?>
<!DOCTYPE html>
<html lang="zxx">

<head>
    <title>zemaraim — Hotel Website Template</title>
    <link rel="icon" href="images/icon.webp" type="image/gif" sizes="16x16">
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">
    <meta content="zemaraim — Hotel Website Template" name="description">
    <meta content="" name="keywords">
    <meta content="" name="author">
    <!-- CSS Files
    ================================================== -->
    <link href="css/bootstrap.min.css" rel="stylesheet" type="text/css" id="bootstrap">
    <link href="css/plugins.css" rel="stylesheet" type="text/css">
    <link href="css/swiper.css" rel="stylesheet" type="text/css">
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <link href="css/coloring.css" rel="stylesheet" type="text/css">
    <!-- color scheme -->
    <link id="colors" href="css/colors/scheme-01.css" rel="stylesheet" type="text/css">

</head>
<body>
    <style>
        .site-header-wrap {
            position: relative !important;
            top: auto !important;
            box-shadow: none !important;
            background: transparent !important;
        }

        body.has-sticky-main {
            padding-top: var(--sticky-main-height, 72px);
        }

        .site-location {
            text-align: right;
        }

        .site-header-top,
        .site-header-middle {
            transition: all 0.3s ease;
        }
        
        .site-header-top.hide,
        .site-header-middle.hide {
            display: none;
        }
        
        .site-header-main.sticky {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            width: 100%;
            z-index: 1000;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }

        .site-header-top-inner {
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
            gap: 15px;
        }

        .site-header-middle-inner {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 20px;
            flex-wrap: wrap;
        }

        .site-contact-strip {
            display: flex;
            gap: 20px;
            align-items: center;
            flex: 1;
            min-width: 200px;
        }

        .site-contact-strip span {
            display: flex;
            align-items: center;
            gap: 8px;
            font-size: 13px;
            white-space: nowrap;
        }

        .site-user-profile {
            display: inline-flex;
            align-items: center;
            gap: 10px;
            padding: 6px 10px;
            border-radius: 10px;
            background: #ffffff;
            border: 1px solid #e6edf5;
        }

        .site-user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            color: #ffffff;
            font-size: 13px;
            font-weight: 700;
            background: linear-gradient(135deg, #10243d 0%, #2c4d74 100%);
            flex-shrink: 0;
        }

        .site-user-meta {
            display: flex;
            flex-direction: column;
            line-height: 1.15;
        }

        .site-user-meta strong {
            font-size: 13px;
            color: #10243d;
        }

        .site-user-meta span {
            font-size: 11px;
            color: #62758d;
        }

        .site-user-dropdown {
            position: relative;
        }

        .site-user-toggle {
            display: inline-flex;
            align-items: center;
            gap: 8px;
            border: 0;
            padding: 0;
            background: transparent;
            cursor: pointer;
        }

        .site-user-caret {
            color: #62758d;
            font-size: 13px;
            transition: transform 0.2s ease;
        }

        .site-user-dropdown-menu {
            position: absolute;
            top: calc(100% + 10px);
            right: 0;
            min-width: 180px;
            background: #ffffff;
            border: 1px solid #e6edf5;
            border-radius: 10px;
            box-shadow: 0 12px 28px rgba(16, 36, 61, 0.16);
            padding: 8px;
            display: none;
            z-index: 1100;
        }

        .site-user-dropdown-menu a {
            display: block;
            padding: 10px 12px;
            border-radius: 8px;
            color: #10243d;
            font-size: 13px;
            font-weight: 600;
            text-decoration: none;
            transition: background 0.2s ease;
        }

        .site-user-dropdown-menu a:hover {
            background: #f2f6fb;
            color: #10243d;
        }

        .site-user-dropdown:hover .site-user-dropdown-menu,
        .site-user-dropdown:focus-within .site-user-dropdown-menu,
        .site-user-dropdown.open .site-user-dropdown-menu {
            display: block;
        }

        .site-user-dropdown:hover .site-user-caret,
        .site-user-dropdown:focus-within .site-user-caret,
        .site-user-dropdown.open .site-user-caret {
            transform: rotate(180deg);
        }

        .site-auth-actions .btn-main.btn-line {
            padding: 8px 14px;
        }

        .site-mobile-auth {
            display: none;
        }

        /* Responsive Styles */
        @media (max-width: 1200px) {
            .site-header-top-inner {
                gap: 12px;
            }

            .site-contact-strip {
                gap: 15px;
                font-size: 12px;
            }
        }

        @media (max-width: 991.98px) {
            .site-header-top {
                padding: 8px 0;
            }

            .site-header-middle {
                padding: 12px 0;
            }

            .site-header-top-inner {
                flex-direction: column;
                gap: 12px;
            }

            .site-location {
                text-align: center;
            }

            .site-social {
                order: 1;
            }

            .site-welcome {
                order: 2;
            }

            .site-location {
                order: 3;
                width: 100%;
            }

            .site-header-middle-inner {
                flex-direction: column;
                width: 100%;
                gap: 15px;
            }

            .site-contact-strip {
                width: 100%;
                justify-content: center;
                order: 1;
                flex: none;
            }

            .site-auth-actions {
                width: 100%;
                justify-content: center;
                order: 2;
            }

            .site-user-dropdown {
                width: 100%;
                max-width: 360px;
            }

            .site-user-toggle {
                width: 100%;
            }

            .site-user-profile {
                width: 100%;
                justify-content: space-between;
            }

            .site-user-dropdown-menu {
                position: static;
                width: 100%;
                margin-top: 8px;
                box-shadow: none;
                border-radius: 8px;
            }
        }

        @media (max-width: 1024px) {
            .site-header-main .de-flex {
                position: relative;
            }

            .site-header-main .menu_side_area {
                position: relative;
                z-index: 1202;
                display: inline-flex;
                align-items: center;
                gap: 10px;
            }

            .site-mobile-nav-backdrop {
                position: fixed;
                inset: 0;
                background: rgba(15, 23, 42, 0.5);
                opacity: 0;
                visibility: hidden;
                pointer-events: none;
                transition: opacity 0.25s ease, visibility 0.25s ease;
                z-index: 1198;
            }

            .site-mobile-nav-open .site-mobile-nav-backdrop {
                opacity: 1;
                visibility: visible;
                pointer-events: auto;
            }

            .site-header-main .header-col-mid {
                position: static;
            }

            .site-header-main #mainmenu {
                position: fixed !important;
                top: 0 !important;
                left: 0 !important;
                width: min(82vw, 340px) !important;
                height: 100vh !important;
                margin: 0 !important;
                padding: 0px 18px 32px !important;
                overflow-y: auto !important;
                background: #10243d !important;
                box-shadow: 16px 0 36px rgba(15, 23, 42, 0.24);
                transform: translateX(-104%);
                opacity: 0;
                visibility: hidden;
                pointer-events: none;
                transition: transform 0.28s ease, opacity 0.22s ease, visibility 0.22s ease;
                z-index: 1201 !important;
            }

            .site-header-main #mainmenu > li {
                width: 100%;
            }

            .site-mobile-auth {
                display: block;
                width: 100%;
                margin-top: 16px;
                padding-top: 14px;
                border-top: 1px solid rgba(255, 255, 255, 0.18);
            }

            .site-mobile-auth-card {
                display: flex;
                align-items: center;
                gap: 10px;
                padding: 10px 12px;
                border: 1px solid rgba(255, 255, 255, 0.18);
                border-radius: 10px;
                background: rgba(255, 255, 255, 0.08);
                margin-bottom: 10px;
            }

            .site-mobile-auth-avatar {
                width: 34px;
                height: 34px;
                border-radius: 50%;
                display: inline-flex;
                align-items: center;
                justify-content: center;
                color: #ffffff;
                font-size: 12px;
                font-weight: 700;
                background: linear-gradient(135deg, #0f2a45 0%, #2d517a 100%);
                flex-shrink: 0;
            }

            .site-mobile-auth-meta {
                min-width: 0;
            }

            .site-mobile-auth-meta strong,
            .site-mobile-auth-meta span {
                display: block;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }

            .site-mobile-auth-meta strong {
                color: #ffffff;
                font-size: 13px;
                line-height: 1.2;
            }

            .site-mobile-auth-meta span {
                color: rgba(255, 255, 255, 0.74);
                font-size: 11px;
                line-height: 1.3;
            }

            .site-mobile-auth-actions {
                display: grid;
                grid-template-columns: 1fr;
                gap: 8px;
            }

            .site-mobile-auth-actions .btn-main {
                width: 100%;
                text-align: center;
                padding: 9px 12px;
                font-size: 12px;
            }

            .site-mobile-nav-open .site-header-main #mainmenu {
                transform: translateX(0);
                opacity: 1;
                visibility: visible;
                pointer-events: auto;
            }

            .site-header-main #menu-btn {
                position: relative;
                z-index: 1202;
            }

            body.site-mobile-nav-lock {
                overflow: hidden;
                touch-action: none;
            }

            .site-contact-strip {
                flex-direction: column;
                gap: 8px;
                align-items: center;
            }

            .site-contact-strip span {
                font-size: 12px;
            }

            .site-user-profile {
                padding: 8px 12px;
            }

            .site-user-avatar {
                width: 32px;
                height: 32px;
                font-size: 12px;
            }

            .site-user-meta strong {
                font-size: 12px;
            }

            .site-user-meta span {
                font-size: 10px;
            }

            .site-auth-actions .btn-main.btn-line {
                padding: 6px 12px;
                font-size: 12px;
            }
        }

        @media (max-width: 576px) {
            .site-header-top {
                padding: 6px 0;
            }

            .site-header-middle {
                padding: 10px 0;
            }

            .site-header-top-inner {
                gap: 10px;
            }

            .site-social {
                gap: 8px;
            }

            .site-social a {
                font-size: 14px;
            }

            .site-welcome {
                font-size: 12px;
            }

            .site-location span {
                font-size: 11px;
            }

            .site-contact-strip {
                gap: 6px;
                flex-direction: row;
                font-size: 11px;
            }

            .site-contact-strip span {
                font-size: 11px;
            }

            .site-contact-strip span i {
                font-size: 12px;
            }

            .site-user-profile {
                padding: 6px 8px;
                gap: 8px;
            }

            .site-user-avatar {
                width: 28px;
                height: 28px;
                font-size: 11px;
            }

            .site-user-meta {
                display: none;
            }

            .site-user-meta strong {
                font-size: 11px;
            }

            .site-user-meta span {
                font-size: 9px;
            }

            .site-user-caret {
                font-size: 12px;
            }

            .site-user-dropdown-menu {
                min-width: 150px;
            }

            .site-user-dropdown-menu a {
                padding: 8px 10px;
                font-size: 12px;
            }

            .site-auth-actions .btn-main.btn-line {
                padding: 5px 10px;
                font-size: 11px;
            }
        }

        /* Ensure mobile auth buttons are hidden on desktop */
        @media (min-width: 1025px) {
            .site-mobile-auth {
                display: none !important;
            }
        }
    </style>

    <header class="site-header-wrap">
        <div class="site-mobile-nav-backdrop" id="siteMobileNavBackdrop"></div>
        <div class="site-header-top">
            <div class="container">
                <div class="site-header-top-inner">
                    <div class="site-social">
                        <a href="#"><i class="fa-brands fa-facebook-f"></i></a>
                        <a href="#"><i class="fa-brands fa-instagram"></i></a>
                        <a href="#"><i class="fa-brands fa-x-twitter"></i></a>
                        <a href="#"><i class="fa-brands fa-youtube"></i></a>
                    </div>
                    <div class="site-welcome">Welcome to Zemaraim Hotel Booking</div>
                    <div class="site-location">
                        <span><i class="icofont-location-pin"></i>Brooklyn, NY</span>
                    </div>
                </div>
            </div>
        </div>

        <div class="site-header-middle">
            <div class="container">
                <div class="site-header-middle-inner">
                    <div class="site-contact-strip">
                        <span><i class="icofont-phone"></i>+929 333 9296</span>
                        <span><i class="icofont-envelope"></i>contact@zemaraim.com</span>
                    </div>
                    <div class="site-auth-actions">
                        <?php if ($isUserLoggedIn): ?>
                            <div class="site-user-dropdown">
                                <button class="site-user-toggle" type="button" aria-expanded="false" aria-label="Open user menu">
                                    <div class="site-user-profile">
                                        <span class="site-user-avatar"><?php echo htmlspecialchars($avatarInitials, ENT_QUOTES, 'UTF-8'); ?></span>
                                        <div class="site-user-meta">
                                            <strong><?php echo htmlspecialchars($displayName, ENT_QUOTES, 'UTF-8'); ?></strong>
                                            <span><?php echo htmlspecialchars($displayEmail, ENT_QUOTES, 'UTF-8'); ?></span>
                                        </div>
                                        <i class="icofont-simple-down site-user-caret" aria-hidden="true"></i>
                                    </div>
                                </button>
                                <div class="site-user-dropdown-menu">
                                    <a href="<?php echo htmlspecialchars($dashboardUrl, ENT_QUOTES, 'UTF-8'); ?>" title="My Dashboard">Dashboard</a>
                                    <a href="logout.php">Logout</a>
                                </div>
                            </div>
                        <?php else: ?>
                            <a href="login.php" class="btn-main">Login</a>
                            <a href="register.php" class="btn-main">Register</a>
                        <?php endif; ?>
                    </div>
                </div>
            </div>
        </div>

        <div class="site-header-main transparent">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="de-flex sm-pt10">
                            <div class="de-flex-col">
                                <div id="logo">
                                    <a href="index.php">
                                        <img class="logo-main" src="images/ztpllogolight.png" alt="">
                                    </a>
                                </div>
                            </div>
                            <div class="de-flex-col header-col-mid">
                                <ul id="mainmenu">
                                    <li><a class="menu-item" href="index.php">Home</a></li>
                                    <li>
                                        <a class="menu-item" href="about.php">About Us</a>
                                        <ul>
                                            <li><a href="facilities.php">Facilities</a></li>
                                            <li><a href="offer.php">Offers</a></li>
                                        </ul>
                                    </li>
                                     <li>
                                        <a class="menu-item" href="gallery.php">Gallery</a>
                                    </li>
                                    <li>
                                        <a class="menu-item" href="rooms.php">Rooms</a>
                                    </li>
                                    <li>
                                        <a class="menu-item" href="news.php">News</a>
                                    </li>
                                    <li>
                                        <a class="menu-item" href="contact.php">Contact</a>
                                    </li>
                                    <li class="site-mobile-auth">
                                        <?php if ($isUserLoggedIn): ?>
                                            <div class="site-mobile-auth-card">
                                                <span class="site-mobile-auth-avatar"><?php echo htmlspecialchars($avatarInitials, ENT_QUOTES, 'UTF-8'); ?></span>
                                                <div class="site-mobile-auth-meta">
                                                    <strong><?php echo htmlspecialchars($displayName, ENT_QUOTES, 'UTF-8'); ?></strong>
                                                    <span><?php echo htmlspecialchars($displayEmail, ENT_QUOTES, 'UTF-8'); ?></span>
                                                </div>
                                            </div>
                                            <div class="site-mobile-auth-actions">
                                                <a href="<?php echo htmlspecialchars($dashboardUrl, ENT_QUOTES, 'UTF-8'); ?>" class="btn-main btn-line">Dashboard</a>
                                                <a href="logout.php" class="btn-main">Logout</a>
                                            </div>
                                        <?php else: ?>
                                            <div class="site-mobile-auth-actions">
                                                <a href="login.php" class="btn-main">Login</a>
                                                <a href="register.php" class="btn-main btn-line">Register</a>
                                            </div>
                                        <?php endif; ?>
                                    </li>
                                    <?php if ($isUserLoggedIn): ?>
                                    <!-- <li>
                                        <a class="menu-item" href="dashboard.php">My Dashboard</a>
                                    </li> -->
                                    <?php endif; ?>
                                </ul>
                            </div>
                            <div class="de-flex-col">
                                <div class="menu_side_area">
                                    <a href="reservation.php" class="btn-main btn-line">Reservation</a>
                                    <span id="menu-btn"></span>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>
         
    
    <!-- Javascript Files
    ================================================== -->
    <script src="https://cdn.jsdelivr.net/npm/swiper@11/swiper-bundle.min.js"></script>
    <script src="js/plugins.js"></script>
    <script src="js/designesia.js"></script>
    <script src="js/swiper.js"></script>
    <script src="js/custom-marquee.js"></script>
    <script src="js/custom-swiper-3.js"></script>
    <script src='../../recaptcha/api.js' async="" defer=""></script>
    <script src="contact.js"></script>
    
    <script>
        const headerWrap = document.querySelector('.site-header-wrap');
        const headerTop = document.querySelector('.site-header-top');
        const headerMiddle = document.querySelector('.site-header-middle');
        const headerMain = document.querySelector('.site-header-main');
        const userDropdown = document.querySelector('.site-user-dropdown');
        const userToggle = document.querySelector('.site-user-toggle');
        const menuBtn = document.getElementById('menu-btn');
        const mainMenu = document.getElementById('mainmenu');
        const mobileNavBackdrop = document.getElementById('siteMobileNavBackdrop');
        const stickyTrigger = 40;

        function isMobileViewport() {
            return window.matchMedia('(max-width: 1024px)').matches;
        }

        function closeMobileNav() {
            if (!headerWrap) {
                return;
            }
            headerWrap.classList.remove('site-mobile-nav-open');
            document.body.classList.remove('site-mobile-nav-lock');
            if (menuBtn) {
                menuBtn.classList.remove('menu-open');
                menuBtn.setAttribute('aria-expanded', 'false');
            }
        }

        function openMobileNav() {
            if (!headerWrap) {
                return;
            }
            headerWrap.classList.add('site-mobile-nav-open');
            document.body.classList.add('site-mobile-nav-lock');
            if (menuBtn) {
                menuBtn.classList.add('menu-open');
                menuBtn.setAttribute('aria-expanded', 'true');
            }
        }

        function syncStickyHeader() {
            if (!headerTop || !headerMiddle || !headerMain) {
                return;
            }

            if (isMobileViewport()) {
                headerTop.classList.remove('hide');
                headerMiddle.classList.remove('hide');
                headerMain.classList.remove('sticky');
                document.body.classList.remove('has-sticky-main');
                return;
            }

            const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
            const shouldStick = scrollTop > stickyTrigger;

            if (shouldStick) {
                headerTop.classList.add('hide');
                headerMiddle.classList.add('hide');
                headerMain.classList.add('sticky');
                document.documentElement.style.setProperty('--sticky-main-height', `${headerMain.offsetHeight}px`);
                document.body.classList.add('has-sticky-main');
            } else {
                headerTop.classList.remove('hide');
                headerMiddle.classList.remove('hide');
                headerMain.classList.remove('sticky');
                document.body.classList.remove('has-sticky-main');
            }
        }

        if (window.jQuery && menuBtn) {
            window.jQuery(menuBtn).off('click');
        }

        if (menuBtn && mainMenu) {
            menuBtn.setAttribute('role', 'button');
            menuBtn.setAttribute('aria-controls', 'mainmenu');
            menuBtn.setAttribute('aria-expanded', 'false');
            menuBtn.setAttribute('tabindex', '0');

            menuBtn.addEventListener('click', function(event) {
                if (!isMobileViewport()) {
                    return;
                }
                event.preventDefault();
                event.stopPropagation();
                if (headerWrap && headerWrap.classList.contains('site-mobile-nav-open')) {
                    closeMobileNav();
                } else {
                    openMobileNav();
                }
            });

            menuBtn.addEventListener('keydown', function(event) {
                if (event.key === 'Enter' || event.key === ' ') {
                    event.preventDefault();
                    menuBtn.click();
                }
            });
        }

        if (mainMenu) {
            mainMenu.addEventListener('click', function(event) {
                if (!isMobileViewport()) {
                    return;
                }
                const link = event.target.closest('a');
                if (link) {
                    closeMobileNav();
                }
            });
        }

        if (mobileNavBackdrop) {
            mobileNavBackdrop.addEventListener('click', closeMobileNav);
        }

        document.addEventListener('click', function(event) {
            if (!isMobileViewport() || !headerWrap || !headerWrap.classList.contains('site-mobile-nav-open')) {
                return;
            }

            if ((mainMenu && mainMenu.contains(event.target)) || (menuBtn && menuBtn.contains(event.target))) {
                return;
            }

            closeMobileNav();
        });

        window.addEventListener('scroll', syncStickyHeader);
        window.addEventListener('resize', function() {
            if (!isMobileViewport()) {
                closeMobileNav();
            }
            syncStickyHeader();
        });
        window.addEventListener('load', syncStickyHeader);

        if (userDropdown && userToggle) {
            userToggle.addEventListener('click', function(event) {
                event.preventDefault();
                const isOpen = userDropdown.classList.toggle('open');
                userToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
            });

            document.addEventListener('click', function(event) {
                if (!userDropdown.contains(event.target)) {
                    userDropdown.classList.remove('open');
                    userToggle.setAttribute('aria-expanded', 'false');
                }
            });

            document.addEventListener('keydown', function(event) {
                if (event.key === 'Escape') {
                    userDropdown.classList.remove('open');
                    userToggle.setAttribute('aria-expanded', 'false');
                }
            });
        }
    </script>

</body>
</html>
