@extends('layouts.app')
@section('title', 'Teacher Dashboard')
@section('page-title', 'Teacher Dashboard')
@section('sidebar-nav')
<div class="nav-item"><a href="{{ route('teacher.dashboard') }}"><i class="bi bi-grid"></i> Dashboard</a></div>
<div class="nav-item"><a href="{{ route('teacher.timetable') }}"><i class="bi bi-calendar3"></i> Timetable</a></div>
<div class="nav-item"><a href="{{ route('teacher.marks') }}"><i class="bi bi-pencil-square"></i> Enter Marks</a></div>
<div class="nav-item"><a href="{{ route('teacher.attendance') }}"><i class="bi bi-calendar-check"></i> Attendance</a></div>
@endsection

@section('content')
<div class="page-header">
    <div>
        <h1>Welcome, {{ auth()->user()->name }}</h1>
        <p>{{ now()->format('l, d F Y') }}</p>
    </div>
</div>

<div class="grid grid-3" style="margin-bottom:24px;">
    <div class="stat-card">
        <div class="stat-icon green"><i class="bi bi-book"></i></div>
        <div class="stat-info">
            <h3>{{ $streams->count() }}</h3>
            <p>Assigned Streams</p>
        </div>
    </div>
    <div class="stat-card">
        <div class="stat-icon blue"><i class="bi bi-file-earmark-text"></i></div>
        <div class="stat-info">
            <h3>{{ $assignments->count() }}</h3>
            <p>Assignments</p>
        </div>
    </div>
    <div class="stat-card">
        <div class="stat-icon amber"><i class="bi bi-person-badge"></i></div>
        <div class="stat-info">
            <h3>{{ $teacher->tsc_no ?? 'N/A' }}</h3>
            <p>TSC Number</p>
        </div>
    </div>
</div>

<div class="grid grid-2">
    <div class="card">
        <div class="card-header"><h5>My Subjects & Streams</h5></div>
        <div class="card-body" style="padding:0;">
            @forelse($streams as $assignment)
            <div style="padding:14px 20px;border-bottom:1px solid var(--border);display:flex;justify-content:space-between;align-items:center;">
                <div>
                    <div style="font-weight:500;">{{ $assignment->subject->name }}</div>
                    <div style="font-size:12px;color:var(--gray);">{{ $assignment->stream->schoolClass->name }} {{ $assignment->stream->name }}</div>
                </div>
                <a href="{{ route('teacher.marks', ['stream_id' => $assignment->stream_id, 'subject_id' => $assignment->subject_id]) }}" class="btn btn-sm btn-outline">Enter Marks</a>
            </div>
            @empty
            <div style="padding:20px;text-align:center;color:var(--gray);">No subjects assigned yet</div>
            @endforelse
        </div>
    </div>
    <div class="card">
        <div class="card-header">
            <h5>Recent Assignments</h5>
            <button onclick="document.getElementById('assignModal').style.display='flex'" class="btn btn-sm btn-primary">
                <i class="bi bi-plus"></i> New
            </button>
        </div>
        <div class="card-body" style="padding:0;">
            @forelse($assignments as $a)
            <div style="padding:14px 20px;border-bottom:1px solid var(--border);">
                <div style="font-weight:500;">{{ $a->title }}</div>
                <div style="font-size:12px;color:var(--gray);">Due: {{ $a->due_date->format('d M Y') }} &bull; {{ $a->subject->name }}</div>
            </div>
            @empty
            <div style="padding:20px;text-align:center;color:var(--gray);">No assignments yet</div>
            @endforelse
        </div>
    </div>
</div>

<!-- Assignment Modal -->
<div id="assignModal" style="display:none;position:fixed;inset:0;background:rgba(0,0,0,.5);z-index:2000;align-items:center;justify-content:center;">
    <div class="card" style="width:100%;max-width:500px;margin:20px;">
        <div class="card-header">
            <h5>Upload Assignment</h5>
            <button onclick="document.getElementById('assignModal').style.display='none'" style="background:none;border:none;cursor:pointer;font-size:20px;">&times;</button>
        </div>
        <div class="card-body">
            <form method="POST" action="{{ route('teacher.assignments.store') }}" enctype="multipart/form-data">
                @csrf
                <div class="form-group"><label>Title *</label><input type="text" name="title" required></div>
                <div class="form-group"><label>Description</label><textarea name="description" rows="3"></textarea></div>
                <div class="grid grid-2">
                    <div class="form-group">
                        <label>Subject *</label>
                        <select name="subject_id" required>
                            @foreach($streams as $s)
                                <option value="{{ $s->subject_id }}">{{ $s->subject->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group">
                        <label>Stream *</label>
                        <select name="stream_id" required>
                            @foreach($streams as $s)
                                <option value="{{ $s->stream_id }}">{{ $s->stream->schoolClass->name }} {{ $s->stream->name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="form-group"><label>Due Date *</label><input type="date" name="due_date" required></div>
                    <div class="form-group"><label>Total Marks</label><input type="number" name="total_marks" value="10" min="1"></div>
                </div>
                <div class="form-group"><label>File (PDF/DOC)</label><input type="file" name="file" accept=".pdf,.doc,.docx"></div>
                <button type="submit" class="btn btn-primary">Upload Assignment</button>
            </form>
        </div>
    </div>
</div>
@endsection
