<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', function () {
    return redirect()->to('login');
});

$routes->get('register', 'AuthController::register', ['as' => 'register']);
$routes->post('register', 'AuthController::register');
$routes->get('login', 'AuthController::login', ['as' => 'login']);
$routes->post('login', 'AuthController::attemptLogin');
$routes->post('logout', 'AuthController::logout', ['as' => 'logout']);


$routes->group('', ['filter' => 'auth'], function ($routes) {
    $routes->get('dashboard', 'DashboardController::index');

    $routes->get('/edit_profile', 'AuthController::edit_profile');
    $routes->post('/edit_profile_proses/(:num)', 'AuthController::edit_profile_proses/$1');

    $routes->group('customer', function ($routes) {
        $routes->get('/', 'CustomerController::index');
        $routes->get('create', 'CustomerController::create');
        $routes->post('create', 'CustomerController::create');
        $routes->post('create_ajax', 'CustomerController::create_ajax');
        $routes->get('search', 'CustomerController::search');
        $routes->get('edit/(:num)', 'CustomerController::edit/$1');
        $routes->post('edit/(:num)', 'CustomerController::edit/$1');
        $routes->post('delete/(:num)', 'CustomerController::delete/$1');
    });

    $routes->group('employee', function ($routes) {
        $routes->get('/', 'EmployeeController::index');
        $routes->get('create', 'EmployeeController::create');
        $routes->post('create', 'EmployeeController::create');
        $routes->get('edit/(:num)', 'EmployeeController::edit/$1');
        $routes->post('edit/(:num)', 'EmployeeController::edit/$1');
        $routes->post('delete/(:num)', 'EmployeeController::delete/$1');
    });

    $routes->group('type_of_fabrics', function ($routes) {
        $routes->get('/', 'TypeOfFabricController::index');
        $routes->get('create', 'TypeOfFabricController::create');
        $routes->post('create', 'TypeOfFabricController::create');
        $routes->get('edit/(:num)', 'TypeOfFabricController::edit/$1');
        $routes->post('edit/(:num)', 'TypeOfFabricController::edit/$1');
        $routes->post('delete/(:num)', 'TypeOfFabricController::delete/$1');
    });

    $routes->group('model', function ($routes) {
        $routes->get('/', 'ModelController::index');
        $routes->get('create', 'ModelController::create');
        $routes->post('create', 'ModelController::create');
        $routes->get('edit/(:num)', 'ModelController::edit/$1');
        $routes->post('edit/(:num)', 'ModelController::edit/$1');
        $routes->get('detail/(:num)', 'ModelController::detail/$1');
        $routes->post('checkout', 'ModelController::checkout');
        $routes->post('delete/(:num)', 'ModelController::delete/$1');
    });

    $routes->group('permintaan_custom', function ($routes) {
        $routes->get('/', 'PermintaanCustomController::index');
        $routes->get('history', 'PermintaanCustomController::history');
        $routes->get('create', 'PermintaanCustomController::create');
        $routes->post('create', 'PermintaanCustomController::create');
        $routes->get('edit/(:num)', 'PermintaanCustomController::edit/$1');
        $routes->post('edit/(:num)', 'PermintaanCustomController::edit/$1');
        $routes->post('delete/(:num)', 'PermintaanCustomController::delete/$1');
        $routes->get('detail/(:num)', 'PermintaanCustomController::detail/$1');
        $routes->get('ConrfirmOrder/(:num)', 'PermintaanCustomController::ConrfirmOrder/$1');
        $routes->post('confirmAsAdmin/(:num)', 'PermintaanCustomController::confirmAsAdmin/$1');
        $routes->post('rejectAsAdmin/(:num)', 'PermintaanCustomController::rejectAsAdmin/$1');
        $routes->post('confirmAsKasir/(:num)', 'PermintaanCustomController::confirmAsKasir/$1');
        $routes->post('updateStatus/(:num)', 'PermintaanCustomController::updateStatus/$1');
        $routes->post('updateOrderStatus/(:num)', 'PermintaanCustomController::updateOrderStatus/$1');
        $routes->get('kasir_edit_meter/(:num)', 'PermintaanCustomController::kasir_edit_meter/$1');
        $routes->post('kasir_edit_meter/(:num)', 'PermintaanCustomController::kasir_edit_meter/$1');
        $routes->post('showPemesanan', 'PermintaanCustomController::showPemesanan');
    });

    $routes->group('pengiriman', function ($routes) {
        $routes->get('/', 'PengirimanController::index');
        $routes->get('create', 'PengirimanController::create');
        $routes->post('store', 'PengirimanController::store');
        $routes->post('update/(:any)', 'PengirimanController::update/$1');
        $routes->get('detail/(:num)', 'PengirimanController::detail/$1');
        $routes->get('delete/(:any)', 'PengirimanController::delete/$1');
        $routes->post('delete/(:any)', 'PengirimanController::delete/$1');
    });

    $routes->group('permintaan_perubahan', function ($routes) {
        $routes->get('/', 'PermintaanPerubahanController::index');
        $routes->get('create/(:num)', 'PermintaanPerubahanController::create/$1');
        $routes->post('create', 'PermintaanPerubahanController::create');
    });

    $routes->group('riwayat_perubahan', function ($routes) {
        $routes->get('/', 'RiwayatController::index');
        $routes->get('confirm_revision/(:num)', 'RiwayatController::confirm_revision/$1');
        $routes->post('createRevision', 'RiwayatController::createRevision');
        $routes->post('approveRevision/(:num)', 'RiwayatController::approveRevision/$1');
        $routes->get('detail/(:num)', 'RiwayatController::detail/$1');
        $routes->get('rejectRevision/(:num)', 'RiwayatController::rejectRevision/$1');
        $routes->post('delete/(:num)', 'RiwayatController::delete/$1');
    });

    $routes->group('laporan', function ($routes) {
        $routes->get('/', 'LaporanController::index');
        $routes->get('create', 'LaporanController::create');
        $routes->post('create', 'LaporanController::create');
        $routes->get('edit/(:num)', 'LaporanController::edit/$1');
        $routes->post('edit/(:num)', 'LaporanController::edit/$1');
        $routes->post('delete/(:num)', 'LaporanController::delete/$1');
        $routes->get('report/(:num)', 'LaporanController::report/$1');
        $routes->get('generateReport', 'LaporanController::generateReport');
        $routes->get('exportPDF', 'LaporanController::exportPDF');
    });

    $routes->group('transactions', function ($routes) {
        $routes->get('/', 'TransactionController::index');
        $routes->post('pay_proccess/(:num)', 'TransactionController::pay_proccess/$1');
        $routes->get('pay_dp/(:num)', 'TransactionController::pay_dp/$1');
        $routes->post('pay_dp/(:num)', 'TransactionController::pay_dp/$1');
        $routes->get('invoice/(:num)', 'TransactionController::invoice/$1');
        $routes->get('confirm_order/(:num)', 'TransactionController::confirm_order/$1');
        $routes->post('confirm_order/(:num)', 'TransactionController::confirm_order/$1');
    });

    // API routes for AJAX
    $routes->group('api', function ($routes) {
        $routes->get('models', 'Api::models');
        $routes->get('model/(:segment)', 'Api::model/$1');
        $routes->get('fabrics', 'Api::fabrics');
        $routes->get('fabric/(:segment)', 'Api::fabric/$1');
        $routes->get('customers', 'Api::customers');
        $routes->post('customer/create', 'Api::createCustomer');
    });
});
