@extends('layouts.app')

@section('title', 'Edit Kontraktor - Admin 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 Kontraktor
            </h1>
            <p class="text-gray-500 text-sm mt-1">Edit data kontraktor {{ $contractor->business_name }}</p>
        </div>
        <a href="{{ route('admin.contractors.index') }}" class="text-gray-600 hover:text-gray-800 transition">
            <i class="fas fa-arrow-left mr-1"></i> Kembali
        </a>
    </div>
</div>

@if(session('success'))
    <div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
        {{ session('success') }}
    </div>
@endif

@if(session('error'))
    <div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
        {{ session('error') }}
    </div>
@endif

@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('admin.contractors.update', $contractor) }}" 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">Nama Usaha *</label>
                <input type="text" name="business_name" value="{{ old('business_name', $contractor->business_name) }}" 
                       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">Short Name</label>
                <input type="text" name="short_name" value="{{ old('short_name', $contractor->short_name) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Tipe Usaha *</label>
                <select name="business_type" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>
                    <option value="pt" {{ old('business_type', $contractor->business_type) == 'pt' ? 'selected' : '' }}>PT</option>
                    <option value="cv" {{ old('business_type', $contractor->business_type) == 'cv' ? 'selected' : '' }}>CV</option>
                    <option value="koperasi" {{ old('business_type', $contractor->business_type) == 'koperasi' ? 'selected' : '' }}>Koperasi</option>
                    <option value="firma" {{ old('business_type', $contractor->business_type) == 'firma' ? 'selected' : '' }}>Firma</option>
                    <option value="perseorangan" {{ old('business_type', $contractor->business_type) == 'perseorangan' ? 'selected' : '' }}>Perseorangan</option>
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Status OAP *</label>
                <select name="oap_status" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>
                    <option value="pending" {{ old('oap_status', $contractor->oap_status) == 'pending' ? 'selected' : '' }}>Pending</option>
                    <option value="verified" {{ old('oap_status', $contractor->oap_status) == 'verified' ? 'selected' : '' }}>Verified</option>
                    <option value="rejected" {{ old('oap_status', $contractor->oap_status) == 'rejected' ? 'selected' : '' }}>Rejected</option>
                </select>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
                <input type="email" name="email" value="{{ old('email', $contractor->email) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Telepon</label>
                <input type="text" name="phone" value="{{ old('phone', $contractor->phone) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Website</label>
                <input type="url" name="website" value="{{ old('website', $contractor->website) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Status Aktif</label>
                <select name="is_active" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
                    <option value="1" {{ old('is_active', $contractor->is_active) == 1 ? 'selected' : '' }}>Aktif</option>
                    <option value="0" {{ old('is_active', $contractor->is_active) == 0 ? 'selected' : '' }}>Nonaktif</option>
                </select>
            </div>
            <div class="md:col-span-2">
                <label class="block text-sm font-medium text-gray-700 mb-1">Alamat *</label>
                <textarea name="address" rows="2" class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]" required>{{ old('address', $contractor->address) }}</textarea>
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Provinsi *</label>
                <input type="text" name="province" value="{{ old('province', $contractor->province) }}" 
                       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">Kabupaten *</label>
                <input type="text" name="regency" value="{{ old('regency', $contractor->regency) }}" 
                       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">Kecamatan *</label>
                <input type="text" name="district" value="{{ old('district', $contractor->district) }}" 
                       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">Desa/Kelurahan *</label>
                <input type="text" name="village" value="{{ old('village', $contractor->village) }}" 
                       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">Kode POS</label>
                <input type="text" name="postal_code" value="{{ old('postal_code', $contractor->postal_code) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </div>
            <div>
                <label class="block text-sm font-medium text-gray-700 mb-1">Tahun Berdiri</label>
                <input type="number" name="established_year" value="{{ old('established_year', $contractor->established_year) }}" 
                       class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-[#0b2b4a] focus:border-[#0b2b4a]">
            </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('admin.contractors.index') }}" class="text-gray-600 hover:text-gray-800 transition">
                Batal
            </a>
        </div>
    </form>
</div>
@endsection