@extends('layouts.stage_academy_portal')

@section('title', __('stage_academy_portal.trainers.title'))

@section('body')
    @php
        $locale = app()->getLocale();
        $otherLocale = $locale === 'ar' ? 'en' : 'ar';
        $textDir = $locale === 'ar' ? 'rtl' : 'ltr';
        $active = $active ?? 'dashboard';
    @endphp

    <nav class="navbar navbar-expand-lg navbar-light bg-white bg-opacity-75 border-bottom sap-portal-navbar" style="backdrop-filter: blur(10px);">
        <div class="container">
            <div class="d-flex flex-column">
                <span class="navbar-brand fw-bold mb-0 sap-brand-shine">{{ __('stage_academy_portal.brand') }}</span>
            </div>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#sapNavbar" aria-controls="sapNavbar" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="sapNavbar">
                <div class="d-flex flex-column flex-lg-row {{ $locale === 'ar' ? 'flex-lg-row-reverse' : '' }} w-100 align-items-lg-center justify-content-lg-between gap-2 py-2 py-lg-0">
                    <ul class="navbar-nav mb-0">
                        <li class="nav-item">
                            <a class="nav-link {{ $active === 'my_courses' ? 'active fw-semibold' : '' }}" href="{{ route('stage-academy-portal.my-courses') }}">{{ __('stage_academy_portal.nav.my_courses') }}</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {{ $active === 'profile' ? 'active fw-semibold' : '' }}" href="{{ route('stage-academy-portal.profile') }}">{{ __('stage_academy_portal.nav.profile') }}</a>
                        </li>
                    </ul>

                    <div class="d-flex align-items-center gap-2">
                        <div class="sap-welcome-text d-flex align-items-center gap-2 small text-secondary" dir="{{ $textDir }}">
                            @if(! empty($portalUser->image) && \Illuminate\Support\Facades\Schema::hasColumn('stage_academy_users', 'image'))
                                <img src="{{ asset('storage/'.$portalUser->image) }}" alt="{{ $portalUser->name }}" style="width: 32px; height: 32px; object-fit: cover; border-radius: 50%;">
                            @else
                                <div class="d-flex align-items-center justify-content-center bg-white border rounded-circle" style="width: 32px; height: 32px;">
                                    <i class="bi bi-person-fill text-secondary"></i>
                                </div>
                            @endif
                            <span>{{ __('stage_academy_portal.welcome') }} <strong>{{ $portalUser->name }}</strong></span>
                        </div>
                        <a href="{{ route('lang.switch', $otherLocale) }}" class="btn btn-sm btn-outline-secondary" dir="ltr">
                            {{ strtoupper($otherLocale) }}
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </nav>

    <div class="container py-3 py-md-4">
        <div class="d-flex align-items-center justify-content-between gap-3 flex-wrap mb-3">
            <div>
                <div class="fw-bold fs-4">{{ __('stage_academy_portal.trainers.title') }}</div>
                <div class="text-secondary mt-1">{{ __('stage_academy_portal.trainers.subtitle') }}</div>
            </div>
            <a href="{{ route('stage-academy-portal.dashboard') }}" class="btn btn-sm btn-outline-success">
                <i class="bi {{ $locale === 'ar' ? 'bi-arrow-right' : 'bi-arrow-left' }}"></i> {{ __('common.back') }}
            </a>
        </div>

        @if(isset($trainers) && $trainers->isNotEmpty())
            <div class="card border-0 shadow-sm rounded-4">
                <div class="card-body p-3 p-md-4">
                    <div class="sap-trainers-strip" style="margin-top: 0;">
                        @foreach($trainers as $trainer)
                            <a href="{{ route('stage-academy-portal.trainers.show', $trainer->id) }}" class="sap-trainer-item">
                                <div class="sap-trainer-avatar">
                                    @if(! empty($trainer->image))
                                        <img src="{{ asset('storage/'.$trainer->image) }}" alt="{{ $locale === 'ar' ? $trainer->name_ar : $trainer->name_en }}">
                                    @else
                                        <i class="bi bi-person-circle"></i>
                                    @endif
                                </div>
                                <div class="sap-trainer-name">
                                    {{ $locale === 'ar' ? $trainer->name_ar : $trainer->name_en }}
                                </div>
                            </a>
                        @endforeach
                    </div>
                </div>
            </div>
        @else
            <div class="card border-0 shadow-sm rounded-4">
                <div class="card-body p-4 p-md-5 text-center text-secondary">
                    <i class="bi bi-people fs-2 d-block mb-2"></i>
                    <div class="fw-semibold">{{ __('stage_academy_portal.trainers.empty_title') }}</div>
                    <div class="mt-1">{{ __('stage_academy_portal.trainers.empty_body') }}</div>
                </div>
            </div>
        @endif
    </div>
@endsection
