<x-layouts::app :title="__('Edit School: ' . ($tenant->school_name ?: $tenant->tenant_id))">
    <div class="max-w-3xl mx-auto space-y-6">
        <flux:card>
            <flux:heading size="lg">{{ __('Edit School Details') }}</flux:heading>

            @if ($errors->any())
                <div class="rounded-2xl border border-rose-200 bg-rose-50 p-4 text-sm text-rose-700">
                    <ul class="list-disc pl-5">
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif

            <form method="POST" action="{{ route('admin.tenants.update', $tenant->tenant_id) }}" class="mt-6 space-y-6">
                @csrf
                @method('PUT')

                <div class="space-y-2">
                    <label for="tenant_id" class="block text-sm font-semibold text-slate-700">{{ __('Tenant ID (System Generated)') }}</label>
                    <input type="text" class="w-full rounded-xl border border-slate-200 bg-slate-100 px-4 py-3 text-sm text-slate-700" id="tenant_id" value="{{ $tenant->tenant_id }}" readonly disabled>
                    <p class="text-sm text-slate-500">{{ __('The tenant ID cannot be changed.') }}</p>
                </div>

                <div class="space-y-2">
                    <label for="school_name" class="block text-sm font-semibold text-slate-700">{{ __('School Name') }} <span class="text-rose-600">*</span></label>
                    <input type="text" class="w-full rounded-xl border border-slate-200 px-4 py-3 text-sm text-slate-900" id="school_name" name="school_name" value="{{ old('school_name', $tenant->school_name) }}" required>
                </div>

                <div class="space-y-2">
                    <label for="subscription_ends_at" class="block text-sm font-semibold text-slate-700">{{ __('Subscription End Date') }}</label>
                    <input type="date" class="w-full rounded-xl border border-slate-200 px-4 py-3 text-sm text-slate-900" id="subscription_ends_at" name="subscription_ends_at" value="{{ old('subscription_ends_at', $tenant->subscription_ends_at ? $tenant->subscription_ends_at->format('Y-m-d') : '') }}">
                    <p class="text-sm text-slate-500">{{ __('Leave blank if there is no explicit end date.') }}</p>
                </div>

                <div class="flex items-start gap-3">
                    <input type="checkbox" id="is_active" name="is_active" value="1" {{ old('is_active', $tenant->is_active) ? 'checked' : '' }} class="mt-2 h-5 w-5 rounded border-slate-300 text-sky-600 focus:ring-sky-500" />
                    <div>
                        <label for="is_active" class="block text-sm font-semibold text-slate-700">{{ __('Active Account') }}</label>
                        <p class="text-sm text-slate-500">{{ __('If disabled, the school\'s domain will not be accessible to their users.') }}</p>
                    </div>
                </div>

                <div class="flex flex-col gap-3 sm:flex-row sm:justify-between">
                    <a href="{{ route('admin.tenants.show', $tenant->tenant_id) }}" class="inline-flex items-center justify-center rounded-xl border border-slate-200 bg-slate-100 px-5 py-3 text-sm font-semibold text-slate-700 hover:bg-slate-200">{{ __('Cancel') }}</a>
                    <button type="submit" class="inline-flex items-center justify-center rounded-xl bg-sky-600 px-5 py-3 text-sm font-semibold text-white hover:bg-sky-700">
                        <i class="fas fa-save mr-2"></i> {{ __('Save Changes') }}
                    </button>
                </div>
            </form>
        </flux:card>
    </div>
</x-layouts::app>
