<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LandingController;
use App\Http\Controllers\RobotsTxtController;
use App\Http\Controllers\SitemapController;
use App\Http\Controllers\Auth\PasswordResetController;
use App\Http\Controllers\User\AuthController;

/*
|--------------------------------------------------------------------------
| Public SEO Landing Routes
|--------------------------------------------------------------------------
|
| Public landing pages for SEO and indexing.
| Only these public pages should be indexable.
|
*/
Route::get('/', [LandingController::class, 'home'])->name('landing.home');
Route::get('/about', [LandingController::class, 'about'])->name('landing.about');
Route::get('/contact', [LandingController::class, 'contact'])->name('landing.contact');
Route::get('/privacy-policy', [LandingController::class, 'privacyPolicy'])->name('landing.privacy');

/*
|--------------------------------------------------------------------------
| SEO Utility Routes
|--------------------------------------------------------------------------
|
| Dynamic sitemap.xml and robots.txt
|
*/
Route::get('/sitemap.xml', [SitemapController::class, 'index'])->name('sitemap.xml');
Route::get('/sitemap-main.xml', [SitemapController::class, 'main'])->name('sitemap.main');
Route::get('/sitemap-plans.xml', [SitemapController::class, 'plans'])->name('sitemap.plans');
Route::get('/sitemap-blog.xml', [SitemapController::class, 'blog'])->name('sitemap.blog');

// Optional robots.txt dynamic
Route::get('/robots.txt', [SitemapController::class, 'robots'])->name('robots.txt');

/*
|--------------------------------------------------------------------------
| Locale Switch Route
|--------------------------------------------------------------------------
|
| বাংলা / English language switch for whole website
|
*/
Route::get('/locale/{locale}', function ($locale) {
    $supportedLocales = array_keys(config('app.supported_locales', [
        'bn' => 'বাংলা',
        'en' => 'English',
    ]));

    if (in_array($locale, $supportedLocales, true)) {
        session(['locale' => $locale]);
    }

    return redirect()->back();
})->name('locale.switch');

/*
|--------------------------------------------------------------------------
| Guest Authentication Routes (User)
|--------------------------------------------------------------------------
*/
Route::middleware('guest:web')->group(function () {
    Route::get('/register', [AuthController::class, 'showRegistrationForm'])->name('register');
    Route::post('/register', [AuthController::class, 'register'])->name('user.register.submit');

    Route::get('/login', [AuthController::class, 'showLoginForm'])->name('login');
    Route::post('/login', [AuthController::class, 'login'])->name('user.login.submit');

    /*
    |--------------------------------------------------------------------------
    | Password Reset Routes
    |--------------------------------------------------------------------------
    */
    Route::get('/forgot-password', [PasswordResetController::class, 'showLinkRequestForm'])->name('password.request');
    Route::post('/forgot-password', [PasswordResetController::class, 'sendResetLinkEmail'])->name('password.email');
    Route::get('/reset-password/{token}', [PasswordResetController::class, 'showResetForm'])->name('password.reset');
    Route::post('/reset-password', [PasswordResetController::class, 'reset'])->name('password.update');
});

/*
|--------------------------------------------------------------------------
| Authenticated Routes (User)
|--------------------------------------------------------------------------
*/
Route::middleware('auth:web')->group(function () {
    Route::post('/logout', [AuthController::class, 'logout'])->name('logout');
});

/*
|--------------------------------------------------------------------------
| Admin & User Application Routes
|--------------------------------------------------------------------------
*/
require __DIR__ . '/admin.php';
require __DIR__ . '/user.php';