@php
    $facility = \App\Models\Facility::first();
    $programs = \App\Models\Program::with('facilitymembers')->get();
@endphp

<div class="faculty-members-section">
    <h1 class="faculty-title">{{$facility->team_title}}</h1>

    @foreach($programs as $program)
        @if($program->facilitymembers->count() > 0)
            <div class="faculty-category">
                <div class="category-row">
                    <div class="program-title-container">
                        <h2>{{ $program->main_code }}</h2>
                    </div>
                    <div class="swiper-container-wrapper">
                        <div class="swiper-container {{ strtolower($program->main_code) }}-swiper">
                            <div class="swiper-wrapper">
                                @foreach($program->facilitymembers as $member)
                                    <div class="swiper-slide">
                                        <div class="faculty-card">
                                            <div class="card-header">
                                                <img src="{{ asset('storage/' . $member->member_img) }}"
                                                     alt="{{ $member->member_name }}"
                                                     class="faculty-img" />
                                            </div>
                                            <div class="faculty-name">{{ $member->member_name }}</div>
                                            <div class="faculty-position">{{ $member->member_position }} | {{ $member->member_job_title }}</div>
                                            <div class="card-body">
                                                <p>"{{ \Illuminate\Support\Str::words($member->member_desc, 30) }}"</p>
                                            </div>
                                        </div>
                                    </div>
                                @endforeach
                            </div>
                        </div>
                        {{-- <div class="swiper-pagination {{ strtolower($program->main_code) }}-pagination"></div> --}}
                    </div>
                </div>
            </div>
        @endif
    @endforeach
</div>

<style>
    .faculty-members-section {
        margin-top: 5%;
        padding: 48px;
        overflow-x: hidden;
    }
    .faculty-title{
        font-family: Poppins;
        font-weight: 600;
        font-size: 54px;
        line-height: 100%;
        letter-spacing: 2%;
        text-align: center;
        color: #004675;
        margin-bottom: 48px;
        margin-top: 48px;
    }

    .faculty-category {
        margin-bottom: 40px;
    }

    .category-row {
        display: flex;
        align-items: center;
        gap: 40px;
    }

    .program-title-container {
        flex: 0 0 150px;
        display: flex;
        justify-content: center;
        /* padding-top: 40px; */
    }

    .program-title-container h2 {
        font-size: 2.5rem;
        font-weight: bold;
    }

    .swiper-container-wrapper {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
    }

    .swiper-container {
        padding-bottom: 40px;
    }

    .swiper-slide {
        width: 320px !important;
        height: 350px;
        border-radius: 12px;
    }

    .faculty-card {
        padding: 30px 20px;
        border-radius: 12px;
        text-align: center;
        height: 100%;
    }

    .card-header .faculty-img {
        width: 110px;
        height: 110px;
        border-radius: 50%;
        object-fit: cover;
        padding: 5px;
        background: #fff;
        margin: 0 auto 15px auto;
    }

    .faculty-name {
        font-weight: bold;
        font-size: 1.25rem;
        margin-bottom: 5px;
    }

    .faculty-position {
        color: #6c757d;
        font-size: 0.9rem;
        margin-bottom: 20px;
    }

    .card-body p {
        color: #495057;
        font-size: 0.95rem;
        line-height: 1.6;
    }

    .faculty-category:nth-child(odd) h2 { color: #007bff; }
    .faculty-category:nth-child(odd) .faculty-card { background-color: #eaf6ff; }
    .faculty-category:nth-child(odd) .faculty-name { color: #007bff; }
    .faculty-category:nth-child(odd) .faculty-img { border: 4px solid #007bff; }
    .faculty-category:nth-child(odd) .swiper-pagination-bullet-active { background: #007bff; }

    .faculty-category:nth-child(even) h2 { color: #fd7e14; }
    .faculty-category:nth-child(even) .faculty-card { background-color: #fff0e1; }
    .faculty-category:nth-child(even) .faculty-name { color: #fd7e14; }
    .faculty-category:nth-child(even) .faculty-img { border: 4px solid #fd7e14; }
    .faculty-category:nth-child(even) .swiper-pagination-bullet-active { background: #fd7e14; }

    .swiper-pagination {
        bottom: 0 !important;
        position: relative;
        padding-top: 20px;
        text-align: left;
        padding-left: 10px;
    }
    .swiper-pagination-bullet {
        width: 10px;
        height: 10px;
        background: #ccc;
        opacity: 1;
    }



     /* Enhanced responsive styles */
     @media (max-width: 1200px) {
        .faculty-members-section {
            padding: 40px;
            margin-top: 4%;
        }
        .faculty-title {
            font-size: 48px;
            margin-bottom: 40px;
            margin-top: 40px;
        }
        .category-row {
            gap: 30px;
        }
        .program-title-container {
            flex: 0 0 130px;
        }
        .program-title-container h2 {
            font-size: 2.2rem;
        }
        .swiper-slide {
            width: 300px !important;
            height: 330px;
        }
        .faculty-card {
            padding: 25px 18px;
        }
        .card-header .faculty-img {
            width: 100px;
            height: 100px;
        }
        .faculty-name {
            font-size: 1.2rem;
        }
    }

    @media (max-width: 992px) {
        .faculty-members-section {
            padding: 35px;
            margin-top: 3%;
        }
        .faculty-title {
            font-size: 42px;
            margin-bottom: 35px;
            margin-top: 35px;
        }
        .faculty-category {
            margin-bottom: 35px;
        }
        .category-row {
            flex-direction: column;
            gap: 25px;
            text-align: center;
        }
        .program-title-container {
            flex: none;
            width: 100%;
        }
        .program-title-container h2 {
            font-size: 2rem;
        }
        .swiper-container-wrapper {
            width: 100%;
        }
        .swiper-slide {
            width: 280px !important;
            height: 320px;
        }
        .faculty-card {
            padding: 22px 16px;
        }
        .card-header .faculty-img {
            width: 90px;
            height: 90px;
        }
        .faculty-name {
            font-size: 1.15rem;
        }
        .faculty-position {
            font-size: 0.85rem;
            margin-bottom: 18px;
        }
        .card-body p {
            font-size: 0.9rem;
        }
    }

    @media (max-width: 768px) {
        .faculty-members-section {
            padding: 25px;
            margin-top: 2%;
        }
        .faculty-title {
            font-size: 36px;
            margin-bottom: 30px;
            margin-top: 30px;
        }
        .faculty-category {
            margin-bottom: 30px;
        }
        .category-row {
            gap: 20px;
        }
        .program-title-container h2 {
            font-size: 1.8rem;
        }
        .swiper-slide {
            width: 260px !important;
            height: 300px;
        }
        .faculty-card {
            padding: 20px 14px;
        }
        .card-header .faculty-img {
            width: 80px;
            height: 80px;
            margin-bottom: 12px;
        }
        .faculty-name {
            font-size: 1.1rem;
        }
        .faculty-position {
            font-size: 0.8rem;
            margin-bottom: 15px;
        }
        .card-body p {
            font-size: 0.85rem;
            line-height: 1.5;
        }
        .swiper-container {
            padding-bottom: 30px;
        }
    }

    @media (max-width: 600px) {
        .faculty-members-section {
            padding: 20px;
            margin-top: 1%;
        }
        .faculty-title {
            font-size: 30px;
            margin-bottom: 25px;
            margin-top: 25px;
        }
        .faculty-category {
            margin-bottom: 25px;
        }
        .category-row {
            gap: 15px;
        }
        .program-title-container h2 {
            font-size: 1.6rem;
        }
        .swiper-slide {
            width: 240px !important;
            height: 280px;
        }
        .faculty-card {
            padding: 18px 12px;
        }
        .card-header .faculty-img {
            width: 70px;
            height: 70px;
            margin-bottom: 10px;
        }
        .faculty-name {
            font-size: 1rem;
        }
        .faculty-position {
            font-size: 0.75rem;
            margin-bottom: 12px;
        }
        .card-body p {
            font-size: 0.8rem;
            line-height: 1.4;
        }
        .swiper-container {
            padding-bottom: 25px;
        }
    }

    @media (max-width: 480px) {
        .faculty-members-section {
            padding: 15px;
        }
        .faculty-title {
            font-size: 26px;
            margin-bottom: 20px;
            margin-top: 20px;
        }
        .faculty-category {
            margin-bottom: 20px;
        }
        .category-row {
            gap: 12px;
        }
        .program-title-container h2 {
            font-size: 1.4rem;
        }
        .swiper-slide {
            width: 220px !important;
            height: 260px;
        }
        .faculty-card {
            padding: 15px 10px;
        }
        .card-header .faculty-img {
            width: 60px;
            height: 60px;
            margin-bottom: 8px;
        }
        .faculty-name {
            font-size: 0.95rem;
        }
        .faculty-position {
            font-size: 0.7rem;
            margin-bottom: 10px;
        }
        .card-body p {
            font-size: 0.75rem;
            line-height: 1.3;
        }
        .swiper-container {
            padding-bottom: 20px;
        }
        .swiper-pagination {
            padding-top: 15px;
        }
        .swiper-pagination-bullet {
            width: 8px;
            height: 8px;
        }
    }

    @media (max-width: 360px) {
        .faculty-members-section {
            padding: 12px;
        }
        .faculty-title {
            font-size: 22px;
            margin-bottom: 18px;
            margin-top: 18px;
        }
        .faculty-category {
            margin-bottom: 18px;
        }
        .category-row {
            gap: 10px;
        }
        .program-title-container h2 {
            font-size: 1.2rem;
        }
        .swiper-slide {
            width: 200px !important;
            height: 240px;
        }
        .faculty-card {
            padding: 12px 8px;
        }
        .card-header .faculty-img {
            width: 50px;
            height: 50px;
            margin-bottom: 6px;
        }
        .faculty-name {
            font-size: 0.9rem;
        }
        .faculty-position {
            font-size: 0.65rem;
            margin-bottom: 8px;
        }
        .card-body p {
            font-size: 0.7rem;
            line-height: 1.2;
        }
        .swiper-container {
            padding-bottom: 18px;
        }
        .swiper-pagination {
            padding-top: 12px;
        }
        .swiper-pagination-bullet {
            width: 6px;
            height: 6px;
        }
    }
</style>

<script>
    document.addEventListener('DOMContentLoaded', function() {
        @foreach($programs as $program)
            @if($program->facilitymembers->count() > 0)
                var swiper_{{ $program->id }} = new Swiper(".{{ strtolower($program->main_code) }}-swiper", {
                    slidesPerView: 'auto',
                    spaceBetween: 30,
                    grabCursor: true,
                    pagination: {
                        el: ".{{ strtolower($program->main_code) }}-pagination",
                        clickable: true,
                    },
                });
            @endif
        @endforeach
    });
</script>