<?php

use CodeIgniter\Router\RouteCollection;

/**
 * @var RouteCollection $routes
 */
$routes->get('/', 'Home::index');

// =============================================
// Import Excel — TikTok OrderSKUList
// =============================================
$routes->get('/import', 'Import::index');
$routes->post('/import/process', 'Import::process');
$routes->get('/import/riwayat', 'Import::riwayat');

// =============================================
// Omnichannel Penjualan (POS, Reseller, Maklon)
// =============================================
$routes->group('penjualan', function ($routes) {
    $routes->get('/', 'Penjualan::index');
    $routes->post('store-manual', 'Penjualan::storeManual');
    $routes->post('store-mitra', 'Penjualan::storeMitra');
});

// =============================================
// Withdrawal Dashboard (CEO)
// =============================================
$routes->get('/withdrawal', 'Withdrawal::index');
$routes->get('/withdrawal/data', 'Withdrawal::data');
$routes->post('/withdrawal/tarik', 'Withdrawal::tarik');
$routes->post('/withdrawal/reset', 'Withdrawal::reset');
$routes->get('/temp-reset-semua', 'Withdrawal::tempResetSemua');

// =============================================
// Dashboard Analitik
// =============================================
$routes->get('/analytics', 'Analytics::index');
$routes->get('/analytics/data', 'Analytics::data');

// =============================================
// Rekap Produk
// =============================================
$routes->get('/rekap-produk', 'RekapProduk::index');
$routes->get('/rekap-produk/data', 'RekapProduk::data');
$routes->get('/rekap-produk/unit-terjual', 'RekapProduk::unitTerjual');

// ── Bahan ──────────────────────────────────────────────────────
$routes->get('bahan', 'Bahan::index');
$routes->get('bahan/data', 'Bahan::data');
$routes->post('bahan/simpan', 'Bahan::simpan');
$routes->post('bahan/pakai', 'Bahan::pakai');
$routes->post('bahan/hapus', 'Bahan::hapus');
$routes->post('bahan/restore', 'Bahan::restore');
$routes->post('bahan/toggle-status', 'Bahan::toggleStatus');

// ── Pembelian Bahan ────────────────────────────────────────────
$routes->get('pembelian-bahan', 'PembelianBahan::index');
$routes->get('pembelian-bahan/data', 'PembelianBahan::data');
$routes->post('pembelian-bahan/simpan', 'PembelianBahan::simpan');
$routes->post('pembelian-bahan/hapus', 'PembelianBahan::hapus');

// =============================================
// Manajemen Produk
// =============================================
$routes->get('produk', 'Produk::index');
$routes->get('produk/data', 'Produk::data');
$routes->post('produk/simpan', 'Produk::simpan');
$routes->post('produk/mutasi', 'Produk::mutasi');
$routes->post('produk/tambah-stok', 'Produk::tambahStok');
$routes->post('produk/kurangi-stok', 'Produk::kurangiStok');
$routes->post('produk/nonaktifkan', 'Produk::nonaktifkan');
$routes->post('produk/aktifkan', 'Produk::aktifkan');

// =============================================
// Produksi
// =============================================
$routes->get('produksi', 'Produksi::index');
$routes->get('produksi/data', 'Produksi::data');
$routes->post('produksi/simpan', 'Produksi::simpan');
$routes->post('produksi/batalkan', 'Produksi::batalkan');
$routes->get('produksi/detail/(:num)', 'Produksi::detail/$1');

// =============================================
// Resep
// =============================================
$routes->get('resep', 'Resep::index');
$routes->get('/resep/create', 'Resep::create');
$routes->post('/resep/store', 'Resep::store');
$routes->get('/resep/show/(:num)', 'Resep::show/$1');
$routes->get('/resep/edit/(:num)', 'Resep::edit/$1');
$routes->post('/resep/update/(:num)', 'Resep::update/$1');
$routes->post('/resep/delete/(:num)', 'Resep::delete/$1');
$routes->get('resep/bahan-data', 'Resep::getBahanData');
$routes->get('/resep/detail/(:num)', 'Resep::detail/$1');

// =============================================
// Finance — Kas Ledger
// =============================================
$routes->group('finance', function ($routes) {
    $routes->get('pengeluaran', 'Finance::index');
    $routes->post('store', 'Finance::store');
    $routes->get('buku-besar', 'Finance::bukuBesar');
    $routes->get('laporan-keuangan', 'Finance::laporanKeuangan');
});

// =============================================
// HRD Portal
// =============================================
$routes->group('hrd', function ($routes) {
    // Karyawan
    $routes->get('karyawan', 'HRD::karyawan');
    $routes->post('store-karyawan', 'HRD::storeKaryawan');
    $routes->post('delete-karyawan/(:num)', 'HRD::deleteKaryawan/$1');
    $routes->post('toggle-status-karyawan/(:num)', 'HRD::toggleStatusKaryawan/$1'); // ← duplikat dihapus

    // Absensi
    $routes->get('absensi', 'HRD::absensi');
    $routes->post('store-absensi', 'HRD::storeAbsensi');
    $routes->post('update-absensi', 'HRD::updateAbsensi');
    $routes->post('delete-absensi/(:num)', 'HRD::deleteAbsensi/$1');
    $routes->get('laporan-absensi', 'HRD::laporanAbsensi');

    // Penggajian
    $routes->get('penggajian', 'HRD::penggajian');
    $routes->post('generate-gaji', 'HRD::generateGaji');
    $routes->post('bayar-gaji/(:num)', 'HRD::bayarGaji/$1');
    $routes->get('laporan-penggajian', 'HRD::laporanPenggajian');
});

// =============================================
// Master Data Management
// =============================================
$routes->group('master', function ($routes) {
    // Reseller
    $routes->get('reseller', 'Master\Reseller::index');
    $routes->post('reseller/store', 'Master\Reseller::store');
    $routes->post('reseller/toggle/(:num)', 'Master\Reseller::toggleStatus/$1');

    // Maklon
    $routes->get('maklon', 'Master\Maklon::index');
    $routes->post('maklon/store', 'Master\Maklon::store');
    $routes->post('maklon/toggle/(:num)', 'Master\Maklon::toggleStatus/$1');

    // Marketplace
    $routes->get('marketplace', 'Master\Marketplace::index');
    $routes->post('marketplace/store', 'Master\Marketplace::store');
    $routes->post('marketplace/delete/(:num)', 'Master\Marketplace::delete/$1');
    $routes->post('marketplace/toggle/(:num)', 'Master\Marketplace::toggleStatus/$1');
});

// =============================================
// Laporan Penjualan
// =============================================
$routes->group('laporan-penjualan', function ($routes) {
    $routes->get('/', 'LaporanPenjualan::index');
    $routes->get('data', 'LaporanPenjualan::data');
    $routes->get('detail/(:any)', 'LaporanPenjualan::detail/$1'); // ← (:any) bukan (:num) — support TikTok order_id
    $routes->get('export-xlsx', 'LaporanPenjualan::exportXlsx');
    $routes->get('laporan-penjualan/metode-list', 'LaporanPenjualan::metodeList');
});

// =============================================
// Laporan Produksi
// =============================================
$routes->get('laporan/produksi', 'LaporanProduksi::index');
$routes->get('laporan/produksi/data', 'LaporanProduksi::data');