@extends('layouts.app')

@section('title', 'Edit Kontrak - TUNJUK-i')

@section('content')
<div class="mb-6">
    <div class="flex items-center justify-between">
        <div>
            <h1 class="text-2xl font-bold text-[#0b2b4a] flex items-center gap-2">
                <i class="fas fa-edit text-[#c9a84c]"></i>
                Edit Kontrak
            </h1>
            <p class="text-gray-500 text-sm mt-1">{{ $contract->contract_number }}</p>
        </div>
        <a href="{{ route('ppk.contracts.index') }}" class="text-gray-600 hover:text-gray-800 transition">
            <i class="fas fa-arrow-left mr-1"></i> Kembali
        </a>
    </div>
</div>

@if($errors->any())
    <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
        <ul>
            @foreach($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6">
    <form action="{{ route('ppk.contracts.update', $contract) }}" method="POST">
        @csrf
        @method('PUT')

        <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Nilai Kontrak *</label>
                <input type="number" name="value" value="{{ old('value', $contract->value) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Status</label>
                <select name="status" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
                    <option value="draft" {{ $contract->status == 'draft' ? 'selected' : '' }}>Draft</option>
                    <option value="signed" {{ $contract->status == 'signed' ? 'selected' : '' }}>Signed</option>
                    <option value="execution" {{ $contract->status == 'execution' ? 'selected' : '' }}>Execution</option>
                    <option value="completed" {{ $contract->status == 'completed' ? 'selected' : '' }}>Completed</option>
                    <option value="cancelled" {{ $contract->status == 'cancelled' ? 'selected' : '' }}>Cancelled</option>
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Tanggal Mulai *</label>
                <input type="date" name="start_date" value="{{ old('start_date', $contract->start_date->format('Y-m-d')) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Tanggal Selesai *</label>
                <input type="date" name="end_date" value="{{ old('end_date', $contract->end_date->format('Y-m-d')) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>
            </div>
            <div class="md:col-span-2">
                <label class="block text-sm font-medium text-gray-700 mb-1">Catatan</label>
                <textarea name="notes" rows="3" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">{{ old('notes') }}</textarea>
            </div>
        </div>

        <div class="mt-6 flex items-center gap-3">
            <button type="submit" class="bg-[#0b2b4a] text-white px-6 py-2 rounded-lg hover:bg-[#1a4a6e] transition">
                <i class="fas fa-save mr-2"></i> Update
            </button>
            <a href="{{ route('ppk.contracts.index') }}" class="text-gray-600 hover:text-gray-800 transition">
                Batal
            </a>
        </div>
    </form>
</div>
@endsection