<x-app-layout>
    <div class="container my-5">
        <h2 class="mb-4">Add Module</h2>

        @if(session('success'))
            <div class="alert alert-success mb-3">
                {{ session('success') }}
            </div>
        @endif

        <form action="{{ route('admin.modules.create') }}" method="POST">
            @csrf

            <div class="mb-3">
                <label for="course_id" class="form-label">Select Course</label>
                <select name="course_id" id="course_id"
                        class="form-select @error('course_id') is-invalid @enderror"
                        required>
                    <option value="">-- Choose a Course --</option>
                    @foreach($courses as $course)
                        <option value="{{ $course->id }}">
                            {{ $course->subject->name }} ({{ $course->level->name }})
                        </option>
                    @endforeach
                </select>
                @error('course_id')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="mb-3">
                <label for="name" class="form-label">Module Name</label>
                <input type="text" name="name" id="name"
                       class="form-control @error('name') is-invalid @enderror"
                       value="{{ old('name') }}" required>
                @error('name')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <div class="mb-3">
                <label for="order" class="form-label">Order (optional)</label>
                <input type="number" name="order" id="order"
                       class="form-control @error('order') is-invalid @enderror"
                       value="{{ old('order') }}">
                @error('order')
                    <div class="invalid-feedback">{{ $message }}</div>
                @enderror
            </div>

            <button type="submit" class="btn btn-primary">Add Module</button>
        </form>
    </div>
</x-app-layout>