<?php

use App\Http\Controllers\PosReceiptController;
use App\Http\Controllers\ProfileController;
use Illuminate\Support\Facades\Route;

Route::get('/', function () {
    try {
        $siteName    = \App\Models\Setting::get('site_name', 'VVmj8 Casino');
        $tagline     = \App\Models\Setting::get('site_tagline', 'The Ultimate Casino & Sports Betting Platform');
        $maintenance = (bool) \App\Models\Setting::get('maintenance_mode', false);
        $maintMsg    = \App\Models\Setting::get('maintenance_message', 'We are currently undergoing scheduled maintenance.');
        $banners     = \App\Models\SliderBanner::where('is_active', true)->orderBy('sort_order')->take(5)->get();
        $jackpots    = \App\Models\Jackpot::where('is_active', true)->orderBy('id')->get();
        $promotions  = \App\Models\Promotion::where('is_active', true)->orderBy('sort_order')->take(4)->get();
        $hotGames    = \App\Models\Game::where('is_active', true)->where('is_hot', true)->take(12)->get();
    } catch (\Exception) {
        $siteName = 'VVmj8 Casino'; $tagline = 'The Ultimate Casino & Sports Betting Platform';
        $maintenance = false; $maintMsg = '';
        $banners = collect(); $jackpots = collect(); $promotions = collect(); $hotGames = collect();
    }

    return view('welcome', compact('siteName', 'tagline', 'maintenance', 'maintMsg', 'banners', 'jackpots', 'promotions', 'hotGames'));
});

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

Route::middleware('auth')->group(function () {
    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');
    Route::get('/pos/receipts/{sale}/print', [PosReceiptController::class, 'print'])->name('pos.receipts.print');
});

require __DIR__.'/auth.php';
