<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\AuthController;
use App\Http\Controllers\User\UserController;

Route::get('/', function () {
    return redirect()->route('login');
});

if (config('app.debug')) {
    Route::prefix('errors')->group(function () {
        Route::get('{code}', function ($code) {
            if (view()->exists("errors.{$code}")) {
                return view("errors.{$code}");
            }
            abort(404);
        });
    });
}

Route::get('/test-modal', function() {
    return view('admin.users.index', [
        'users' => [],
        'selectedMonth' => '2026-06',
        'topReceivedUser' => null,
        'topSentUser' => null
    ]);
});
Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
Route::post('/login', [AuthController::class, 'login']);
Route::post('/forgot-password', [AuthController::class, 'forgotPassword'])->name('forgot_password');

Route::get('/notification-showcase', function () {
    return view('notification-showcase');
})->name('notification.showcase');

Route::middleware('auth')->group(function () {
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
    
    Route::middleware('force_change_password')->group(function () {
                Route::middleware('member')->group(function () {
            Route::get('/my-page', [UserController::class, 'index'])->name('user.dashboard');
            
            // Coming soon routes replaced with real pages
            Route::get('/received-cards', [UserController::class, 'receivedCards'])->name('user.received');
            Route::get('/sent-cards', [UserController::class, 'sentCards'])->name('user.sent');
            Route::get('/ranking', [UserController::class, 'ranking'])->name('user.ranking');
            Route::view('/gallery', 'coming-soon')->name('user.gallery');
            Route::view('/stats', 'coming-soon')->name('user.stats');
            
            Route::get('/send-thankcards', [UserController::class, 'sendThankcards'])->name('user.send');
            Route::get('/send-thankcards/recipient-stats', [UserController::class, 'getRecipientStats'])->name('user.recipient_stats');
            Route::post('/send-thankcards', [UserController::class, 'storeThankcards'])->name('user.store_send');
        });
    });

    Route::get('/change-password', [UserController::class, 'changePasswordForm'])->name('user.change_password');
    Route::post('/change-password', [UserController::class, 'updatePassword'])->name('user.update_password');
    // Edit personal profile (avatar & password)
    Route::get('/profile/edit', [UserController::class, 'editProfile'])->name('user.edit');
    Route::post('/profile/edit', [UserController::class, 'updateProfile'])->name('user.update_profile');
});
