{{-- projects/create.blade.php --}}
@extends('layouts.admin')
@section('title', isset($project) ? 'Edit Proyek' : 'Proyek Baru')
@section('content')
<div class="row justify-content-center"><div class="col-lg-7">
<div class="card">
  <div class="card-header">{{ isset($project) ? 'Edit '.$project->title : 'Buat Proyek Baru' }}</div>
  <div class="card-body">
    <form action="{{ isset($project) ? route('admin.projects.update',$project) : route('admin.projects.store') }}" method="POST">
    @csrf @if(isset($project)) @method('PUT') @endif
    <div class="row g-3">
      <div class="col-md-6"><label class="form-label fw-semibold">Klien *</label><select name="client_id" class="form-select" required><option value="">—</option>@foreach($clients as $c)<option value="{{ $c->id }}" {{ ($project->client_id??'')==$c->id?'selected':'' }}>{{ $c->name }}</option>@endforeach</select></div>
      <div class="col-md-6"><label class="form-label fw-semibold">PIC</label><select name="pic_id" class="form-select"><option value="">—</option>@foreach($users as $u)<option value="{{ $u->id }}" {{ ($project->pic_id??'')==$u->id?'selected':'' }}>{{ $u->name }}</option>@endforeach</select></div>
      <div class="col-12"><label class="form-label fw-semibold">Judul Proyek *</label><input type="text" name="title" class="form-control" value="{{ old('title',$project->title??'') }}" required></div>
      <div class="col-12"><label class="form-label fw-semibold">Deskripsi</label><textarea name="description" class="form-control" rows="3">{{ old('description',$project->description??'') }}</textarea></div>
      <div class="col-md-4"><label class="form-label fw-semibold">Nilai RAB (Rp)</label><input type="number" name="rab_amount" class="form-control" value="{{ old('rab_amount',$project->rab_amount??0) }}"></div>
      <div class="col-md-4"><label class="form-label fw-semibold">Tgl Mulai</label><input type="date" name="start_date" class="form-control" value="{{ old('start_date',$project->start_date?->format('Y-m-d')??'') }}"></div>
      <div class="col-md-4"><label class="form-label fw-semibold">Tgl Selesai</label><input type="date" name="end_date" class="form-control" value="{{ old('end_date',$project->end_date?->format('Y-m-d')??'') }}"></div>
      <div class="col-12 d-flex gap-2 justify-content-end"><a href="{{ route('admin.projects.index') }}" class="btn btn-secondary">Batal</a><button type="submit" class="btn btn-primary"><i class="fas fa-save me-1"></i>Simpan</button></div>
    </div>
    </form>
  </div>
</div>
</div></div>
@endsection
