@extends('layouts.admin')
@section('title','Proyek '.$project->project_number)
@section('content')
@php $statusColors=['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
<div class="row justify-content-center"><div class="col-lg-8">
<div class="card mb-3">
  <div class="card-header d-flex justify-content-between">
    <div><span class="fw-bold text-primary">{{ $project->project_number }}</span>
    <span class="badge {{ $statusColors[$project->status]??'bg-secondary' }} ms-2">{{ str_replace('_',' ',strtoupper($project->status)) }}</span></div>
    <div class="d-flex gap-2">
      <a href="{{ route('admin.projects.edit',$project) }}" class="btn btn-sm btn-outline-secondary"><i class="fas fa-edit"></i></a>
      @if(auth()->user()->role === 'admin')
      <form action="{{ route('admin.projects.destroy',$project) }}" 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
    </div>
  </div>
  <div class="card-body">
    <h5 class="fw-bold mb-3">{{ $project->title }}</h5>
    <table class="table table-sm">
      <tr><td class="text-muted small" width="140">Klien</td><td><a href="{{ route('admin.clients.show',$project->client) }}">{{ $project->client->name }}</a></td></tr>
      <tr><td class="text-muted small">PIC</td><td class="small">{{ $project->pic?->name ?? '—' }}</td></tr>
      <tr><td class="text-muted small">Nilai RAB</td><td class="small fw-semibold">Rp {{ number_format($project->rab_amount,0,',','.') }}</td></tr>
      <tr><td class="text-muted small">Nilai Final</td><td class="small fw-semibold">Rp {{ number_format($project->final_amount,0,',','.') }}</td></tr>
      <tr><td class="text-muted small">Tgl Mulai</td><td class="small">{{ $project->start_date?->format('d/m/Y') ?? '—' }}</td></tr>
      <tr><td class="text-muted small">Tgl Selesai</td><td class="small">{{ $project->end_date?->format('d/m/Y') ?? '—' }}</td></tr>
    </table>
    @if($project->description)<p class="text-muted small mt-2">{{ $project->description }}</p>@endif
  </div>
</div>
<div class="card">
  <div class="card-header">Update Status</div>
  <div class="card-body">
    <form action="{{ route('admin.projects.status',$project) }}" method="POST" class="d-flex gap-2">@csrf
      <select name="status" class="form-select">
        @foreach(['survey','rab_submitted','approved','in_progress','testing','done','cancelled'] as $s)
        <option value="{{ $s }}" {{ $project->status===$s?'selected':'' }}>{{ str_replace('_',' ',strtoupper($s)) }}</option>
        @endforeach
      </select>
      <button type="submit" class="btn btn-primary text-nowrap">Update</button>
    </form>
  </div>
</div>
</div></div>
@endsection
