@extends('layouts.admin')
@section('title','Laporan CSAT')
@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 Respons</div><div class="fw-bold fs-3">{{ $surveys->count() }}</div></div></div>
  <div class="col-md-4"><div class="card p-3 text-center"><div class="text-muted small">Rata-rata Rating</div><div class="fw-bold fs-3" style="color:#f59e0b">{{ $avg }} ⭐</div></div></div>
  <div class="col-md-4"><div class="card p-3"><div class="text-muted small mb-2">Distribusi</div>@for($i=5;$i>=1;$i--)<div class="d-flex align-items-center gap-2 mb-1"><span class="small">{{ $i }}⭐</span><div class="flex-1" style="background:#e5e7eb;border-radius:4px;height:12px;flex:1"><div style="background:#f59e0b;height:100%;border-radius:4px;width:{{ $surveys->count() ? ($dist[$i]??0)/$surveys->count()*100 : 0 }}%"></div></div><span class="small text-muted">{{ $dist[$i]??0 }}</span></div>@endfor</div></div>
</div>
<div class="card">
  <div class="table-responsive">
    <table class="table table-hover mb-0">
      <thead><tr><th>Tiket</th><th>Klien</th><th>Rating</th><th>Feedback</th><th>Tgl Respons</th></tr></thead>
      <tbody>
      @forelse($surveys as $s)
      <tr>
        <td class="small"><a href="{{ route('admin.tickets.show',$s->ticket) }}" class="text-decoration-none">{{ $s->ticket->ticket_number }}</a></td>
        <td class="small">{{ $s->ticket->client->name }}</td>
        <td>{{ str_repeat('⭐',$s->rating) }}</td>
        <td class="small text-muted">{{ $s->feedback ?? '—' }}</td>
        <td class="small text-muted">{{ $s->answered_at?->format('d/m/Y') }}</td>
      </tr>
      @empty<tr><td colspan="5" class="text-center text-muted py-4">Belum ada data CSAT</td></tr>
      @endforelse
      </tbody>
    </table>
  </div>
</div>
@endsection
