@extends('layouts.teacher')
@section('title', 'Edit Gradebook')
@section('content')
    <x-page-head title="{{ $assessment->title }}" subtitle="{{ $assessment->subject?->name }} — {{ $assessment->schoolClass?->name }}">
        <x-slot:actions><a href="{{ route('teacher.gradebook.index') }}" class="btn btn-outline">Back</a></x-slot:actions>
    </x-page-head>
    <x-panel>
        <form method="POST" action="{{ route('teacher.gradebook.update', $assessment) }}">
            @csrf @method('PUT')
            <div class="table-wrap"><table><thead><tr><th>Student</th><th>Score (max {{ $assessment->max_score }})</th><th>Remarks</th></tr></thead><tbody>
                @foreach ($assessment->schoolClass->students as $student)
                    @php($entry = $assessment->gradebookEntries->firstWhere('student_id', $student->id))
                    <tr>
                        <td>{{ $student->full_name }}</td>
                        <td>
                            <input type="hidden" name="entries[{{ $loop->index }}][student_id]" value="{{ $student->id }}">
                            <input class="input" type="number" step="0.01" name="entries[{{ $loop->index }}][score]" value="{{ old('entries.'.$loop->index.'.score', $entry?->score) }}">
                        </td>
                        <td><input class="input" type="text" name="entries[{{ $loop->index }}][remarks]" value="{{ old('entries.'.$loop->index.'.remarks', $entry?->remarks) }}"></td>
                    </tr>
                @endforeach
            </tbody></table></div>
            <button type="submit" class="btn btn-primary" style="margin-top:12px;">Save Scores</button>
        </form>
    </x-panel>
@endsection
