@php
    $offer = App\Models\UniPopUp::first();
@endphp
@if ($offer)
    <button id="offer-button" class="offer-button">Offer !!!</button>
    <div class="backdrop" id="backdrop"></div>
    <div class="popup_offer" id="popup_offer">
        <img class="background_popup" src="{{ asset('images/behindimage/behindtheofferinthpopup.jpg') }}" alt="">
        <button type="button" id="close">
            <img src="/assets/cross.png" alt="Close" class="close">
        </button>
        <div class="popup_content">
            <h3>{{ $offer->title }}</h3>
            <div class="per_symbol">
                <span class="percentage" style="font-family: 'Kyiv Type Serif';">{{ $offer->number_off }}</span>
                <div class="symbol">
                    <span class="symbol_per">{{ $offer->sign }}</span><br>
                    <span class="symbol_letter">{{ $offer->off }}</span>
                </div>
            </div>
            <span class="students">{{ $offer->desc }}</span>
            <div
                style="width:100%;display: flex;  flex-direction: column; justify-content: center; align-items: center;">
                <a href="{{ $offer->url }}">

                    <button class="carousel_search">Apply Now</button>
                </a>
            </div>
        </div>
    </div>
@endif

<div class="home_image_container">
    <div class="background_image_container">
        <img src="{{ asset('storage/' . $home->top_image) }}" alt="{{ $home->top_image }}">
    </div>
    <div class="stats-cards-container">
        @foreach ($home->count_items as $item)
            <div class="stats-card">
                <img src="{{ asset('storage/' . $item['icon_image']) }}" alt="{{ $item['name'] }} icon"
                    class="stats-icon">
                <div class="stats-info">
                    <div class="stats-count">{{ $item['count'] }}</div>
                    <div class="stats-label">{{ strtoupper($item['name']) }}</div>
                </div>
            </div>
        @endforeach
    </div>
    @php
        $aboutus = App\Models\AboutUs::first();
        $titleParts = explode(' ', $aboutus->main_title, 2); // splits into two parts
    @endphp
    <div class="angled-divider"></div>
    <div class="about-section-hero">
        <div class="about-bg-text">
            <span class="about-bg-blue">{{ $titleParts[0] ?? '' }}</span>
            <span class="about-bg-orange">{{ $titleParts[1] ?? '' }}</span>
        </div>
        <div class="about-content-box">
            <div class="about-description">
                {{ $aboutus->short_description }}
            </div>
        </div>
    </div>
</div>
<style>
    .home_image_container {
        background-color: #004675;
        margin-bottom: 10%;

    }

    .stats-cards-container {
        display: flex;
        justify-content: center;
        gap: 3rem;
        background: #fff;
        border-radius: 12px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
        padding: 2rem 1rem;
        margin-top: -60px;
        position: relative;
        z-index: 2;
        max-width: max-content;
        margin-left: auto;
        margin-right: 48px;
    }

    .stats-card {
        display: flex;
        align-items: center;
        gap: 1.5rem;
        width: max-content;
        padding: 1rem;

    }

    .stats-icon {
        width: 30;
        height: 30px;
        flex-shrink: 0;
    }

    .stats-info {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-count {
        font-size: 24px;
        font-weight: 500;
        color: #17486D;
        margin-bottom: 0.2rem;
    }

    .stats-label {
        font-size: 18px;
        color: #17486D;
        letter-spacing: 1px;
        font-weight: 400;
    }

    .angled-divider {
        margin-top: -15%;
        width: 30%;
        height: 120px;
        /* Adjust height as needed */
        background: #004675;
        clip-path: polygon(0 100%, 100% 100%, 0 0);

    }


    .about-section-wrapper {
        background: #004675;
        position: relative;
        padding: 4rem 0 2rem 0;
        clip-path: polygon(0 0, 100% 10%, 100% 100%, 0% 100%);
        /* Adjust the 10% for the angle steepness */
        margin-top: 2rem;
    }

    .about-us-section {
        background: #fff;
        padding: 2rem;
        border-radius: 12px;
        max-width: 900px;
        margin: 0 auto;
        position: relative;
        z-index: 2;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
    }

    .about-blue {
        color: #FBF599;
        font-weight: bold;
        letter-spacing: 2px;
        font-size: 2.5rem;
    }

    .about-orange {
        color: #F6A84F;
        font-weight: bold;
        letter-spacing: 2px;
        font-size: 2.5rem;
    }

    .about-description {
        margin-top: 1rem;
        color: #222;
        font-size: 1rem;
        line-height: 1.6;
    }

    .background_image_container {
        width: 100%;
        overflow: hidden;
        border-radius: 10px;
    }

    .background_image_container img {
        width: 100%;
        aspect-ratio: 16/9;
        display: block;
        object-fit: cover;
    }

    .home_image.container {
        width: 100%;
        padding: 0;
        margin: 0;
        position: relative;
    }

    .about-section-hero {
        position: relative;
        background: #004675;
        height: 200px;
        display: flex;
        align-items: center;
        padding: 0;
        margin-bottom: 40px;
    }

    .about-bg-text {
        position: absolute;
        left: 14%;
        top: 90%;
        font-size: 3.5rem;
        font-weight: bold;
        letter-spacing: 4px;
        z-index: 5;
        display: flex;
        gap: 10px;

    }

    .about-bg-blue {
        color: #B3C8D6;
    }

    .about-bg-orange {
        color: #F6A84F;
        opacity: 1;
    }

    .about-content-box {
        display: flex;
        justify-content: flex-end;
        align-items: center;
        margin-left: auto;
        margin-right: 48px;
        background: #fff;
        border-radius: 8px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
        padding: 32px 36px;
        z-index: 2;
        width: 60%;
        top: 50%;
        position: relative;
    }

    .about-description {
        width: 90%;
        color: #222;
        font-size: 1rem;
        line-height: 1.6;
    }

    /* Enhanced responsive styles */
    @media (max-width: 1200px) {
        .home_image_container {
            margin-bottom: 8%;
        }

        .stats-cards-container {
            gap: 2.5rem;
            padding: 1.8rem 0.8rem;
            margin-top: -50px;
            margin-right: 40px;
        }

        .stats-card {
            gap: 1.2rem;
            padding: 0.8rem;
        }

        .stats-count {
            font-size: 22px;
        }

        .stats-label {
            font-size: 16px;
        }

        .about-bg-text {
            font-size: 3rem;
            letter-spacing: 3px;
        }

        .about-content-box {
            margin-right: 40px;
            padding: 28px 32px;
            width: 65%;
        }

        .about-description {
            font-size: 0.95rem;
        }
    }

    @media (max-width: 992px) {
        .home_image_container {
            margin-bottom: 6%;
        }

        .stats-cards-container {
            gap: 2rem;
            padding: 1.5rem 0.6rem;
            margin-top: -40px;
            margin-right: 30px;
        }

        .stats-card {
            gap: 1rem;
            padding: 0.6rem;
        }

        .stats-count {
            font-size: 20px;
        }

        .stats-label {
            font-size: 15px;
        }

        .angled-divider {
            margin-top: -12%;
            height: 100px;
        }

        .about-section-hero {
            height: 180px;
            margin-bottom: 30px;
        }

        .about-bg-text {
            font-size: 2.5rem;
            letter-spacing: 2px;
            left: 12%;
        }

        .about-content-box {
            margin-right: 30px;
            padding: 24px 28px;
            width: 70%;
        }

        .about-description {
            font-size: 0.9rem;
        }
    }

    @media (max-width: 768px) {
        .home_image_container {
            margin-bottom: 5%;
        }

        .stats-cards-container {
            flex-direction: column;
            gap: 1.5rem;
            padding: 1.2rem 0.5rem;
            margin-top: -30px;
            margin-right: 20px;
            margin-left: 20px;
            max-width: calc(100% - 40px);
        }

        .stats-card {
            gap: 0.8rem;
            padding: 0.5rem;
            justify-content: center;
        }

        .stats-count {
            font-size: 18px;
        }

        .stats-label {
            font-size: 14px;
        }

        .angled-divider {
            margin-top: -8%;
            height: 80px;
            width: 40%;
        }

        .about-section-hero {
            height: 160px;
            margin-bottom: 25px;
        }

        .about-bg-text {
            font-size: 2rem;
            letter-spacing: 1.5px;
            left: 10%;
            top: 85%;
        }

        .about-content-box {
            margin-right: 20px;
            margin-left: 20px;
            padding: 20px 24px;
            width: calc(100% - 40px);
        }

        .about-description {
            font-size: 0.85rem;
            width: 100%;
        }
    }

    @media (max-width: 600px) {
        .home_image_container {
            margin-bottom: 4%;
        }

        .stats-cards-container {
            gap: 1.2rem;
            padding: 1rem 0.4rem;
            margin-top: -25px;
            margin-right: 15px;
            margin-left: 15px;
        }

        .stats-card {
            gap: 0.6rem;
            padding: 0.4rem;
        }

        .stats-count {
            font-size: 16px;
        }

        .stats-label {
            font-size: 13px;
        }

        .angled-divider {
            margin-top: -6%;
            height: 60px;
            width: 50%;
        }

        .about-section-hero {
            height: auto;
            margin-bottom: 20px;
        }

        .about-bg-text {
            font-size: 1.6rem;
            letter-spacing: 1px;
            left: 8%;
            top: 0;
        }

        .about-content-box {
            margin-right: 15px;
            margin-left: 15px;
            padding: 16px 20px;
        }

        .about-description {
            font-size: 0.8rem;
        }
    }

    @media (max-width: 480px) {
        .home_image_container {
            margin-bottom: 3%;
        }

        .stats-cards-container {
            gap: 1rem;
            padding: 0.8rem 0.3rem;
            margin-top: -20px;
            margin-right: 10px;
            margin-left: 10px;
        }

        .stats-card {
            gap: 0.5rem;
            padding: 0.3rem;
        }

        .stats-count {
            font-size: 14px;
        }

        .stats-label {
            font-size: 12px;
        }

        .angled-divider {
            margin-top: -4%;
            height: 50px;
            width: 60%;
        }

        .about-section-hero {
            margin-bottom: 15px;
        }

        .about-bg-text {
            font-size: 1.3rem;
            letter-spacing: 0.8px;
            left: 6%;
            top: 0;
        }

        .about-content-box {
            margin-right: 10px;
            margin-left: 10px;
            padding: 12px 16px;
        }

        .about-description {
            font-size: 0.75rem;
        }
    }

    @media (max-width: 360px) {
        .home_image_container {
            margin-bottom: 2%;
        }

        .stats-cards-container {
            gap: 0.8rem;
            padding: 0.6rem 0.2rem;
            margin-top: -15px;
            margin-right: 8px;
            margin-left: 8px;
        }

        .stats-card {
            gap: 0.4rem;
            padding: 0.2rem;
        }

        .stats-count {
            font-size: 12px;
        }

        .stats-label {
            font-size: 11px;
        }

        .angled-divider {
            margin-top: -3%;
            height: 40px;
            width: 70%;
        }

        .about-section-hero {
            height: 100px;
            margin-bottom: 12px;
        }

        .about-bg-text {
            font-size: 1.1rem;
            letter-spacing: 0.5px;
            left: 4%;
            top: 0;
        }

        .about-content-box {
            margin-right: 8px;
            margin-left: 8px;
            padding: 10px 12px;
        }

        .about-description {
            font-size: 0.7rem;
        }
    }

    /*  popup offer */
    .backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        /* Semi-transparent black */
        backdrop-filter: blur(5px);
        /* Apply a blur effect */
        z-index: 10;
        /* Ensure backdrop is behind the popup */
        display: none;
        /* Initially hide the backdrop */
    }


    .popup_offer {
        background-color: #E2F4FF;
        background-blend-mode: lighten;
        width: 432px;
        height: 364px;
        position: fixed;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        z-index: 11;
        display: none;
        text-align: center;
        border-radius: 10px;
    }

    .background_popup {
        position: relative;
        margin: 5%;
        width: 90%;
        height: 90%;
        z-index: 10;
        opacity: 0.25;
    }

    .popup_offer .close {
        height: 15px;
        width: 15px;
        position: absolute;
        top: 8px;
        right: 8px;
    }

    #close {
        position: absolute;
        top: 10px;
        right: 10px;
        background-color: #E2F4FF;
        z-index: 12;
        border: none;
    }

    .popup_content {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        top: 20%;
        left: 30%;
        position: absolute;
        z-index: 12;
    }

    .popup_content h3 {
        font-weight: 600;
        font-size: 28px;
        color: #AC1613;
    }

    .popup_content .per_symbol {
        display: flex;
        flex-direction: row;
    }

    .popup_content .per_symbol .percentage {
        color: #0B6F44;
        font-size: 110px;
        font-weight: 500;
        font-family: Arial, Helvetica, sans-serif;
        font-style: sans-serif;
    }

    .symbol {
        padding: 10px;
    }

    .symbol .symbol_per {
        font-size: 54px;
        font-weight: 400;
        color: #1C7AB2;
        font-family: 'Oranienbaum'
    }

    .symbol .symbol_letter {
        font-size: 24px;
        font-weight: 350;
        color: #1C7AB2;
        font-family: 'Kyiv*Type Serif';
    }

    .popup_offer .students {
        color: #303030;
        font-size: 14px;
        font-weight: 200;
        font-family: 'Kyiv*Type Serif';
    }
</style>
<script>
    document.addEventListener("DOMContentLoaded", function() {
        const offerButton = document.getElementById('offer-button');
        const backdrop = document.getElementById('backdrop');
        const popupOffer = document.getElementById('popup_offer');
        const closeButton = document.getElementById('close');

        offerButton.addEventListener('click', togglePopup);
        closeButton.addEventListener('click', togglePopup);
        backdrop.addEventListener('click', togglePopupOutside);

        function togglePopup() {
            console.log('Toggle popup called');
            backdrop.style.display = backdrop.style.display === 'block' ? 'none' : 'block';
            popupOffer.style.display = popupOffer.style.display === 'block' ? 'none' : 'block';
            document.body.style.overflow = backdrop.style.display === 'block' ? 'hidden' : '';
        }

        function togglePopupOutside(event) {
            console.log('Toggle popup outside called');
            if (event.target === this) { // Check if the click occurred on the backdrop itself
                togglePopup();
            }
        }
    });
</script>
<script>
    let animationTimeout;
    document.addEventListener("DOMContentLoaded", function() {
        const offerButton = document.getElementById('offer-button');
        window.addEventListener("scroll", () => {
            if (window.pageYOffset > 510) {
                offerButton.style.top = "110px";
                offerButton.style.left = "0px";
                offerButton.style.visibility = "visible";
                offerButton.style.animationPlayState = "running"; // Start animation
                clearTimeout(animationTimeout); // Clear any existing timeout
                animationTimeout = setTimeout(function() {
                    offerButton.style.animationPlayState = "paused"; // Pause animation
                }, 1000); // 1000 milliseconds = 1 second
            } else {
                offerButton.style.top = "130px";
                offerButton.style.left = "-100px";
                offerButton.style.visibility = "hidden";
                offerButton.style.animationPlayState = "paused"; // Pause animation
                clearTimeout(animationTimeout); // Clear the timeout
            }
        });
    });
</script>
