<x-app-layout>
    <x-slot name="title">Reports</x-slot>
    <x-slot name="header">
        <div class="flex justify-between items-center">
            <h2 class="font-semibold text-xl text-gray-800 leading-tight">
                {{ __('Reports Dashboard') }}
            </h2>
            <a href="{{ route('reports.create') }}" class="px-4 py-2 bg-primary-600 text-white rounded-md hover:bg-primary-700 text-sm font-medium shadow-sm transition-colors">
                <svg class="w-4 h-4 inline-block mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16m8-8H4"></path></svg>
                Build Custom Report
            </a>
        </div>
    </x-slot>

    <div class="py-12">
        <div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-8">
            
            <!-- Standard Reports Section -->
            <div>
                <h3 class="text-lg font-medium text-gray-900 mb-4">Standard Reports</h3>
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
                    <!-- Sales Performance -->
                    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 flex flex-col h-full hover:shadow-md transition-shadow">
                        <div class="p-3 bg-blue-50 rounded-lg w-12 h-12 flex items-center justify-center mb-4 text-blue-600">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path></svg>
                        </div>
                        <h4 class="text-md font-semibold text-gray-900 mb-2">Sales Performance</h4>
                        <p class="text-sm text-gray-500 mb-4 flex-grow">Track lead conversions, agents performance, and overall sales trends.</p>
                        <a href="{{ route('reports.standard', ['preset' => 'sales']) }}" class="text-sm text-primary-600 font-medium hover:text-primary-800">Generate &rarr;</a>
                    </div>
                    
                    <!-- Inventory Status -->
                    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 flex flex-col h-full hover:shadow-md transition-shadow">
                        <div class="p-3 bg-green-50 rounded-lg w-12 h-12 flex items-center justify-center mb-4 text-green-600">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path></svg>
                        </div>
                        <h4 class="text-md font-semibold text-gray-900 mb-2">Inventory Status</h4>
                        <p class="text-sm text-gray-500 mb-4 flex-grow">View total properties, availability, sold units, and blocks.</p>
                        <a href="{{ route('reports.standard', ['preset' => 'inventory']) }}" class="text-sm text-primary-600 font-medium hover:text-primary-800">Generate &rarr;</a>
                    </div>
                    
                    <!-- Financial Collection -->
                    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 flex flex-col h-full hover:shadow-md transition-shadow">
                        <div class="p-3 bg-purple-50 rounded-lg w-12 h-12 flex items-center justify-center mb-4 text-purple-600">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path></svg>
                        </div>
                        <h4 class="text-md font-semibold text-gray-900 mb-2">Financial Collection</h4>
                        <p class="text-sm text-gray-500 mb-4 flex-grow">Analyze expected vs collected payments and overdue invoices.</p>
                        <a href="{{ route('reports.standard', ['preset' => 'financial']) }}" class="text-sm text-primary-600 font-medium hover:text-primary-800">Generate &rarr;</a>
                    </div>
                    
                    <!-- Agent Activity -->
                    <div class="bg-white rounded-xl shadow-sm border border-gray-100 p-6 flex flex-col h-full hover:shadow-md transition-shadow">
                        <div class="p-3 bg-orange-50 rounded-lg w-12 h-12 flex items-center justify-center mb-4 text-orange-600">
                            <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path></svg>
                        </div>
                        <h4 class="text-md font-semibold text-gray-900 mb-2">Agent Activity</h4>
                        <p class="text-sm text-gray-500 mb-4 flex-grow">Monitor daily tasks, calls, site visits, and team follow-ups.</p>
                        <a href="{{ route('reports.standard', ['preset' => 'agents']) }}" class="text-sm text-primary-600 font-medium hover:text-primary-800">Generate &rarr;</a>
                    </div>
                </div>
            </div>

            <!-- Saved Custom Reports -->
            <div>
                <h3 class="text-lg font-medium text-gray-900 mb-4">Saved Custom Reports</h3>
                <div class="bg-white rounded-xl shadow-sm border border-gray-100 overflow-hidden">
                    <table class="min-w-full divide-y divide-gray-200">
                        <thead class="bg-gray-50">
                            <tr>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Report Name</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Module</th>
                                <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Created</th>
                                <th class="px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider">Actions</th>
                            </tr>
                        </thead>
                        <tbody class="bg-white divide-y divide-gray-200">
                            @forelse($reports as $report)
                            <tr class="hover:bg-gray-50">
                                <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900">{{ $report->name }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 capitalize">{{ $report->module }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">{{ $report->created_at->format('M d, Y') }}</td>
                                <td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
                                    <a href="{{ route('reports.show', $report) }}" class="text-primary-600 hover:text-primary-900 mr-3">View Data</a>
                                    <form action="{{ route('reports.destroy', $report) }}" method="POST" class="inline-block" onsubmit="return confirm('Delete this report?');">
                                        @csrf
                                        @method('DELETE')
                                        <button type="submit" class="text-red-600 hover:text-red-900">Delete</button>
                                    </form>
                                </td>
                            </tr>
                            @empty
                            <tr>
                                <td colspan="4" class="px-6 py-8 whitespace-nowrap text-sm text-gray-500 text-center">
                                    <div class="flex flex-col items-center justify-center">
                                        <svg class="h-10 w-10 text-gray-300 mb-2" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 17v-2m3 2v-4m3 4v-6m2 10H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path></svg>
                                        <p>No custom reports saved yet.</p>
                                        <a href="{{ route('reports.create') }}" class="text-primary-600 hover:text-primary-800 mt-1 font-medium">Build one now</a>
                                    </div>
                                </td>
                            </tr>
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</x-app-layout>
