<?php

use App\Http\Controllers\HomeController;
use App\Http\Controllers\AboutController;
use App\Http\Controllers\ServiceController;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\BrandPartnerController;
use App\Http\Controllers\FaqController;
use App\Http\Controllers\BlogController;
use App\Http\Controllers\ContactController;
use App\Http\Controllers\EnquiryController;
use App\Http\Controllers\SitemapController;
use Illuminate\Support\Facades\Route;

// Root redirect
Route::get('/', function () {
    $browserLang = substr(request()->server('HTTP_ACCEPT_LANGUAGE', 'en'), 0, 2);
    $supported = ['en', 'ne', 'hi'];
    $lang = in_array($browserLang, $supported) ? $browserLang : 'en';
    return redirect("/{$lang}");
});

// Language prefixed routes
Route::prefix('{lang}')->middleware('web')->group(function () {
    Route::get('/', [HomeController::class, 'index'])->name('home');
    Route::get('/about', [AboutController::class, 'index'])->name('about');

    // Services
    Route::get('/services', [ServiceController::class, 'index'])->name('services');
    Route::get('/services/{slug}', [ServiceController::class, 'show'])->name('services.show');

    // Products
    Route::get('/products', [ProductController::class, 'index'])->name('products');
    Route::get('/products/{slug}', [ProductController::class, 'category'])->name('products.category');

    // Brand Partners
    Route::get('/brand-partners', [BrandPartnerController::class, 'index'])->name('brand-partners');

    // FAQs
    Route::get('/faqs', [FaqController::class, 'index'])->name('faqs');

    // Blog
    Route::get('/blog', [BlogController::class, 'index'])->name('blog');
    Route::get('/blog/{slug}', [BlogController::class, 'show'])->name('blog.show');

    // Contact
    Route::get('/contact', [ContactController::class, 'index'])->name('contact');

    // Why Sunauli SEO page
    Route::get('/why-sunauli', [HomeController::class, 'whySunauli'])->name('why-sunauli');

    // Enquiry form submissions
    Route::post('/enquiry', [EnquiryController::class, 'store'])
        ->name('enquiry.store')
        ->middleware('throttle:enquiry');
});

// Sitemap & Robots
Route::get('/sitemap.xml', [SitemapController::class, 'index']);
Route::get('/robots.txt', [SitemapController::class, 'robots']);
