@extends('admin.layouts.app')

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

@section('content')
    <x-admin.page-header title="{{ __('dashboard.edit_academy') }}" :breadcrumbs="[__('dashboard.academies') => route('admin.academies.index'), __('dashboard.edit_academy') => '']" />

    <div class="row">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header">
                    <h5 class="card-title mb-0">{{ __('dashboard.academy_information') }}</h5>
                </div>
                <div class="card-body">
                    <x-form action="{{ route('admin.academies.update', $academy) }}" method="PUT">
                        @include('admin.academies.__inputs')
                    </x-form>
                </div>
            </div>
        </div>
    </div>
@endsection

@push('scripts')
<script>
document.addEventListener('DOMContentLoaded', function () {
    const gameSelect = document.querySelector('select[name="game_id"]');
    const coachesSelect = document.getElementById('academy-coaches-select');
    if (!gameSelect || !coachesSelect) return;
    function filterCoachesByGame() {
        const gameId = (gameSelect.value || '').toString();
        Array.from(coachesSelect.options).forEach(opt => {
            if (opt.value === '') return;
            const optGameId = (opt.getAttribute('data-game-id') || '').toString();
            const show = gameId && optGameId === gameId;
            opt.hidden = !show;
            opt.disabled = !show;
            if (!show && opt.selected) opt.selected = false;
        });
    }
    gameSelect.addEventListener('change', filterCoachesByGame);
    filterCoachesByGame();
});
</script>
@endpush
