@extends('layouts.teacher')
@section('title', ($material->exists ? 'Edit' : 'Upload') . ' Material')
@section('content')
    <x-page-head :title="$material->exists ? 'Edit Material' : 'Upload Material'" subtitle="Share resources with your class" />
    <x-panel>
        <form method="POST" action="{{ $material->exists ? route('teacher.materials.update', $material) : route('teacher.materials.store') }}" enctype="multipart/form-data">
            @csrf
            @if($material->exists) @method('PUT') @endif
            <div class="form-grid-2">
                <div class="form-group"><label class="form-label">Title</label><input class="input" name="title" value="{{ old('title', $material->title) }}" required></div>
                <div class="form-group"><label class="form-label">Class</label><select class="select w-full" name="class_id" required>@foreach($classes as $c)<option value="{{ $c->id }}" @selected(old('class_id', $material->class_id)==$c->id)>{{ $c->name }}</option>@endforeach</select></div>
                <div class="form-group"><label class="form-label">Subject</label><select class="select w-full" name="subject_id"><option value="">—</option>@foreach($subjects as $s)<option value="{{ $s->id }}" @selected(old('subject_id', $material->subject_id)==$s->id)>{{ $s->name }}</option>@endforeach</select></div>
                <div class="form-group"><label class="form-label">Type</label><select class="select w-full" name="material_type">@foreach(['document','video','audio','link','note','past_paper'] as $t)<option value="{{ $t }}" @selected(old('material_type', $material->material_type ?? 'document')==$t)>{{ ucfirst(str_replace('_',' ',$t)) }}</option>@endforeach</select></div>
                <div class="form-group"><label class="form-label">Status</label><select class="select w-full" name="status"><option value="draft" @selected(old('status', $material->status ?? 'draft')==='draft')>Draft</option><option value="published" @selected(old('status', $material->status)==='published')>Published</option></select></div>
                <div class="form-group"><label class="form-label">File</label><input class="input" type="file" name="file"></div>
                <div class="form-group" style="grid-column:1/-1;"><label class="form-label">External URL</label><input class="input" name="external_url" value="{{ old('external_url', $material->external_url) }}"></div>
                <div class="form-group" style="grid-column:1/-1;"><label class="form-label">Description</label><textarea class="input" name="description" rows="4">{{ old('description', $material->description) }}</textarea></div>
            </div>
            <button type="submit" class="btn btn-primary" style="margin-top:16px;">Save Material</button>
        </form>
    </x-panel>
@endsection
