@extends('admin.layouts.app')

@section('content')
    <h1 class="text-3xl font-bold mb-6">{{ isset($school) ? 'Edit School' : 'Create School' }}</h1>

    <form action="{{ isset($school) ? route('admin.schools.update', $school) : route('admin.schools.store') }}" method="POST" class="bg-white p-6 rounded shadow max-w-2xl">
        @csrf
        @if(isset($school))
            @method('PUT')
        @endif

        <div class="mb-4">
            <label class="block font-bold mb-2">School Name</label>
            <input type="text" name="name" value="{{ old('name', $school->name ?? '') }}" class="w-full border p-2 rounded" required>
            @error('name') <span class="text-red-500 text-sm">{{ $message }}</span> @enderror
        </div>

        <div class="mb-4">
            <label class="block font-bold mb-2">Manager</label>
            <select name="manager_id" class="w-full border p-2 rounded" required>
                <option value="">Select Manager</option>
                @foreach($managers as $manager)
                    <option value="{{ $manager->id }}" {{ old('manager_id', $school->manager_id ?? '') == $manager->id ? 'selected' : '' }}>
                        {{ $manager->name }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="mb-4">
            <label class="block font-bold mb-2">City</label>
            <select name="city_id" class="w-full border p-2 rounded" required>
                <option value="">Select City</option>
                @foreach($cities as $city)
                    <option value="{{ $city->id }}" {{ old('city_id', $school->city_id ?? '') == $city->id ? 'selected' : '' }}>
                        {{ $city->name }}
                    </option>
                @endforeach
            </select>
        </div>

        <div class="mb-4">
            <label class="block font-bold mb-2">Status</label>
            <select name="status" class="w-full border p-2 rounded" required>
                <option value="pending" {{ old('status', $school->status ?? '') == 'pending' ? 'selected' : '' }}>Pending</option>
                <option value="approved" {{ old('status', $school->status ?? '') == 'approved' ? 'selected' : '' }}>Approved</option>
                <option value="rejected" {{ old('status', $school->status ?? '') == 'rejected' ? 'selected' : '' }}>Rejected</option>
            </select>
        </div>

        <button type="submit" class="bg-blue-600 text-white px-4 py-2 rounded">
            {{ isset($school) ? 'Update School' : 'Save School' }}
        </button>
    </form>
@endsection
