<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */

// ----------------------------------------------------------------
// Authentication Routes (public — no auth filter)
// ----------------------------------------------------------------
$routes->get('/',                    'Auth\LoginController::index');
$routes->get('login',                'Auth\LoginController::index',       ['as' => 'login']);
$routes->post('login',               'Auth\LoginController::attempt',     ['as' => 'login.attempt']);
$routes->get('logout',               'Auth\LoginController::logout',      ['as' => 'logout']);
$routes->get('forgot-password',      'Auth\LoginController::forgot',      ['as' => 'forgot.password']);
$routes->post('forgot-password',     'Auth\LoginController::sendReset',   ['as' => 'forgot.send']);
$routes->get('reset-password/(:segment)',  'Auth\LoginController::resetForm/$1',   ['as' => 'reset.form']);
$routes->post('reset-password',      'Auth\LoginController::resetPassword', ['as' => 'reset.password']);

// ----------------------------------------------------------------
// Admin Panel Routes (protected by 'auth' filter)
// ----------------------------------------------------------------
$routes->group('admin', ['filter' => 'auth'], static function ($routes) {

    // Dashboard
    $routes->get('/',          'Admin\DashboardController::index');
    $routes->get('dashboard',  'Admin\DashboardController::index',        ['as' => 'admin.dashboard']);
    $routes->get('activity-logs', 'Admin\DashboardController::activityLogs', ['as' => 'admin.logs']);
    $routes->get('lang/(:segment)', 'Admin\DashboardController::switchLang/$1', ['as' => 'admin.lang']);

    // Users / Profiles
    $routes->get('users',                'Admin\UsersController::index',    ['as' => 'admin.users.index']);
    $routes->get('users/create',         'Admin\UsersController::create',   ['as' => 'admin.users.create']);
    $routes->post('users/store',         'Admin\UsersController::store',    ['as' => 'admin.users.store']);
    $routes->get('users/edit/(:num)',    'Admin\UsersController::edit/$1',  ['as' => 'admin.users.edit']);
    $routes->post('users/update/(:num)', 'Admin\UsersController::update/$1', ['as' => 'admin.users.update']);
    $routes->get('users/view/(:num)',    'Admin\UsersController::view/$1',  ['as' => 'admin.users.view']);
    $routes->post('users/delete/(:num)', 'Admin\UsersController::delete/$1', ['as' => 'admin.users.delete']);
    $routes->post('users/delete-media/(:num)', 'Admin\UsersController::deleteMedia/$1', ['as' => 'admin.users.deleteMedia']);
    $routes->get('users/export',         'Admin\UsersController::export',   ['as' => 'admin.users.export']);
    $routes->post('users/toggle/(:num)', 'Admin\UsersController::toggle/$1', ['as' => 'admin.users.toggle']);

    // QR Codes — manual management removed; QR codes are now generated
    // automatically when a profile photo is uploaded (admin or member).
    // $routes->get('qrcode',                   'Admin\QRCodeController::index',       ['as' => 'admin.qrcode.index']);
    // $routes->post('qrcode/generate/(:num)',  'Admin\QRCodeController::generate/$1', ['as' => 'admin.qrcode.generate']);
    // $routes->get('qrcode/download/(:num)',   'Admin\QRCodeController::download/$1', ['as' => 'admin.qrcode.download']);
    // $routes->post('qrcode/delete/(:num)',    'Admin\QRCodeController::delete/$1',   ['as' => 'admin.qrcode.delete']);

    // Settings (super admin only)
    $routes->get('settings',  'Admin\SettingsController::index',  ['as' => 'admin.settings']);
    $routes->post('settings', 'Admin\SettingsController::update', ['as' => 'admin.settings.update']);
});

// ----------------------------------------------------------------
// Secure upload file server (auth protected)
// ----------------------------------------------------------------
$routes->get('uploads/(:any)', 'Admin\UploadsController::serve/$1', ['filter' => 'auth']);

// ----------------------------------------------------------------
// Member Login (mobile OTP — no auth required)
// ----------------------------------------------------------------
$routes->get ('member/login',      'MemberAuthController::loginForm',  ['as' => 'member.login']);
$routes->post('member/send-otp',   'MemberAuthController::sendOtp',    ['as' => 'member.send_otp']);
$routes->get ('member/verify',     'MemberAuthController::otpForm',    ['as' => 'member.otp']);
$routes->post('member/verify',     'MemberAuthController::verifyOtp',  ['as' => 'member.verify_otp']);
$routes->post('member/resend-otp', 'MemberAuthController::resendOtp',  ['as' => 'member.resend_otp']);
$routes->get ('member/captcha',    'MemberAuthController::captchaImage',['as' => 'member.captcha']);
$routes->get ('member/logout',     'MemberAuthController::logout',     ['as' => 'member.logout']);

// ----------------------------------------------------------------
// Member Profile Edit  (member session required)
// ----------------------------------------------------------------
$routes->get ('member/profile/edit',              'MemberProfileController::editPage');
$routes->post('member/profile/save-theme',        'MemberProfileController::saveTheme');
$routes->post('member/profile/save-info',         'MemberProfileController::saveInfo');
$routes->post('member/profile/save-about',        'MemberProfileController::saveAbout');
$routes->post('member/profile/save-contact',      'MemberProfileController::saveContact');
$routes->post('member/profile/save-social',       'MemberProfileController::saveSocial');
$routes->post('member/profile/upload-photo',      'MemberProfileController::uploadPhoto');
$routes->post('member/profile/upload-logo',       'MemberProfileController::uploadLogo');
$routes->post('member/profile/upload-gallery',    'MemberProfileController::uploadGallery');
$routes->post('member/profile/add-video',         'MemberProfileController::addVideo');
$routes->post('member/profile/upload-document',   'MemberProfileController::uploadDocument');
$routes->post('member/profile/delete-media/(:num)',   'MemberProfileController::deleteMedia/$1');
$routes->post('member/profile/add-section',                    'MemberProfileController::addSection');
$routes->post('member/profile/add-section-item/(:num)',        'MemberProfileController::addSectionItem/$1');
$routes->post('member/profile/delete-section-item/(:num)',     'MemberProfileController::deleteSectionItem/$1');
$routes->post('member/profile/update-section/(:num)',          'MemberProfileController::updateSection/$1');
$routes->post('member/profile/delete-section/(:num)',          'MemberProfileController::deleteSection/$1');

// ----------------------------------------------------------------
// Public Profile Pages  (no auth required)
// ----------------------------------------------------------------
$routes->get('profile/(:segment)/vcard', 'ProfileController::vcard/$1',  ['as' => 'profile.vcard']);
$routes->get('profile/(:segment)',       'ProfileController::show/$1',   ['as' => 'profile.show']);

// ----------------------------------------------------------------
// 404 override
// ----------------------------------------------------------------
$routes->set404Override();
