@extends('layouts.stage_academy_portal')

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

@section('body')
    @php
        $locale = app()->getLocale();
        $otherLocale = $locale === 'ar' ? 'en' : 'ar';
        $textDir = $locale === 'ar' ? 'rtl' : 'ltr';
        $active = $active ?? 'dashboard';
        $trainerName = $locale === 'ar' ? $trainer->name_ar : $trainer->name_en;
        $trainerDetails = $locale === 'ar' ? (string) $trainer->details_ar : (string) $trainer->details_en;
        $trainerDetails = trim($trainerDetails);
    @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">
            <a href="{{ route('stage-academy-portal.trainers') }}" class="btn btn-sm btn-outline-success">
                <i class="bi {{ $locale === 'ar' ? 'bi-arrow-right' : 'bi-arrow-left' }}"></i> {{ __('common.back') }}
            </a>
        </div>

        <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
            <div class="card-body p-4 p-md-5" style="background: radial-gradient(700px 350px at 10% 20%, rgba(34, 197, 94, 0.16), transparent 55%), radial-gradient(700px 350px at 90% 10%, rgba(16, 185, 129, 0.12), transparent 55%);">
                <div class="d-flex align-items-start gap-4 flex-column flex-md-row">
                    <div class="sap-trainer-hero-avatar flex-shrink-0">
                        @if(! empty($trainer->image))
                            <img src="{{ asset('storage/'.$trainer->image) }}" alt="{{ $trainerName }}">
                        @else
                            <i class="bi bi-person-circle"></i>
                        @endif
                    </div>

                    <div class="flex-grow-1">
                        <div class="fw-bold fs-3">{{ $trainerName }}</div>
                        @if($trainerDetails !== '')
                            <div class="text-secondary mt-3 text-break">{{ $trainerDetails }}</div>
                        @endif

                        @php
                            $socials = [
                                ['key' => 'facebook', 'url' => $trainer->facebook, 'icon' => 'bi-facebook', 'label' => 'Facebook'],
                                ['key' => 'instagram', 'url' => $trainer->instagram, 'icon' => 'bi-instagram', 'label' => 'Instagram'],
                                ['key' => 'tiktok', 'url' => $trainer->tiktok, 'icon' => 'bi-tiktok', 'label' => 'TikTok'],
                                ['key' => 'youtube', 'url' => $trainer->youtube, 'icon' => 'bi-youtube', 'label' => 'YouTube'],
                                ['key' => 'twitter', 'url' => $trainer->twitter, 'icon' => 'bi-twitter-x', 'label' => 'X'],
                                ['key' => 'website', 'url' => $trainer->website, 'icon' => 'bi-globe2', 'label' => 'Website'],
                            ];
                            $hasSocials = collect($socials)->contains(fn ($s) => ! empty(trim((string) $s['url'])));
                        @endphp

                        @if($hasSocials)
                            <div class="mt-4">
                                <div class="fw-semibold mb-2">{{ __('stage_academy_portal.trainers.socials_title') }}</div>
                                <div class="d-flex flex-wrap gap-2">
                                    @foreach($socials as $social)
                                        @php $url = trim((string) $social['url']); @endphp
                                        @if($url !== '')
                                            <a
                                                href="{{ $url }}"
                                                target="_blank"
                                                rel="noopener"
                                                class="btn btn-sm btn-outline-success d-inline-flex align-items-center gap-2"
                                                aria-label="{{ $social['label'] }}"
                                                title="{{ $social['label'] }}"
                                            >
                                                <i class="bi {{ $social['icon'] }}"></i>
                                                <span class="d-none d-sm-inline">{{ $social['label'] }}</span>
                                            </a>
                                        @endif
                                    @endforeach
                                </div>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
