@php
$headers = App\Models\Header::whereNull('parent_id')->orderBy('position','asc')->get();
$headerLogo = App\Models\HeaderLogo::first();
$topheader = App\Models\TopHeader::first();
@endphp

<header class="header" id="header">
    @include('components.nav-footer.topheader')
    <nav class="navbar_second " id="navbarSecond">
        <div class="nav_menu">
            <!-- Hamburger Menu Button -->
            <div class="hamburger-menu">
                <button class="hamburger-btn" id="hamburger-btn">
                    <span class="hamburger-line"></span>
                    <span class="hamburger-line"></span>
                    <span class="hamburger-line"></span>
                </button>
            </div>

            <ul class="nav__list" id="nav-list">
                @foreach ($headers as $header)
                @include('components.nav-footer.nav_item', ['header' => $header])
                @endforeach
            </ul>
        </div>
        @if($topheader)
            <div class="nav_buttons">
                @if ($topheader->requestinfo_status && $topheader->requestinfo && $topheader->requestinfo_link)
                <a href="{{ $topheader->requestinfo_link }}" class="request_info_link"> {{ strtoupper($topheader->requestinfo) }}</a>
                @endif
                @if ($topheader->applynow_status && $topheader->apply_now && $topheader->apply_now_link)
                    <a href="{{ $topheader->apply_now_link }}" class="ribbon">
                        <span class="ribbon-text">{{ strtoupper($topheader->apply_now) }}</span>
                    </a>

                    <a href="{{ $topheader->apply_now_link }}" class="mobile-apply-link">{{ strtoupper($topheader->apply_now) }}</a>
                @endif
            </div>
        @endif
    </nav>
</header>

<script>
    // Hamburger menu functionality
    const hamburgerBtn = document.getElementById('hamburger-btn');
    const navList = document.getElementById('nav-list');
    const hamburgerLines = document.querySelectorAll('.hamburger-line');

    hamburgerBtn.addEventListener('click', function() {
        navList.classList.toggle('show');
        hamburgerBtn.classList.toggle('active');

        // Animate hamburger lines
        hamburgerLines.forEach((line, index) => {
            line.classList.toggle('active');
        });
    });

    // Close menu when clicking outside
    document.addEventListener('click', function(event) {
        if (!hamburgerBtn.contains(event.target) && !navList.contains(event.target)) {
            navList.classList.remove('show');
            hamburgerBtn.classList.remove('active');
            hamburgerLines.forEach(line => {
                line.classList.remove('active');
            });
        }
    });

    // Close menu when clicking on a link
    const navLinks = document.querySelectorAll('.nav__list a');
    navLinks.forEach(link => {
        link.addEventListener('click', function() {
            navList.classList.remove('show');
            hamburgerBtn.classList.remove('active');
            hamburgerLines.forEach(line => {
                line.classList.remove('active');
            });
        });
    });

    // Active page highlighting
    const activePage = window.location.pathname;
    document.querySelectorAll('.nav__list li').forEach(link => {
        if (link.href && link.href.includes(`${activePage}`)) {
            link.classList.add('active');
        }
    });
</script>

<style>
    .header{
        position:fixed ;
        width:100%;
        z-index: 10;
        box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
    }
    .navbar_second {
        background: #004675;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 32px;
        position: relative;
    }

    .nav_menu {
        display: flex;
        align-items: center;
        justify-content: space-between;
        flex: 1;
    }

    .nav__list {
        display: flex;
        align-items: center;
        list-style: none;
        margin: 0;
        padding: 0;
    }

    .nav__list li {
        margin: 0 2px;
    }

    .nav__list a {
        display: block;
        padding: 15px 20px;
        color: #fff;
        text-decoration: none;
        font-family: 'Poppins', Arial, sans-serif;
        font-size: 15px;
        font-weight: 500;
        letter-spacing: 0.08em;
        transition: background 0.2s, color 0.2s;
        position: relative;
    }

    .nav__list a:hover,
    .nav__list .active>a,
    .nav__list li.active>a {
        background: #F3881B;
        color: #fff;
    }

    /* Hamburger Menu Styles */
    .hamburger-menu {
        display: none;
    }

    .hamburger-btn {
        background: none;
        border: none;
        cursor: pointer;
        padding: 5px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        width: 30px;
        height: 32px;
        z-index: 1000;
    }

    .hamburger-line {
        margin-top: 3px;
        width: 100%;
        height: 3px;
        background-color: #fff;
        border-radius: 2px;
        transition: all 0.3s ease;
        transform-origin: center;
    }

    .hamburger-btn.active .hamburger-line:nth-child(1) {
        transform: rotate(45deg) translate(6px, 6px);
    }

    .hamburger-btn.active .hamburger-line:nth-child(2) {
        opacity: 0;
    }

    .hamburger-btn.active .hamburger-line:nth-child(3) {
        transform: rotate(-45deg) translate(6px, -6px);
    }

    /* Responsive */
    @media (max-width: 1099px) {
        .navbar_second {
            padding: 0 20px;
            height: 50px;
        }

        .hamburger-menu {
            display: block;
        }

        .nav__list {
            flex-direction: column;
            background: #004675;
            position: absolute;
            top: 100%;
            left: 0;
            width: 100%;
            display: none;
            box-shadow: 0 4px 8px rgba(0,0,0,0.1);
            padding: 20px 0;
        }

        .nav__list.show {
            display: flex;
        }

        .nav__list li {
            width: 100%;
            margin: 0;
        }

        .nav__list a {
            padding: 15px 20px;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            text-align: left;
        }

        .nav__list a:hover {
            background: #F3881B;
        }

        /* Submenu styles for mobile */
        .nav__list .sub-menu {
            position: static;
            background: rgba(0,0,0,0.1);
            box-shadow: none;
            width: 100%;
            padding-left: 20px;
        }

        .nav__list .sub-menu li {
            width: 100%;
        }

        .nav__list .sub-menu a {
            padding: 10px 20px;
            font-size: 14px;
        }

        .nav_buttons {
            display: flex;
            gap: 10px;

        }

        /* Hide ribbon in mobile */
        .ribbon {
            display: none !important;
        }

        /* Show mobile apply link */
        .mobile-apply-link {
            display: inline-block !important;
        }
    }
    .nav_menu {
        display: flex;
    }
    .nav_buttons {
        display: flex;
        align-items: center;
        gap: 15px;
        margin-right: 7%;
    }

    .request_info_link {
        color: #F3881B;
        border: none;
        padding: 10px 20px;
        text-decoration: none;
        font-family: Poppins;
        font-weight: 500;
        font-size: 14px;
        line-height: 16.8px;
        letter-spacing: 0px;
    }

    .mobile-apply-link {
        display: none;
        color: #F3881B;
        border: none;
        padding: 10px 20px;
        text-decoration: none;
        font-family: Poppins;
        font-weight: 500;
        font-size: 14px;
        line-height: 16.8px;
        letter-spacing: 0px;
    }

    /* Show mobile apply link only on screens smaller than 1100px */
    @media (max-width: 1099px) {
        .mobile-apply-link {
            display: inline-block;
        }
    }

    .apply-ribbon {
        position: relative;
        display: inline-block;
        background: #F3881B;
        text-align: center;
    }

    /* HTML: <div class="ribbon">Your text content</div> */
    .ribbon {
        font-size: 28px;
        font-weight: bold;
        color: #fff;
    }

    .ribbon {
        --f: .4em;
        --r: 2em;
        position: absolute;
        z-index: 9999;
        right: 30px;
        top: -10px;
        padding: 15px;
        border: solid #0000;
        border-width: 0 calc(2*var(--f)) var(--r) 0;
        background:
            radial-gradient(50% 100% at bottom, #0005 98%, #0000 101%) 100% 0/calc(2*var(--f)) var(--f) no-repeat border-box;
        background-color: #F3881B;
        border-radius: var(--f) var(--f) 0 0;
        clip-path: polygon(100% 0, 0 0, 0 100%, calc(50% - var(--f)) calc(100% - var(--r)), calc(100% - 2*var(--f)) 100%, calc(100% - 2*var(--f)) var(--f), 100% var(--f));
    }

    .ribbon-text {
        writing-mode: vertical-rl;
        text-orientation: upright;
        font-family: Quicksand;
        font-weight: 700;
        font-size: 12px;
        line-height: 18px;
        letter-spacing: 0px;
        text-align: center;
    }
</style>