{{-- sla.blade.php --}}
@extends('layouts.admin')
@section('title','Laporan SLA')
@section('content')
<div class="card mb-3"><div class="card-body py-2"><form class="row g-2" method="GET"><div class="col-md-3"><input type="date" name="from" class="form-control form-control-sm" value="{{ $from }}"></div><div class="col-md-3"><input type="date" name="to" class="form-control form-control-sm" value="{{ $to }}"></div><div class="col-auto"><button type="submit" class="btn btn-primary btn-sm">Filter</button></div></form></div></div>
<div class="row g-3 mb-3">
  <div class="col-md-4"><div class="card p-3 text-center"><div class="text-muted small">Total Tiket dengan SLA</div><div class="fw-bold fs-3">{{ $tickets->count() }}</div></div></div>
  <div class="col-md-4"><div class="card p-3 text-center"><div class="text-muted small">SLA Compliance</div><div class="fw-bold fs-3 {{ $compliance >= 90 ? 'text-success' : ($compliance >= 70 ? 'text-warning' : 'text-danger') }}">{{ $compliance }}%</div></div></div>
  <div class="col-md-4"><div class="card p-3 text-center"><div class="text-muted small">SLA Breach</div><div class="fw-bold fs-3 text-danger">{{ $tickets->where('sla_status','breach')->count() }}</div></div></div>
</div>
<div class="card">
  <div class="table-responsive">
    <table class="table table-hover mb-0">
      <thead><tr><th>No. Tiket</th><th>Klien</th><th>Prioritas</th><th>Status Tiket</th><th>SLA Status</th><th>Deadline Selesai</th></tr></thead>
      <tbody>
      @forelse($tickets->take(50) as $t)
      <tr>
        <td><a href="{{ route('admin.tickets.show',$t) }}" class="text-decoration-none fw-semibold small">{{ $t->ticket_number }}</a></td>
        <td class="small">{{ $t->client->name }}</td>
        <td><span class="badge bg-{{ $t->priority_badge }}">{{ strtoupper($t->priority) }}</span></td>
        <td><span class="badge bg-{{ $t->status_badge }} small">{{ str_replace('_',' ',strtoupper($t->status)) }}</span></td>
        <td>@if($t->sla_status==='breach')<span class="badge badge-breach">BREACH</span>@elseif($t->sla_status==='warning')<span class="badge badge-warning">WARNING</span>@else<span class="badge badge-ok">OK</span>@endif</td>
        <td class="small {{ $t->sla_status==='breach'?'text-danger fw-bold':'' }}">{{ $t->sla_solve_deadline?->format('d/m/Y H:i') ?? '—' }}</td>
      </tr>
      @empty<tr><td colspan="6" class="text-center text-muted py-4">Tidak ada data</td></tr>
      @endforelse
      </tbody>
    </table>
  </div>
</div>
@endsection
