<?php

use App\Http\Controllers\EmailController;
use App\Http\Controllers\front\MemberController;
use App\Http\Controllers\front\PromoCodeController;
use App\Http\Controllers\front\RegisterController;
use App\Http\Controllers\LoginController;
use App\Http\Middleware\GuestRedirect;
use App\Http\Middleware\MemberRedirect;
use Illuminate\Support\Facades\Route;

//
//guest
Route::get('/', function () {

})->middleware(GuestRedirect::class);

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

Route::get('profile', function () {

    return view('profile.index');

});

//前台 login 畫面;
Route::get("login", [LoginController::class, 'index'])->name('login')->middleware(MemberRedirect::class);
//前台 line 登入;
Route::post('login/process', [LoginController::class, 'memberNormalLogin'])->name('member.login.post');
Route::get('login/line', [LoginController::class, 'redirectToProvider'])->name('front.login.line');
//前台 line 登入後查詢;
Route::get('login/line/callback', [LoginController::class, 'handleProviderCallback'])->name('front.login.line.callback');
Route::get('register', [RegisterController::class, 'index'])->name('member.register');
Route::post('register/create', [RegisterController::class, 'create'])->name('member.register.create');

Route::get('email/verify', [EmailController::class, 'index'])->name('email.verify');
Route::get('email/password', [RegisterController::class, 'forgotPassword'])->name('email.password');
Route::post('email/password', [RegisterController::class, 'sendForgotPassword'])->name('email.password.post');
Route::get('resetpassword', [RegisterController::class, 'resetPassword'])->name('reset.password.token');
Route::get('changepassword', [RegisterController::class, 'changePassword'])->name('change.password');
Route::put('changepassword', [RegisterController::class, 'resetPasswordProcess'])->name('change.password.put');
Route::any('checkphone', [MemberController::class, 'checkPhone'])->name('member.checkphone');
Route::get('checkemail', [MemberController::class, 'checkEmail'])->name('member.checkemail');
Route::get('google/auth', [LoginController::class, 'redirectToGoogle'])->name('google.auth');
Route::get('google/callback', [LoginController::class, 'handleGoogleCallback'])->name('google.redirect');
Route::patch('changelevel', [MemberController::class, 'changeLevel'])->name('member.changelevel');

//前台route 登入後;
Route::prefix('member')
    ->middleware(['auth:member']) // 使用自定义守卫的中间件
    ->as('member.')
    ->group(function () {
        Route::get('/', [MemberController::class, 'index'])->name('index');
        Route::post('getpromocode', [PromoCodeController::class, 'create'])->name('getpromocode');
        Route::get('logout', [LoginController::class, 'memberLogout'])->name('logout');
        Route::get('profile', [MemberController::class, 'profile'])->name('profile');
        Route::put('profile/update', [MemberController::class, 'profileUpdate'])->name('profile.update');
        Route::get('validemail', [EmailController::class, 'validemail'])->name('validemail');
        Route::post('sendemail', [EmailController::class, 'sendemail'])->name('sendemail');
        Route::get('page-profile', [MemberController::class, 'pageProfile'])->name('page-profile');
        Route::patch('morepromocode', [PromoCodeController::class, 'morePromocode'])->name('morepromocode');
    });

/*
 *********************************************************************************************
 * 後台route
 **********************************************************************************************
 */
// Web 路由...
//設定路由路徑
Route::prefix('admin')
    ->as('admin.')
    ->group(base_path('routes/admin.php'));
//
