@extends('layouts.app') @section('title', 'Timetable') @section('page-title', 'Timetable') @section('content')
{{-- Admin: Class Selector + Action Buttons --}} @if(auth()->user()->isAdmin())
@if(request('class_id')) @if(!$editMode) {{ $entries->isEmpty() ? 'Create Timetable' : 'Edit Timetable' }} @else Cancel @endif @endif
@endif {{-- Success Message --}} @if(session('success'))
{{ session('success') }}
@endif {{-- Validation Errors --}} @if($errors->any())
@foreach($errors->all() as $error)

{{ $error }}

@endforeach
@endif {{-- EDIT MODE: Editable Grid Form --}} @if(auth()->user()->isAdmin() && $editMode && request('class_id') && $periods->isNotEmpty())
@csrf
@foreach($days as $day) @endforeach @php $idx = 0; @endphp @foreach($periods as $period) @foreach($days as $day) @endforeach @endforeach
Period Time{{ ucfirst($day) }}
{{ $period->name }} {{ \Carbon\Carbon::parse($period->start_time)->format('h:i A') }} - {{ \Carbon\Carbon::parse($period->end_time)->format('h:i A') }} @if($period->is_break) Break @else @php $existing = $grid[$period->id][$day] ?? null; @endphp @php $idx++; @endphp @endif
{{-- VIEW MODE: Read-only Grid --}} @elseif($periods->isNotEmpty() && !empty($grid))
@foreach($days as $day) @endforeach @foreach($periods as $period) @foreach($days as $day) @endforeach @endforeach
Period Time{{ ucfirst($day) }}
{{ $period->name }} {{ \Carbon\Carbon::parse($period->start_time)->format('h:i A') }} - {{ \Carbon\Carbon::parse($period->end_time)->format('h:i A') }} @if($period->is_break) Break @elseif(isset($grid[$period->id][$day])) @php $entry = $grid[$period->id][$day]; @endphp

{{ $entry->subject?->name ?? '-' }}

{{ $entry->teacher?->name ?? '' }}

@if($entry->room)

{{ $entry->room }}

@endif
@else @endif
@else

{{ auth()->user()->isAdmin() ? 'Select a class to view or create a timetable.' : 'Select a class to view the timetable.' }}

@endif
@endsection