@extends('layouts.app')

@section('title', 'Kelola Kontrak - 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-file-signature text-[#c9a84c]"></i>
                Kelola Kontrak
            </h1>
            <p class="text-gray-500 text-sm mt-1">Kelola semua kontrak di sistem</p>
        </div>
        <a href="{{ route('super_admin.dashboard') }}" class="text-gray-600 hover:text-gray-800 transition">
            <i class="fas fa-arrow-left mr-1"></i> Kembali
        </a>
    </div>
</div>

@php
    $contracts = \App\Models\Contract::with(['jobPackage', 'contractor'])
        ->orderBy('created_at', 'desc')
        ->paginate(10);
@endphp

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden">
    <div class="overflow-x-auto">
        <table class="w-full">
            <thead class="bg-gray-50">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">No. Kontrak</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Paket</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Kontraktor</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Nilai</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Status</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">PPK</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase">Aksi</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-200">
                @forelse($contracts as $contract)
                    <tr class="hover:bg-gray-50 transition">
                        <td class="px-6 py-4 text-sm font-medium text-gray-900">{{ $contract->contract_number }}</td>
                        <td class="px-6 py-4 text-sm text-gray-900">{{ $contract->jobPackage->name ?? '-' }}</td>
                        <td class="px-6 py-4 text-sm text-gray-900">{{ $contract->contractor->business_name ?? '-' }}</td>
                        <td class="px-6 py-4 text-sm text-gray-900">Rp {{ number_format($contract->value, 0, ',', '.') }}</td>
                        <td class="px-6 py-4">
                            <span class="px-2 py-1 text-xs rounded-full 
                                {{ $contract->status === 'completed' ? 'bg-green-100 text-green-700' : 
                                   ($contract->status === 'signed' ? 'bg-blue-100 text-blue-700' : 
                                   ($contract->status === 'execution' ? 'bg-purple-100 text-purple-700' : 
                                   ($contract->status === 'draft' ? 'bg-gray-100 text-gray-700' : 
                                   'bg-red-100 text-red-700'))) }}">
                                {{ ucfirst($contract->status) }}
                            </span>
                        </td>
                        <td class="px-6 py-4 text-sm text-gray-900">{{ $contract->jobPackage->ppk->name ?? '-' }}</td>
                        <td class="px-6 py-4">
                            <a href="{{ route('super_admin.contracts.show', $contract) }}" class="text-blue-600 hover:text-blue-800">
                                <i class="fas fa-eye"></i>
                            </a>
                        </td>
                    </tr>
                @empty
                    <tr>
                        <td colspan="7" class="px-6 py-8 text-center text-gray-500">
                            <i class="fas fa-file-signature text-4xl block mb-2 text-gray-300"></i>
                            Belum ada kontrak
                        </td>
                    </tr>
                @endforelse
            </tbody>
        </table>
    </div>
    <div class="px-6 py-4 border-t border-gray-200">
        {{ $contracts->links() }}
    </div>
</div>
@endsection