@extends('layouts.admin')

@section('title', 'Reports - Admin')
@section('page-title', 'Reports & Analytics')
@section('page-description', 'Generate and download platform reports')

@section('content')
<div class="space-y-6">
    
    <!-- Report Types -->
    <div class="glass-card rounded-2xl p-6 border border-white/10" data-aos="fade-up">
        <h3 class="text-xl font-bold text-white mb-4">📊 Generate Reports</h3>
        <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
            <div class="p-4 bg-white/5 rounded-xl hover:bg-white/10 transition cursor-pointer group" onclick="selectReport('weddings')">
                <i class="fas fa-ring text-3xl text-purple-400 mb-3 block"></i>
                <h4 class="text-white font-semibold">Weddings Report</h4>
                <p class="text-gray-400 text-sm mt-1">All wedding details and statistics</p>
                <span class="text-purple-400 text-xs mt-2 inline-block opacity-0 group-hover:opacity-100 transition">Generate →</span>
            </div>
            <div class="p-4 bg-white/5 rounded-xl hover:bg-white/10 transition cursor-pointer group" onclick="selectReport('users')">
                <i class="fas fa-users text-3xl text-blue-400 mb-3 block"></i>
                <h4 class="text-white font-semibold">Users Report</h4>
                <p class="text-gray-400 text-sm mt-1">User registrations and activity</p>
                <span class="text-purple-400 text-xs mt-2 inline-block opacity-0 group-hover:opacity-100 transition">Generate →</span>
            </div>
            <div class="p-4 bg-white/5 rounded-xl hover:bg-white/10 transition cursor-pointer group" onclick="selectReport('subscriptions')">
                <i class="fas fa-credit-card text-3xl text-green-400 mb-3 block"></i>
                <h4 class="text-white font-semibold">Subscriptions Report</h4>
                <p class="text-gray-400 text-sm mt-1">Revenue and plan distribution</p>
                <span class="text-purple-400 text-xs mt-2 inline-block opacity-0 group-hover:opacity-100 transition">Generate →</span>
            </div>
            <div class="p-4 bg-white/5 rounded-xl hover:bg-white/10 transition cursor-pointer group" onclick="selectReport('bookings')">
                <i class="fas fa-calendar-check text-3xl text-orange-400 mb-3 block"></i>
                <h4 class="text-white font-semibold">Bookings Report</h4>
                <p class="text-gray-400 text-sm mt-1">Guest bookings overview</p>
                <span class="text-purple-400 text-xs mt-2 inline-block opacity-0 group-hover:opacity-100 transition">Generate →</span>
            </div>
        </div>
    </div>
    
    <!-- Report Configuration -->
    <div class="glass-card rounded-2xl p-6 border border-white/10" data-aos="fade-up">
        <h3 class="text-xl font-bold text-white mb-4">⚙️ Report Configuration</h3>
        <div class="grid md:grid-cols-3 gap-6">
            <div>
                <label class="block text-white mb-2">Date Range</label>
                <select class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white focus:outline-none focus:border-purple-500">
                    <option>Last 7 days</option>
                    <option>Last 30 days</option>
                    <option>Last 3 months</option>
                    <option>Last 6 months</option>
                    <option>This year</option>
                    <option>Custom range</option>
                </select>
            </div>
            <div>
                <label class="block text-white mb-2">Format</label>
                <select class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white focus:outline-none focus:border-purple-500">
                    <option>PDF Document</option>
                    <option>Excel Spreadsheet</option>
                    <option>CSV File</option>
                    <option>JSON Data</option>
                </select>
            </div>
            <div>
                <label class="block text-white mb-2">Include Charts</label>
                <select class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white focus:outline-none focus:border-purple-500">
                    <option>Yes, include charts</option>
                    <option>No, data only</option>
                </select>
            </div>
        </div>
        
        <div id="customDateRange" class="grid md:grid-cols-2 gap-4 mt-4" style="display: none;">
            <div>
                <label class="block text-white mb-2">From Date</label>
                <input type="date" class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white">
            </div>
            <div>
                <label class="block text-white mb-2">To Date</label>
                <input type="date" class="w-full px-4 py-2 bg-white/10 border border-white/20 rounded-lg text-white">
            </div>
        </div>
        
        <div class="mt-6 flex gap-4">
            <button id="generateReportBtn" class="px-6 py-2 bg-gradient-to-r from-purple-600 to-pink-600 rounded-lg text-white font-semibold hover:shadow-2xl transition hover:scale-105">
                <i class="fas fa-chart-line mr-2"></i>Generate Report
            </button>
            <button class="px-6 py-2 bg-white/10 rounded-lg text-gray-300 hover:bg-white/20 transition">
                <i class="fas fa-download mr-2"></i>Download Sample
            </button>
        </div>
    </div>
    
    <!-- Recent Reports -->
    <div class="glass-card rounded-2xl p-6 border border-white/10" data-aos="fade-up">
        <div class="flex justify-between items-center mb-4">
            <h3 class="text-xl font-bold text-white">📁 Recent Reports</h3>
            <button class="text-purple-400 text-sm hover:text-purple-300">View All →</button>
        </div>
        <div class="overflow-x-auto">
            <table class="w-full">
                <thead>
                    <tr class="border-b border-white/10">
                        <th class="text-left py-3 text-gray-400">Report Name</th>
                        <th class="text-left py-3 text-gray-400">Type</th>
                        <th class="text-left py-3 text-gray-400">Date Range</th>
                        <th class="text-left py-3 text-gray-400">Generated</th>
                        <th class="text-left py-3 text-gray-400">Size</th>
                        <th class="text-left py-3 text-gray-400">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    <tr class="hover:bg-white/5 transition">
                        <td class="py-3 text-white">Weddings_Report_Mar2024</td>
                        <td class="py-3"><span class="badge badge-info">PDF</span></td>
                        <td class="py-3 text-gray-300">Mar 1-31, 2024</td>
                        <td class="py-3 text-gray-300">Mar 25, 2024</td>
                        <td class="py-3 text-gray-300">2.4 MB</td>
                        <td class="py-3">
                            <div class="flex gap-2">
                                <button class="text-purple-400 hover:text-purple-300"><i class="fas fa-download"></i></button>
                                <button class="text-blue-400 hover:text-blue-300"><i class="fas fa-eye"></i></button>
                                <button class="text-red-400 hover:text-red-300"><i class="fas fa-trash"></i></button>
                            </div>
                        </td>
                    </tr>
                    <tr class="hover:bg-white/5 transition">
                        <td class="py-3 text-white">Users_Activity_Feb2024</td>
                        <td class="py-3"><span class="badge badge-success">Excel</span></td>
                        <td class="py-3 text-gray-300">Feb 1-29, 2024</td>
                        <td class="py-3 text-gray-300">Mar 1, 2024</td>
                        <td class="py-3 text-gray-300">1.8 MB</td>
                        <td class="py-3">
                            <div class="flex gap-2">
                                <button class="text-purple-400 hover:text-purple-300"><i class="fas fa-download"></i></button>
                                <button class="text-blue-400 hover:text-blue-300"><i class="fas fa-eye"></i></button>
                                <button class="text-red-400 hover:text-red-300"><i class="fas fa-trash"></i></button>
                            </div>
                        </td>
                    </tr>
                    <tr class="hover:bg-white/5 transition">
                        <td class="py-3 text-white">Subscriptions_Q1_2024</td>
                        <td class="py-3"><span class="badge badge-warning">CSV</span></td>
                        <td class="py-3 text-gray-300">Jan 1-Mar 31, 2024</td>
                        <td class="py-3 text-gray-300">Mar 20, 2024</td>
                        <td class="py-3 text-gray-300">3.2 MB</td>
                        <td class="py-3">
                            <div class="flex gap-2">
                                <button class="text-purple-400 hover:text-purple-300"><i class="fas fa-download"></i></button>
                                <button class="text-blue-400 hover:text-blue-300"><i class="fas fa-eye"></i></button>
                                <button class="text-red-400 hover:text-red-300"><i class="fas fa-trash"></i></button>
                            </div>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    
    <!-- Scheduled Reports -->
    <div class="glass-card rounded-2xl p-6 border border-white/10" data-aos="fade-up">
        <div class="flex justify-between items-center mb-4">
            <h3 class="text-xl font-bold text-white">⏰ Scheduled Reports</h3>
            <button class="px-3 py-1 bg-purple-600 rounded-lg text-white text-sm hover:bg-purple-700 transition">
                <i class="fas fa-plus mr-1"></i>Add Schedule
            </button>
        </div>
        <div class="grid md:grid-cols-2 gap-4">
            <div class="p-4 bg-white/5 rounded-lg">
                <div class="flex justify-between items-start mb-2">
                    <div>
                        <h4 class="text-white font-semibold">Weekly Weddings Report</h4>
                        <p class="text-gray-400 text-sm">Every Monday at 9:00 AM</p>
                    </div>
                    <span class="badge badge-success">Active</span>
                </div>
                <p class="text-gray-300 text-sm">PDF format • Emailed to admin@wedbooker.com</p>
                <div class="flex gap-2 mt-3">
                    <button class="text-purple-400 text-sm hover:text-purple-300"><i class="fas fa-edit"></i> Edit</button>
                    <button class="text-red-400 text-sm hover:text-red-300"><i class="fas fa-stop"></i> Disable</button>
                </div>
            </div>
            <div class="p-4 bg-white/5 rounded-lg">
                <div class="flex justify-between items-start mb-2">
                    <div>
                        <h4 class="text-white font-semibold">Monthly Revenue Report</h4>
                        <p class="text-gray-400 text-sm">1st of every month at 8:00 AM</p>
                    </div>
                    <span class="badge badge-success">Active</span>
                </div>
                <p class="text-gray-300 text-sm">Excel format • Emailed to finance@wedbooker.com</p>
                <div class="flex gap-2 mt-3">
                    <button class="text-purple-400 text-sm hover:text-purple-300"><i class="fas fa-edit"></i> Edit</button>
                    <button class="text-red-400 text-sm hover:text-red-300"><i class="fas fa-stop"></i> Disable</button>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Report Preview (Hidden by default) -->
    <div id="reportPreview" class="glass-card rounded-2xl p-6 border border-white/10" style="display: none;" data-aos="fade-up">
        <div class="flex justify-between items-center mb-4">
            <h3 class="text-xl font-bold text-white">📄 Report Preview</h3>
            <button onclick="closePreview()" class="text-gray-400 hover:text-white">
                <i class="fas fa-times text-xl"></i>
            </button>
        </div>
        <div id="previewContent" class="bg-white/5 rounded-xl p-6">
            <div class="text-center">
                <i class="fas fa-chart-line text-4xl text-purple-400 mb-3"></i>
                <p class="text-gray-300">Generating preview...</p>
            </div>
        </div>
        <div class="flex gap-3 mt-4">
            <button class="flex-1 px-4 py-2 bg-purple-600 rounded-lg text-white hover:bg-purple-700 transition">
                <i class="fas fa-download mr-2"></i>Download
            </button>
            <button onclick="closePreview()" class="px-4 py-2 bg-white/10 rounded-lg text-gray-300 hover:bg-white/20 transition">
                Close
            </button>
        </div>
    </div>
</div>

@push('scripts')
<script>
    // Date range toggle
    const dateRangeSelect = document.querySelector('select:first-of-type');
    const customDateRange = document.getElementById('customDateRange');
    
    if(dateRangeSelect) {
        dateRangeSelect.addEventListener('change', function() {
            if(this.value === 'Custom range') {
                customDateRange.style.display = 'grid';
            } else {
                customDateRange.style.display = 'none';
            }
        });
    }
    
    // Generate report function
    function selectReport(type) {
        const reportNames = {
            'weddings': 'Weddings Report',
            'users': 'Users Report',
            'subscriptions': 'Subscriptions Report',
            'bookings': 'Bookings Report'
        };
        
        // Show loading state
        const generateBtn = document.getElementById('generateReportBtn');
        const originalText = generateBtn.innerHTML;
        generateBtn.innerHTML = '<i class="fas fa-spinner fa-pulse mr-2"></i>Generating...';
        generateBtn.disabled = true;
        
        // Simulate report generation
        setTimeout(() => {
            generateBtn.innerHTML = originalText;
            generateBtn.disabled = false;
            
            // Show preview
            const preview = document.getElementById('reportPreview');
            const previewContent = document.getElementById('previewContent');
            
            previewContent.innerHTML = `
                <div class="space-y-4">
                    <div class="flex items-center gap-3 pb-4 border-b border-white/10">
                        <i class="fas fa-file-alt text-2xl text-purple-400"></i>
                        <div>
                            <h4 class="text-white font-bold">${reportNames[type]}</h4>
                            <p class="text-gray-400 text-sm">Generated on ${new Date().toLocaleString()}</p>
                        </div>
                    </div>
                    <div class="grid grid-cols-2 gap-4">
                        <div class="p-3 bg-white/5 rounded-lg">
                            <p class="text-gray-400 text-sm">Total Records</p>
                            <p class="text-white text-2xl font-bold">${Math.floor(Math.random() * 1000) + 100}</p>
                        </div>
                        <div class="p-3 bg-white/5 rounded-lg">
                            <p class="text-gray-400 text-sm">Date Range</p>
                            <p class="text-white">Mar 1-31, 2024</p>
                        </div>
                    </div>
                    <div class="p-3 bg-white/5 rounded-lg">
                        <p class="text-gray-400 text-sm">Summary</p>
                        <p class="text-gray-300 text-sm mt-1">Report generated successfully. Click download to save the file.</p>
                    </div>
                </div>
            `;
            
            preview.style.display = 'block';
            preview.scrollIntoView({ behavior: 'smooth' });
            
            // Show success notification
            showNotification('Report generated successfully!', 'success');
        }, 1500);
    }
    
    // Close preview
    function closePreview() {
        document.getElementById('reportPreview').style.display = 'none';
    }
    
    // Notification function
    function showNotification(message, type) {
        const notification = document.createElement('div');
        notification.className = `fixed top-4 right-4 px-6 py-3 rounded-lg shadow-2xl z-50 animate-float ${
            type === 'success' ? 'bg-green-500' : 'bg-red-500'
        } text-white font-semibold`;
        notification.innerHTML = `
            <div class="flex items-center gap-2">
                <i class="fas fa-${type === 'success' ? 'check-circle' : 'exclamation-circle'}"></i>
                <span>${message}</span>
            </div>
        `;
        document.body.appendChild(notification);
        setTimeout(() => notification.remove(), 3000);
    }
    
    // Generate report button click
    document.getElementById('generateReportBtn').addEventListener('click', () => {
        selectReport('weddings');
    });
</script>
@endpush
@endsection