<?php

use App\Http\Controllers\BlogController;
use App\Http\Controllers\CheckoutController;
use App\Http\Controllers\HomeController;
use App\Http\Controllers\NewsletterController;
use App\Http\Controllers\PageController;
use App\Http\Controllers\SitemapController;
use App\Http\Controllers\StoreController;
use Illuminate\Support\Facades\Route;

Route::get('/', HomeController::class)->name('home');

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

Route::get('/store', [StoreController::class, 'index'])->name('store.index');
Route::get('/store/{product:slug}', [StoreController::class, 'show'])->name('store.show');
Route::get('/plans', [StoreController::class, 'plans'])->name('plans');

Route::post('/checkout/{product:slug}', [CheckoutController::class, 'product'])->name('checkout.product');
Route::get('/checkout/success', [CheckoutController::class, 'success'])->name('checkout.success');

Route::post('/subscribe', [NewsletterController::class, 'subscribe'])
    ->middleware('throttle:10,1')->name('newsletter.subscribe');
Route::get('/newsletter/confirm/{subscriber}', [NewsletterController::class, 'confirm'])
    ->middleware('signed')->name('newsletter.confirm');
Route::get('/newsletter/unsubscribe/{subscriber}', [NewsletterController::class, 'unsubscribe'])
    ->middleware('signed')->name('newsletter.unsubscribe');

Route::get('/sitemap.xml', SitemapController::class)->name('sitemap');

// CMS pages — kept last so it can never shadow real routes.
Route::get('/{page:slug}', PageController::class)
    ->where('page', '^(?!admin|livewire|storage|api)[a-z0-9\-]+$')
    ->name('page.show');
