@extends('layouts.client')
@section('title','Dashboard')
@section('content')
<div class="mb-3">
  <h5 class="fw-bold">Selamat datang, {{ $user->name }}!</h5>
  <p class="text-muted small">{{ $client->name }} · {{ $client->type_label }}</p>
</div>
<div class="row g-3 mb-4">
  <div class="col-4"><div class="card p-3 text-center"><div class="text-muted small">Tiket Open</div><div class="fw-bold fs-3 text-primary">{{ $stats['open'] }}</div></div></div>
  <div class="col-4"><div class="card p-3 text-center"><div class="text-muted small">In Progress</div><div class="fw-bold fs-3 text-warning">{{ $stats['progress'] }}</div></div></div>
  <div class="col-4"><div class="card p-3 text-center"><div class="text-muted small">Selesai</div><div class="fw-bold fs-3 text-success">{{ $stats['resolved'] }}</div></div></div>
</div>
<div class="row g-3">
  <div class="col-lg-7">
    <div class="card">
      <div class="card-header d-flex justify-content-between align-items-center">
        <span>Tiket Terbaru</span>
        <a href="{{ route('client.tickets.create') }}" class="btn btn-primary btn-sm"><i class="fas fa-plus me-1"></i>Buat Tiket</a>
      </div>
      <div class="list-group list-group-flush">
        @forelse($recent as $t)
        <a href="{{ route('client.tickets.show',$t) }}" class="list-group-item list-group-item-action py-2">
          <div class="d-flex justify-content-between">
            <span class="fw-semibold small">{{ $t->ticket_number }}</span>
            <span class="badge bg-{{ $t->status_badge }} small">{{ str_replace('_',' ',strtoupper($t->status)) }}</span>
          </div>
          <div class="text-muted" style="font-size:12px">{{ $t->subject }}</div>
        </a>
        @empty<div class="list-group-item text-center text-muted small py-3">Belum ada tiket</div>
        @endforelse
      </div>
    </div>
  </div>
  <div class="col-lg-5">
    @if($pendingInvoices->count())
    <div class="card">
      <div class="card-header fw-semibold text-danger"><i class="fas fa-exclamation-circle me-1"></i>Invoice Belum Dibayar</div>
      <div class="list-group list-group-flush">
        @foreach($pendingInvoices as $inv)
        <div class="list-group-item py-2">
          <div class="d-flex justify-content-between">
            <span class="fw-semibold small">{{ $inv->invoice_number }}</span>
            <span class="badge {{ $inv->status==='overdue'?'bg-danger':'bg-warning text-dark' }}">{{ strtoupper($inv->status) }}</span>
          </div>
          <div class="d-flex justify-content-between">
            <span class="text-muted" style="font-size:12px">Jatuh tempo: {{ $inv->due_date->format('d/m/Y') }}</span>
            <span class="fw-semibold small text-danger">Rp {{ number_format($inv->total,0,',','.') }}</span>
          </div>
        </div>
        @endforeach
      </div>
    </div>
    @endif
  </div>
</div>
@endsection
