@extends('layouts.app')

@section('content')
<div class="container-xxl flex-grow-1 container-p-y">
    <div class="card">
        <div class="card-header">
            <h5 class="mb-0">Create Assignment</h5>
            <hr/>
        </div>

        <div class="card-body">
            <form method="POST" action="{{ route('assignments.store') }}">
                @csrf

                <div class="row">

                    {{-- Course Select --}}
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Course</label>
                        <select name="course_id" class="form-control">
                            <option value="">-- Select Course --</option>
                            @foreach($courses as $course)
                                <option value="{{ $course->id }}" {{ old('course_id') == $course->id ? 'selected' : '' }}>
                                    {{ $course->title }}
                                </option>
                            @endforeach
                        </select>
                        @error('course_id') <small class="text-danger">{{ $message }}</small> @enderror
                    </div>

                    {{-- Due Date --}}
                    <div class="col-md-6 mb-3">
                        <label class="form-label">Due Date</label>
                        <input type="datetime-local" class="form-control" name="due_date" value="{{ old('due_date') }}">
                        @error('due_date') <small class="text-danger">{{ $message }}</small> @enderror
                    </div>

                    {{-- Title --}}
                    <div class="col-md-12 mb-3">
                        <label class="form-label">Title</label>
                        <input class="form-control" name="title" value="{{ old('title') }}">
                        @error('title') <small class="text-danger">{{ $message }}</small> @enderror
                    </div>

                    {{-- Description --}}
                    <div class="col-md-12 mb-3">
                        <label class="form-label">Description</label>
                        <textarea class="form-control" name="description" rows="4">{{ old('description') }}</textarea>
                        @error('description') <small class="text-danger">{{ $message }}</small> @enderror
                    </div>

                </div>

                <button class="btn btn-primary">Save</button>
                <a href="{{ url()->previous() }}" class="btn btn-secondary">Back</a>
            </form>
        </div>
    </div>
</div>
@endsection