@extends('layouts.app')

@section('title', 'Agent Portal - Dashboard')

@section('content')
<div class="bg-black text-white py-10 border-b border-neutral-800">
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 flex flex-col md:flex-row md:items-center justify-between gap-4">
        <div>
            <span class="text-[10px] font-bold uppercase tracking-[0.3em] text-brand-gold">Agent Portal</span>
            <h1 class="font-serif-heading font-extrabold text-3xl text-white">Welcome, {{ $agent->name ?? Auth::user()->name }}</h1>
            <p class="text-gray-400 text-xs mt-1">{{ $agent->title ?? 'Real Estate Advisor' }}</p>
        </div>
        <div class="flex space-x-3">
            <a href="{{ route('agent.properties.create') }}" class="px-5 py-2.5 bg-brand-blue text-white text-xs font-bold uppercase tracking-widest hover:bg-brand-darkblue shadow">
                + Publish New Listing
            </a>
            <a href="{{ route('agent.profile') }}" class="px-4 py-2.5 border border-neutral-700 text-gray-300 text-xs font-bold uppercase tracking-widest hover:bg-neutral-800">
                Edit Profile
            </a>
        </div>
    </div>
</div>

<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-12 space-y-10">
    
    <!-- Listing Table -->
    <div class="border border-gray-200 bg-white space-y-4">
        <div class="p-6 border-b border-gray-100 flex items-center justify-between">
            <h3 class="font-serif-heading font-bold text-xl text-black">My Managed Properties</h3>
            <a href="{{ route('agent.properties.create') }}" class="text-xs text-brand-blue font-bold uppercase tracking-widest">+ Add Property</a>
        </div>

        <div class="overflow-x-auto">
            <table class="w-full text-left text-sm text-gray-700">
                <thead class="bg-gray-50 text-[10px] font-bold text-gray-500 uppercase border-b border-gray-100">
                    <tr>
                        <th class="px-6 py-3">Property</th>
                        <th class="px-6 py-3">Category</th>
                        <th class="px-6 py-3">Status</th>
                        <th class="px-6 py-3">Price</th>
                        <th class="px-6 py-3">City</th>
                    </tr>
                </thead>
                <tbody class="divide-y divide-gray-100">
                    @forelse($properties as $property)
                        <tr class="hover:bg-gray-50">
                            <td class="px-6 py-4 font-bold text-black flex items-center space-x-3">
                                <img src="{{ $property->main_image }}" class="w-10 h-10 object-cover border border-gray-200">
                                <span>{{ $property->title }}</span>
                            </td>
                            <td class="px-6 py-4 text-xs font-semibold">{{ $property->property_type }}</td>
                            <td class="px-6 py-4"><span class="px-2 py-0.5 bg-black text-white text-[10px] font-bold uppercase">For {{ $property->status }}</span></td>
                            <td class="px-6 py-4 font-bold text-black">₦{{ number_format($property->price, 0) }}</td>
                            <td class="px-6 py-4 text-xs">{{ $property->city }}</td>
                        </tr>
                    @empty
                        <tr>
                            <td colspan="5" class="px-6 py-8 text-center text-xs text-gray-400">You have not published any properties yet. Click "+ Publish New Listing" to add one!</td>
                        </tr>
                    @endforelse
                </tbody>
            </table>
        </div>
        <div class="p-4 border-t border-gray-100">
            {{ $properties->links() }}
        </div>
    </div>

</div>
@endsection
