<?php

namespace Config;

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes = Services::routes();

$routes->setDefaultNamespace('App\Controllers');
$routes->setDefaultController('Login'); // default controller: Login
$routes->setDefaultMethod('index');
$routes->setTranslateURIDashes(false);
$routes->set404Override();
$routes->setAutoRoute(false); // autoRoute sebaiknya dimatikan untuk keamanan

// 🔐 ROUTES UNTUK LOGIN (UMUM)
$routes->get('/', 'Login::index');
$routes->get('login', 'Login::index');
$routes->post('login/auth', 'Login::auth');
$routes->get('logout', 'Login::logout');

// 🛡️ ROUTES ADMIN (dengan filter login)
$routes->group('admin', ['filter' => 'auth'], function($routes) {
    $routes->get('dashboard', 'Dashboard::index');

    // Supplier
    $routes->get('supplier', 'Supplier::index');
    $routes->get('supplier/create', 'Supplier::create');
    $routes->post('supplier/store', 'Supplier::store');
    $routes->get('supplier/edit/(:num)', 'Supplier::edit/$1');
    $routes->post('supplier/update/(:num)', 'Supplier::update/$1');
    $routes->get('supplier/delete/(:num)', 'Supplier::delete/$1');

    // Customer
    $routes->get('customer', 'Customer::index');
    $routes->get('customer/create', 'Customer::create');
    $routes->post('customer/store', 'Customer::store');
    $routes->get('customer/edit/(:num)', 'Customer::edit/$1');
    $routes->post('customer/update/(:num)', 'Customer::update/$1');
    $routes->get('customer/delete/(:num)', 'Customer::delete/$1');

    // Unit
    $routes->get('unit', 'Unit::index');
    $routes->post('unit/save', 'Unit::save');
    $routes->get('unit/delete/(:num)', 'Unit::delete/$1');
    $routes->get('unit/edit/(:num)', 'Unit::edit/$1');
    $routes->post('unit/update/(:num)', 'Unit::update/$1');

    // Category
    $routes->get('category', 'Category::index');
    $routes->post('category/save', 'Category::save');
    $routes->get('category/delete/(:num)', 'Category::delete/$1');
    $routes->get('category/edit/(:num)', 'Category::edit/$1');
    $routes->post('category/update/(:num)', 'Category::update/$1');


    // Item
    $routes->get('item', 'Item::index');
    $routes->get('item/create', 'Item::create');
    $routes->post('item/save', 'Item::save');
    $routes->get('item/delete/(:num)', 'Item::delete/$1');
    $routes->get('item/edit/(:num)', 'Item::edit/$1');
    $routes->post('item/update/(:num)', 'Item::update/$1');
    $routes->get('item/disable/(:num)', 'Item::disable/$1');
    $routes->get('item/enable/(:num)', 'Item::enable/$1');
    $routes->get('item/search', 'Item::search');


    // Product In
    $routes->get('product_in', 'ProductIn::index');
    $routes->get('product_in/create', 'ProductIn::create');
    $routes->post('product_in/save', 'ProductIn::save');
    $routes->get('product_in/delete/(:num)', 'ProductIn::delete/$1');
    $routes->get('product_in/detail/(:num)', 'ProductIn::detail/$1');
    $routes->get('product_in/edit/(:num)', 'ProductIn::edit/$1');
    $routes->post('product_in/update/(:num)', 'ProductIn::update/$1');


    // Product Out
    $routes->get('product_out', 'ProductOut::index');
    $routes->post('product_out/save', 'ProductOut::save');
    $routes->get('product_out/delete/(:num)', 'ProductOut::delete/$1');
    $routes->get('product_out/detail/(:any)', 'ProductOut::detail/$1');
    $routes->get('product_out/edit/(:any)', 'ProductOut::edit/$1');
    $routes->post('product_out/update/(:any)', 'ProductOut::update/$1');


    // Sales
    $routes->get('sales', 'Sale::create');
    $routes->get('sales/create', 'Sale::create');
    $routes->post('sales/save', 'Sale::save');
    $routes->get('sales/detail/(:num)', 'Sale::detail/$1');
    $routes->get('sales/delete/(:num)', 'Sale::delete/$1');
    $routes->get('sales/print/(:num)', 'Sale::print/$1');


    // Report
    $routes->get('report', 'Report::index');
    $routes->get('report/sales', 'Report::sales');
    $routes->get('report/summary', 'Report::summary');
    $routes->get('report/sales/edit/(:num)', 'Report::edit/$1');
    $routes->post('report/sales/update/(:num)', 'Report::update/$1');
    $routes->get('report/product_in', 'Report::product_in');
    $routes->get('report/product_out', 'Report::product_out');
    $routes->get('report/product_out/detail/(:num)', 'Report::productOutDetail/$1');
    $routes->get('report/product_out/edit/(:num)', 'Report::productOutEdit/$1');
    $routes->post('report/product_out/edit/(:num)', 'Report::productOutUpdate/$1');
    $routes->get('report/product_out/delete/(:num)', 'Report::productOutDelete/$1');
    $routes->get('report/sales/detail/(:num)', 'Report::salesDetail/$1');
    $routes->post('report/product_out/update_by_kode/(:any)', 'Report::update_by_kode/$1');
    $routes->get('report/product_out/delete_by_kode/(:any)', 'Report::delete_by_kode/$1');
    $routes->get('report/items', 'Report::items');




    // Users (hanya superadmin nanti di view dibatasi)
    $routes->get('users', 'User::index');
    $routes->get('users/create', 'User::create');
    $routes->post('users/save', 'User::save');
    $routes->get('users/edit/(:num)', 'User::edit/$1');
    $routes->post('users/update/(:num)', 'User::update/$1');
    $routes->get('users/delete/(:num)', 'User::delete/$1');

    // Setting
    $routes->get('setting', 'Setting::receipt'); 
    $routes->get('setting/receipt', 'Setting::receipt');
    $routes->post('setting/receipt/save', 'Setting::receiptSave');
    $routes->get('setting/printer', 'Setting::printer');
    $routes->post('setting/printer/save', 'Setting::printerSave');
    $routes->get('setting/export', 'Setting::exportForm'); 
    $routes->post('setting/export', 'Setting::export');    
    $routes->get('setting/tax', 'Tax::index');
    $routes->get('setting/tax/create', 'Tax::create');
    $routes->post('setting/tax/save', 'Tax::save');
    $routes->get('setting/tax/edit/(:num)', 'Tax::edit/$1');
    $routes->post('setting/tax/update/(:num)', 'Tax::update/$1');
    $routes->get('setting/tax/toggle/(:num)', 'Tax::toggle/$1');
});

