{{-- projects/index.blade.php --}}
@extends('layouts.admin')
@section('title','Proyek CCTV')
@section('content')
<div class="card">
  <div class="card-header d-flex justify-content-between align-items-center">
    <span>Proyek Havva <span class="badge bg-secondary">{{ $projects->total() }}</span></span>
    <a href="{{ route('admin.projects.create') }}" class="btn btn-primary btn-sm"><i class="fas fa-plus me-1"></i>Proyek Baru</a>
  </div>
  <div class="table-responsive">
    <table class="table table-hover mb-0">
      <thead><tr><th>No. Proyek</th><th>Klien</th><th>Judul</th><th>Status</th><th>PIC</th><th>RAB</th><th>Mulai</th><th></th></tr></thead>
      <tbody>
      @forelse($projects as $p)
      @php $sc=['survey'=>'bg-secondary','rab_submitted'=>'bg-info','approved'=>'bg-primary','in_progress'=>'bg-warning text-dark','testing'=>'bg-info','done'=>'bg-success','cancelled'=>'bg-danger']; @endphp
      <tr>
        <td class="fw-semibold small text-primary"><a href="{{ route('admin.projects.show',$p) }}" class="text-decoration-none">{{ $p->project_number }}</a></td>
        <td class="small">{{ $p->client->name }}</td>
        <td class="small">{{ $p->title }}</td>
        <td><span class="badge {{ $sc[$p->status]??'bg-secondary' }}">{{ str_replace('_',' ',strtoupper($p->status)) }}</span></td>
        <td class="small">{{ $p->pic?->name ?? '—' }}</td>
        <td class="small">Rp {{ number_format($p->rab_amount,0,',','.') }}</td>
        <td class="small text-muted">{{ $p->start_date?->format('d/m/Y') ?? '—' }}</td>
        <td><a href="{{ route('admin.projects.show',$p) }}" class="btn btn-sm btn-outline-primary"><i class="fas fa-eye"></i></a>
        @if(auth()->user()->role === 'admin')
        <form action="{{ route('admin.projects.destroy',$p) }}" method="POST" onsubmit="return confirm('Hapus proyek ini?')" style="display:inline">@csrf @method('DELETE')<button class="btn btn-sm btn-outline-danger"><i class="fas fa-trash"></i></button></form>
        @endif
        </td>
      </tr>
      @empty<tr><td colspan="8" class="text-center text-muted py-4">Belum ada proyek</td></tr>
      @endforelse
      </tbody>
    </table>
  </div>
  <div class="card-footer">{{ $projects->links() }}</div>
</div>
@endsection
