<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

// ──────────────── FRONTEND ROUTES ────────────────
$routes->group('', ['namespace' => 'App\Modules\Frontend\Controllers'], function ($routes) {
    // Homepage
    $routes->get('/', 'HomeController::index', ['as' => 'home']);

    // Public Tours (uses ToursController → plural)
    $routes->get('tours', 'ToursController::index', ['as' => 'tours']);
    $routes->get('tours/(:any)', 'ToursController::show/$1', ['as' => 'tour.show']);

    // Booking
    $routes->get('booking', 'BookingController::create', ['as' => 'booking.create']);
    $routes->post('booking', 'BookingController::store', ['as' => 'booking.store']);
    $routes->get('booking/success', 'BookingController::success', ['as' => 'booking.success']);

    // Leads
    $routes->post('lead/packing-list', 'LeadController::capture', ['as' => 'lead.packing']);
    $routes->post('lead/newsletter', 'LeadController::capture', ['as' => 'lead.newsletter']);

    // Currency
    $routes->post('currency/set', 'CurrencyController::set', ['as' => 'currency.set']);

    // SEO
    $routes->get('sitemap.xml', 'SeoController::sitemap', ['as' => 'sitemap']);
    // Blog Routes
    $routes->get('blog', 'BlogController::index');
    $routes->get('blog/(:segment)', 'BlogController::show/$1');
});

// ──────────────── ADMIN AUTH (Public Routes) ────────────────
$routes->group('admin', ['namespace' => 'App\Modules\Admin\Controllers'], function ($routes) {
    $routes->get('login', 'AuthController::login', ['as' => 'admin.login']);
    $routes->post('login', 'AuthController::authenticate', ['as' => 'admin.authenticate']);
    $routes->get('logout', 'AuthController::logout', ['as' => 'admin.logout']);
});

// ──────────────── ADMIN PANEL (Protected Routes) ────────────────
$routes->group('admin', [
    'namespace' => 'App\Modules\Admin\Controllers',
    'filter' => 'AuthFilter'
], function ($routes) {
    // Dashboard
    $routes->get('dashboard', 'AdminController::dashboard', ['as' => 'admin.dashboard']);

    // Blog CRUD
    $routes->get('blog', 'BlogController::index', ['as' => 'admin.blog.index']);
    $routes->get('blog/create', 'BlogController::create', ['as' => 'admin.blog.create']);
    $routes->post('blog', 'BlogController::store', ['as' => 'admin.blog.store']);
    $routes->get('blog/edit/(:num)', 'BlogController::edit/$1', ['as' => 'admin.blog.edit']);
    $routes->post('blog/update/(:num)', 'BlogController::update/$1', ['as' => 'admin.blog.update']);
    $routes->get('blog/delete/(:num)', 'BlogController::delete/$1', ['as' => 'admin.blog.delete']);

    // Tour CRUD (Admin uses TourController → singular)
    $routes->get('tours', 'TourController::index', ['as' => 'admin.tours.index']);
    $routes->get('tours/create', 'TourController::create', ['as' => 'admin.tours.create']);
    $routes->post('tours', 'TourController::store', ['as' => 'admin.tours.store']);
    $routes->get('tours/edit/(:num)', 'TourController::edit/$1', ['as' => 'admin.tours.edit']);
    $routes->post('tours/update/(:num)', 'TourController::update/$1', ['as' => 'admin.tours.update']);
    $routes->get('tours/delete/(:num)', 'TourController::delete/$1', ['as' => 'admin.tours.delete']);
});