@extends('layouts.app')

@section('title', 'Profil Kontraktor - 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-user-circle text-[#c9a84c]"></i>
                Profil Kontraktor
            </h1>
            <p class="text-gray-500 text-sm mt-1">Kelola profil kontraktor Anda</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>

@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

@php
    $user = Auth::user();
    $contractor = \App\Models\Contractor::where('user_id', $user->id)->first();
@endphp

@if($contractor)
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
        <!-- Profile Card -->
        <div class="md:col-span-2 bg-white rounded-2xl shadow-sm border border-gray-100 p-6">
            <div class="flex items-start gap-6">
                <div class="w-20 h-20 rounded-full bg-[#0b2b4a] flex items-center justify-center text-white text-3xl">
                    {{ substr($contractor->business_name, 0, 1) }}
                </div>
                <div class="flex-1">
                    <h2 class="text-2xl font-bold text-gray-800">{{ $contractor->business_name }}</h2>
                    <p class="text-gray-500">{{ $contractor->short_name ?? '-' }}</p>
                    <div class="flex flex-wrap items-center gap-3 mt-2">
                        <span class="text-xs px-2 py-1 rounded-full 
                            {{ $contractor->oap_status === 'verified' ? 'bg-green-100 text-green-700' : 
                               ($contractor->oap_status === 'pending' ? 'bg-yellow-100 text-yellow-700' : 
                               'bg-red-100 text-red-700') }}">
                            OAP: {{ ucfirst($contractor->oap_status) }}
                        </span>
                        <span class="text-xs px-2 py-1 rounded-full {{ $contractor->is_active ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' }}">
                            {{ $contractor->is_active ? 'Aktif' : 'Nonaktif' }}
                        </span>
                        <span class="text-xs px-2 py-1 rounded-full bg-gray-100 text-gray-700">
                            SKP: {{ $contractor->skp_remaining ?? 0 }}
                        </span>
                        <span class="text-xs px-2 py-1 rounded-full bg-yellow-100 text-yellow-700">
                            Rating: {{ $contractor->rating_avg ?? 0 }}
                        </span>
                    </div>
                </div>
            </div>

            <div class="grid grid-cols-2 gap-6 mt-6 pt-6 border-t border-gray-200">
                <div>
                    <label class="text-xs text-gray-500">Tipe Usaha</label>
                    <p class="text-sm font-medium text-gray-800">{{ $contractor->business_type }}</p>
                </div>
                <div>
                    <label class="text-xs text-gray-500">Email</label>
                    <p class="text-sm font-medium text-gray-800">{{ $contractor->email ?? '-' }}</p>
                </div>
                <div>
                    <label class="text-xs text-gray-500">Telepon</label>
                    <p class="text-sm font-medium text-gray-800">{{ $contractor->phone ?? '-' }}</p>
                </div>
                <div>
                    <label class="text-xs text-gray-500">Website</label>
                    <p class="text-sm font-medium text-gray-800">{{ $contractor->website ?? '-' }}</p>
                </div>
                <div class="col-span-2">
                    <label class="text-xs text-gray-500">Alamat</label>
                    <p class="text-sm text-gray-800">{{ $contractor->address }}</p>
                </div>
                <div class="col-span-2">
                    <label class="text-xs text-gray-500">Lokasi</label>
                    <p class="text-sm text-gray-800">
                        {{ $contractor->village }}, {{ $contractor->district }}, {{ $contractor->regency }}, {{ $contractor->province }}
                    </p>
                </div>
            </div>
        </div>

        <!-- Info Card -->
        <div class="bg-white rounded-2xl shadow-sm border border-gray-100 p-6">
            <h3 class="text-sm font-semibold text-gray-700 mb-4">Aksi Cepat</h3>
            <div class="space-y-3">
                <a href="#" class="block text-center bg-[#0b2b4a] text-white px-4 py-2 rounded-lg hover:bg-[#1a4a6e] transition">
                    <i class="fas fa-edit mr-2"></i> Edit Profil
                </a>
                <a href="#" class="block text-center bg-[#c9a84c] text-white px-4 py-2 rounded-lg hover:bg-[#b8962a] transition">
                    <i class="fas fa-upload mr-2"></i> Upload Dokumen
                </a>
                <a href="{{ route('super_admin.my-contracts') }}" class="block text-center bg-gray-600 text-white px-4 py-2 rounded-lg hover:bg-gray-700 transition">
                    <i class="fas fa-file-signature mr-2"></i> Lihat Kontrak
                </a>
            </div>
        </div>
    </div>
@else
    <div class="bg-white p-8 rounded-2xl shadow-sm text-center">
        <i class="fas fa-user-circle text-6xl text-gray-300 mb-4"></i>
        <h3 class="text-xl font-semibold text-gray-700">Profil Belum Lengkap</h3>
        <p class="text-gray-500 mt-2">Silakan lengkapi profil kontraktor Anda</p>
        <a href="#" class="mt-4 inline-block bg-[#c9a84c] text-white px-6 py-2 rounded-lg hover:bg-[#b8962a] transition">
            <i class="fas fa-edit mr-2"></i> Lengkapi Profil
        </a>
    </div>
@endif
@endsection