<?php
/* ============================================================================
 *  config/modules.php — central registry of company modules.
 *  'built' = true  -> the module is live (real pages exist).
 *  'built' = false -> placeholder/coming-soon, ready to develop.
 *  To add a module, add one line here; it auto-appears in the admin dashboard,
 *  the company create/edit checkboxes, and the company dashboard.
 * ==========================================================================*/

function available_modules(): array {
    return [
        /* ── HR modules (built / live) ── */
        'staff' => [
            'icon'=>'👥', 'en'=>'Staff Management', 'lo'=>'ຈັດການພະນັກງານ',
            'desc_en'=>'Staff list, profiles, documents & bank info.', 'desc_lo'=>'ລາຍຊື່, ໂປຣໄຟລ໌, ເອກະສານ ແລະ ທະນາຄານ',
            'color'=>'card-teal', 'built'=>true, 'group'=>'HR',
        ],
        'attendance' => [
            'icon'=>'🕐', 'en'=>'Attendance Management', 'lo'=>'ຈັດການການເຂົ້າວຽກ',
            'desc_en'=>'Check-in selfies, shifts, GPS, OT & settings.', 'desc_lo'=>'ລົງເວລາ, ກະ, GPS, OT ແລະ ການຕັ້ງຄ່າ',
            'color'=>'card-amber', 'built'=>true, 'group'=>'HR', 'needs'=>'staff',
        ],
        'leave' => [
            'icon'=>'🏖️', 'en'=>'Leave Management', 'lo'=>'ຈັດການການລາພັກ',
            'desc_en'=>'Leave requests, approvals & annual balances.', 'desc_lo'=>'ຄຳຂໍລາພັກ, ອະນຸມັດ ແລະ ໂຄຕາ',
            'color'=>'card-green', 'built'=>true, 'group'=>'HR', 'needs'=>'staff',
        ],
        'payroll' => [
            'icon'=>'💵', 'en'=>'Payroll Management', 'lo'=>'ຈັດການເງິນເດືອນ',
            'desc_en'=>'Salary, auto payroll, payslips, loans & allowances.', 'desc_lo'=>'ເງິນເດືອນ, ໃບແຈ້ງ, ກູ້ຢືມ ແລະ ເບ້ຍ',
            'color'=>'card-blue', 'built'=>true, 'group'=>'HR', 'needs'=>'staff',
        ],

        /* ── Service Portal modules (native, Type 1: Photocopy Rental) ── */
        'customer' => [
            'icon'=>'👤', 'en'=>'Customer Management', 'lo'=>'ຈັດການລູກຄ້າ',
            'desc_en'=>'Customers & machines (Type 1: Photocopy Rental).', 'desc_lo'=>'ລູກຄ້າ ແລະ ເຄື່ອງຈັກ (ປະເພດ 1: ເຊົ່າຖ່າຍເອກະສານ)',
            'color'=>'card-blue', 'built'=>true, 'group'=>'Operations', 'type'=>'photocopy_rental',
        ],
        'stock' => [
            'icon'=>'📦', 'en'=>'Stock Management', 'lo'=>'ຈັດການສະຕັອກ',
            'desc_en'=>'Inventory & stock in/out (Type 1: Photocopy Rental).', 'desc_lo'=>'ສິນຄ້າຄົງຄັງ, ເຂົ້າ-ອອກ (ປະເພດ 1: ເຊົ່າຖ່າຍເອກະສານ)',
            'color'=>'card-purple', 'built'=>true, 'group'=>'Operations', 'type'=>'photocopy_rental',
        ],
        'jobs' => [
            'icon'=>'🛠️', 'en'=>'Job Management', 'lo'=>'ຈັດການວຽກບໍລິການ',
            'desc_en'=>'Service jobs — create, assign & close (Type 1: Photocopy Rental).', 'desc_lo'=>'ວຽກບໍລິການ — ສ້າງ, ມອບໝາຍ ແລະ ປິດ (ປະເພດ 1: ເຊົ່າຖ່າຍເອກະສານ)',
            'color'=>'card-teal', 'built'=>true, 'group'=>'Operations', 'type'=>'photocopy_rental',
        ],
        'part_request' => [
            'icon'=>'🧾', 'en'=>'Request Form', 'lo'=>'ໃບຂໍ',
            'desc_en'=>'Staff request parts/toner; stock control fulfils (Type 1: Photocopy Rental).', 'desc_lo'=>'ພະນັກງານຂໍອາໄຫຼ່/ໝຶກ; ຄວບຄຸມສະຕັອກເປັນຜູ້ຈ່າຍ',
            'color'=>'card-amber', 'built'=>true, 'group'=>'Operations', 'type'=>'photocopy_rental',
        ],
        'asset' => [
            'icon'=>'🏷️', 'en'=>'Asset Management', 'lo'=>'ຈັດການຊັບສິນ',
            'desc_en'=>'Register and track company assets.', 'desc_lo'=>'ລົງທະບຽນ ແລະ ຕິດຕາມຊັບສິນ',
            'color'=>'card-purple', 'built'=>false, 'group'=>'Operations',
        ],
        'fleet' => [
            'icon'=>'🚚', 'en'=>'Car Fleet Management', 'lo'=>'ຈັດການກອງລົດ',
            'desc_en'=>'Manage vehicles, fuel and maintenance.', 'desc_lo'=>'ຈັດການລົດ, ນ້ຳມັນ ແລະ ການບຳລຸງ',
            'color'=>'card-amber', 'built'=>false, 'group'=>'Operations',
        ],
        'meter' => [
            'icon'=>'⏱️', 'en'=>'Meter Collecting', 'lo'=>'ເກັບຄ່າມິເຕີ',
            'desc_en'=>'Record meter readings and billing.', 'desc_lo'=>'ບັນທຶກເລກມິເຕີ ແລະ ໃບບິນ',
            'color'=>'card-teal', 'built'=>false, 'group'=>'Operations',
        ],
        'invoice' => [
            'icon'=>'🧾', 'en'=>'Invoice System', 'lo'=>'ລະບົບໃບເກັບເງິນ',
            'desc_en'=>'Create and track customer invoices.', 'desc_lo'=>'ສ້າງ ແລະ ຕິດຕາມໃບເກັບເງິນ',
            'color'=>'card-green', 'built'=>false, 'group'=>'Sales',
        ],
        'quotation' => [
            'icon'=>'📝', 'en'=>'Quotation', 'lo'=>'ໃບສະເໜີລາຄາ',
            'desc_en'=>'Prepare and send price quotations.', 'desc_lo'=>'ສ້າງ ແລະ ສົ່ງໃບສະເໜີລາຄາ',
            'color'=>'card-pink', 'built'=>false, 'group'=>'Sales',
        ],
    ];
}

/* Module keys enabled for a company */
function company_enabled_modules(PDO $pdo, int $companyId): array {
    try {
        $st = $pdo->prepare("SELECT module_key FROM company_modules WHERE company_id=?");
        $st->execute([$companyId]);
        return array_column($st->fetchAll(PDO::FETCH_ASSOC), 'module_key');
    } catch (Throwable $e) { return []; }
}

/* Convenience: is a module enabled for this company's set? */
function module_on(array $enabled, string $key): bool {
    return in_array($key, $enabled, true);
}