<?php

use App\Http\Controllers\EnquiryController;
use Illuminate\Support\Facades\Route;

Route::view('/', 'pages.home')->name('home');
Route::view('/products', 'pages.products')->name('products.index');
Route::view('/products/mutton-cloth', 'products.mutton-cloth')->name('products.mutton-cloth');
Route::view('/products/stockinette', 'products.stockinette')->name('products.stockinette');
Route::view('/about', 'pages.about')->name('about');
Route::view('/insights', 'pages.insights')->name('insights.index');
Route::get('/insights/{slug}', function (string $slug) {
    abort_unless($article = config("insights.published.$slug"), 404);

    return view('pages.article', compact('article', 'slug'));
})->name('insights.show');
Route::view('/contact', 'pages.contact')->name('contact');
Route::view('/thank-you', 'pages.thank-you')->name('enquiries.thank-you');
Route::get('/sitemap.xml', function () {
    $urls = collect(['home', 'products.index', 'products.mutton-cloth', 'products.stockinette', 'about', 'insights.index', 'contact'])
        ->map(fn (string $name) => '<url><loc>'.e(route($name)).'</loc></url>')
        ->merge(collect(config('insights.published'))->keys()->map(fn ($slug) => '<url><loc>'.e(route('insights.show', $slug)).'</loc></url>'))->implode('');

    return response('<?xml version="1.0" encoding="UTF-8"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'.$urls.'</urlset>', 200)
        ->header('Content-Type', 'application/xml');
})->name('sitemap');
Route::post('/enquiries', [EnquiryController::class, 'store'])
    ->middleware('throttle:enquiries')
    ->name('enquiries.store');
