@extends('layouts.app')
@section('title', 'Notifications')
@section('crumbs', '<b>🔔 Notifications</b>')
@section('content')
<div class="card">
  <div class="card-h"><b>📌 My Tasks ({{ count($tasks) }})</b><span class="muted small" style="margin-left:auto">live · approvals + overdue + expiries</span></div>
  @if(!count($tasks))<div class="empty-state">Nothing needs you right now. ✅</div>@endif
  @foreach($tasks as $t)
    <a href="{{ $t['url'] }}" class="hrow" style="text-decoration:none;border-bottom:1px solid var(--border)">
      <span class="nm" style="font-size:18px">{{ $t['icon'] }}</span>
      <b>{{ $t['label'] }}</b>
      <span class="muted small" style="margin-left:auto;white-space:nowrap">{{ $t['sub'] }}</span>
    </a>
  @endforeach
</div>
<div class="card">
  <div class="card-h"><b>Unread ({{ $unread->count() }})</b>
    <span style="margin-left:auto">
      @if($unread->count())
      <form method="POST" action="{{ route('notifications.read-all') }}" style="display:inline">@csrf<button class="btn btn-sm">Mark all read</button></form>
      @endif
    </span>
  </div>
  @if(!$unread->count())<div class="empty-state">All caught up. 🎉</div>@endif
  @foreach($unread as $n)
    <a href="{{ route('notifications.open', $n->id) }}" class="hrow" style="text-decoration:none;border-bottom:1px solid var(--border)">
      <span class="nm" style="font-size:18px">{{ $n->data['icon'] ?? '🔔' }}</span>
      <b>{{ $n->data['title'] ?? $n->type }}</b>
      <span class="muted small">{{ $n->data['body'] ?? '' }}</span>
      <span class="muted small" style="margin-left:auto;white-space:nowrap">{{ $n->created_at->diffForHumans() }}</span>
    </a>
  @endforeach
</div>
@if($read->count())
<div class="card">
  <div class="card-h"><b>Recently read</b></div>
  @foreach($read as $n)
    <a href="{{ route('notifications.open', $n->id) }}" class="hrow" style="text-decoration:none;border-bottom:1px solid var(--border);opacity:.65">
      <span class="nm" style="font-size:18px">{{ $n->data['icon'] ?? '🔔' }}</span>
      <b>{{ $n->data['title'] ?? $n->type }}</b>
      <span class="muted small" style="margin-left:auto;white-space:nowrap">{{ $n->created_at->diffForHumans() }}</span>
    </a>
  @endforeach
</div>
@endif
@endsection
