<?php

use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\MatchController;
use App\Http\Controllers\RevenueController;
use App\Http\Controllers\TicketCenterController;
use App\Http\Controllers\AuditLogController;
use App\Http\Controllers\TicketController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\FanController;

// Route::get('/', function () {
//     return view('welcome');
// });

Route::get('/', [HomeController::class, 'index'])->name('home');

Route::get('/dashboard', function () {
    return view('dashboard');
})->middleware(['auth', 'verified'])->name('dashboard');

// Ticket routes
Route::get('/tickets/create', [TicketController::class, 'create'])->name('tickets.create');
Route::post('/tickets', [TicketController::class, 'store'])->name('tickets.store');
Route::get('/tickets/verify/{ticketNumber}', [TicketController::class, 'verify'])->name('tickets.verify');

// Fan routes
Route::get('fans/create', [FanController::class, 'create'])->name('fans.create');
Route::post('fans', [FanController::class, 'store'])->name('fans.store');
Route::get('fans/profile', [FanController::class, 'profile'])->name('fans.profile');

// Route::middleware('auth')->group(function () {

// });
Route::middleware(['auth', 'admin'])->prefix('admin')->group(function () {
    Route::get('dashboard', [AdminController::class, 'dashboard'])->name('admin.dashboard');

    // Match CRUD routes - Use resource with proper naming
    Route::resource('matches', MatchController::class)->names([
        'index' => 'admin.matches.index',
        'create' => 'admin.matches.create',
        'store' => 'admin.matches.store',
        'show' => 'admin.matches.show',
        'edit' => 'admin.matches.edit',
        'update' => 'admin.matches.update',
        'destroy' => 'admin.matches.destroy',
    ]);

    // Revenue analytics routes
    Route::get('revenue', [RevenueController::class, 'index'])->name('admin.revenue.index');
    Route::get('revenue/analytics', [RevenueController::class, 'analytics'])->name('admin.revenue.analytics');

    // Ticket Center CRUD routes - Use resource with proper naming
    Route::resource('ticket-centers', TicketCenterController::class)->names([
        'index' => 'admin.ticket-centers.index',
        'create' => 'admin.ticket-centers.create',
        'store' => 'admin.ticket-centers.store',
        'show' => 'admin.ticket-centers.show',
        'edit' => 'admin.ticket-centers.edit',
        'update' => 'admin.ticket-centers.update',
        'destroy' => 'admin.ticket-centers.destroy',
    ]);

    Route::get('ticket-centers/ajax/available-staff', [TicketCenterController::class, 'getAvailableStaff'])->name('admin.ticket-centers.available-staff');

    // Audit Log routes (keep as is)
    Route::get('audit-logs', [AuditLogController::class, 'index'])->name('admin.audit-logs.index');
    Route::get('audit-logs/{auditLog}', [AuditLogController::class, 'show'])->name('admin.audit-logs.show');
    Route::get('audit-logs/user/{user}', [AuditLogController::class, 'userLogs'])->name('admin.audit-logs.user-logs');
    Route::get('audit-logs/action/{action}', [AuditLogController::class, 'actionLogs'])->name('admin.audit-logs.action-logs');
    Route::get('audit-logs/export/csv', [AuditLogController::class, 'export'])->name('admin.audit-logs.export');
    Route::get('audit-logs/statistics/overview', [AuditLogController::class, 'statistics'])->name('admin.audit-logs.statistics');

    Route::get('transactions', [\App\Http\Controllers\TransactionController::class, 'index'])->name('admin.transactions.index');
    Route::get('transactions/export/csv', [\App\Http\Controllers\TransactionController::class, 'exportCsv'])->name('admin.transactions.exportCsv');
    Route::get('transactions/export/pdf', [\App\Http\Controllers\TransactionController::class, 'exportPdf'])->name('admin.transactions.exportPdf');

    Route::get('profile', [ProfileController::class, 'edit'])->name('profile.edit');
    Route::patch('profile', [ProfileController::class, 'update'])->name('profile.update');
    Route::delete('profile', [ProfileController::class, 'destroy'])->name('profile.destroy');
});

require __DIR__ . '/auth.php';
