@extends('student.layouts.app') @section('content')
{{-- Header with Back to Dashboard --}}

Homework

Assignments & Tasks

{{-- Flash Messages --}} @if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif {{-- Filter Header + Unread Toggle --}}

Filter Homework

{{-- Smart Unread Toggle Button --}} {{ request('unread') ? 'Show All' : 'Unread Only' }}
{{-- Server-side validation error --}} @if($errors->any())
{{ $errors->first() }}
@endif
{{-- SUBJECT --}} {{-- FROM DATE --}} {{-- TO DATE --}}
{{-- Client-side instant error --}}
Clear
{{-- Homework List --}}
@forelse($homeworks as $hw) @php $hasUnreadReplies = ($hw->unread_replies ?? 0) > 0; $isNewHomework = ($hw->is_new ?? 0) > 0; $isUnread = $hasUnreadReplies || $isNewHomework; @endphp {{-- ✅ CORNER BADGE: Shows count for unread replies, or "NEW" for never-opened homework --}} @if($isUnread) @if($hasUnreadReplies) {{ $hw->unread_replies > 9 ? '9+' : $hw->unread_replies }} @else NEW @endif @endif
{{-- Icon --}}
{{-- Content --}}

{{ $hw->title ?: 'Untitled Assignment' }}

{{ \Carbon\Carbon::parse($hw->created_at)->format('d M') }}

{{ $hw->message }}

{{ $hw->subject_name ?? 'General' }} @if($hw->attachment) @endif
{{-- Chevron --}}
@empty

No homework found

@if(request('from_date') || request('to_date') || request('subject_id')) Try clearing the filters. @else Check back later for new assignments. @endif

@endforelse
{{-- Pagination --}} @if($homeworks->hasPages())
{{ $homeworks->links() }}
@endif
@endsection