@extends('admin.layouts.app')

@section('title', __('dashboard.coach_details'))

@section('content')
<x-admin.page-header title="{{ __('dashboard.coach_details') }}" :breadcrumbs="[__('dashboard.coaches') => route('admin.coaches.index'), __('dashboard.details') => '']" />
<div class="row justify-content-center">
    <div class="col-xl-12">
        <div class="card mb-4">
            <div class="card-body">
                @if($coach->image)
                    <img src="{{ asset('storage/' . $coach->image) }}" alt="{{ $coach->name }}" class="img-fluid rounded mb-3" style="max-height: 200px; object-fit: cover;">
                @endif
                <div class="d-flex justify-content-between align-items-start">
                    <div>
                        <h3 class="mb-1">{{ $coach->name }}</h3>
                        <p class="text-muted mb-0">{{ $coach->phone ?? '-' }}</p>
                        <p class="text-muted mb-0">{{ $coach->email ?? '-' }}</p>
                    </div>
                    @if($coach->is_active)
                        <span class="badge bg-success">{{ __('dashboard.active') }}</span>
                    @else
                        <span class="badge bg-danger">{{ __('dashboard.inactive') }}</span>
                    @endif
                </div>
            </div>
        </div>
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">{{ __('dashboard.general_info') }}</h5>
            </div>
            <div class="card-body">
                <div class="row">
                    <x-view-col label="{{ __('dashboard.id') }}" :value="$coach->id"/>
                    <x-view-col label="{{ __('dashboard.game') }}" :value="$coach->game?->name ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.name') }}" :value="$coach->name"/>
                    <x-view-col label="{{ __('dashboard.phone') }}" :value="$coach->phone ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.email') }}" :value="$coach->email ?? '-'"/>
                    <x-view-col label="{{ __('dashboard.created_at') }}" :value="$coach->created_at"/>
                    <x-view-col label="{{ __('dashboard.updated_at') }}" :value="$coach->updated_at"/>
                </div>
                @if($coach->academies->isNotEmpty())
                    <hr>
                    <h6>{{ __('dashboard.academies') }}</h6>
                    <div class="row g-3">
                        @foreach($coach->academies as $academy)
                            <div class="col-md-6 col-lg-4">
                                <div class="card h-100 shadow-sm">
                                    @if($academy->image)
                                        <img src="{{ asset('storage/' . $academy->image) }}" class="card-img-top" alt="{{ $academy->name }}" style="height: 140px; object-fit: cover;">
                                    @else
                                        <img src="{{ asset('images/default-academy.png') }}" class="card-img-top" alt="{{ $academy->name }}" style="height: 140px; object-fit: cover;">
                                    @endif
                                    <div class="card-body d-flex flex-column">
                                        <h6 class="card-title mb-1">{{ $academy->name }}</h6>
                                        <p class="card-text text-muted mb-2">{{ $academy->game?->name ?? '-' }}</p>
                                        <a href="{{ route('admin.academies.show', $academy->id) }}" class="btn btn-sm btn-primary mt-auto">{{ __('dashboard.view') }}</a>
                                    </div>
                                </div>
                            </div>
                        @endforeach
                    </div>
                @endif
            </div>
        </div>

        {{-- ===== SLOTS SECTION ===== --}}
        @if($coach->game_id)
        <div class="card mt-4 mb-4">
            <div class="card-header d-flex justify-content-between align-items-center flex-wrap gap-2">
                <h5 class="card-title mb-0">
                    <i class="ri-time-line me-1"></i>{{ __('dashboard.slots') }}
                    <small class="text-muted fs-12">({{ $coach->game?->name ?? '' }})</small>
                </h5>
                <div class="d-flex align-items-center gap-2">
                    <input type="date" id="slot-date-filter" class="form-control form-control-sm" style="width:160px" value="{{ now()->toDateString() }}">
                    <input type="hidden" id="slot-coach-filter" value="{{ $coach->id }}">
                    <a href="{{ route('admin.slots.index') }}?coach_id={{ $coach->id }}" class="btn btn-sm btn-soft-primary">
                        {{ __('dashboard.view_all') }}
                    </a>
                </div>
            </div>
            <div class="card-body">
                <div class="table-responsive custom-scrollbar server-side-table">
                    {!! $dataTable->table(['class' => 'table table-bordered', 'id' => 'slots-table']) !!}
                </div>
            </div>
        </div>
        @endif
    </div>
</div>
@endsection

@push('scripts')
@if($coach->game_id)
{!! $dataTable->scripts() !!}
<script>
document.addEventListener('DOMContentLoaded', function () {
    const table = $('#slots-table').DataTable();


    $('#slot-date-filter').on('change', function () {
        table.draw();
    });
});
</script>
@endif
@endpush

