<?php

namespace App\Libraries;

class Categories
{
    private static array $columnDefs = [];
    private static array $registry   = [];

    // -----------------------------------------------------------------------
    // Column sets
    // -----------------------------------------------------------------------

    private static function edcColumns(): array
    {
        return [
            ['field'=>'posisi','label'=>'Posisi','type'=>'date'],
            ['field'=>'kode_kanwil','label'=>'Kode Kanwil','type'=>'string'],
            ['field'=>'nama_kanwil','label'=>'Nama Kanwil','type'=>'string'],
            ['field'=>'kode_kanca','label'=>'Kode Kanca','type'=>'string'],
            ['field'=>'nama_kanca','label'=>'Nama Kanca','type'=>'string'],
            ['field'=>'kode_uker','label'=>'Kode Uker','type'=>'string'],
            ['field'=>'nama_uker','label'=>'Nama Uker','type'=>'string'],
            ['field'=>'tid','label'=>'TID','type'=>'string'],
            ['field'=>'mid','label'=>'MID','type'=>'string'],
            ['field'=>'nama_merchant','label'=>'Nama Merchant','type'=>'string'],
            ['field'=>'jenis','label'=>'Jenis','type'=>'string'],
            ['field'=>'kanwil_pemrakarsa','label'=>'Kanwil Pemrakarsa','type'=>'string'],
            ['field'=>'kanwil_nama_pemrakarsa','label'=>'Kanwil Nama Pemrakarsa','type'=>'string'],
            ['field'=>'uker_pemrakarsa','label'=>'Uker Pemrakarsa','type'=>'string'],
            ['field'=>'uker_nama_pemrakarsa','label'=>'Uker Nama Pemrakarsa','type'=>'string'],
            ['field'=>'kanwil_implementor','label'=>'Kanwil Implementor','type'=>'string'],
            ['field'=>'kanwil_nama_implementor','label'=>'Kanwil Nama Implementor','type'=>'string'],
            ['field'=>'uker_implementor','label'=>'Uker Implementor','type'=>'string'],
            ['field'=>'uker_nama_implementor','label'=>'Uker Nama Implementor','type'=>'string'],
            ['field'=>'pn_user_pemrakarsa','label'=>'PN User Pemrakarsa','type'=>'string'],
            ['field'=>'nama_user_pemrakarsa','label'=>'Nama User Pemrakarsa','type'=>'string'],
            ['field'=>'last_available','label'=>'Last Available','type'=>'date'],
            ['field'=>'status_available','label'=>'Status Available','type'=>'string'],
            ['field'=>'last_utility','label'=>'Last Utility','type'=>'date'],
            ['field'=>'status_utility','label'=>'Status Utility','type'=>'string'],
            ['field'=>'last_transactional','label'=>'Last Transactional','type'=>'date'],
            ['field'=>'status_transactional','label'=>'Status Transactional','type'=>'string'],
            ['field'=>'alamat_merchant','label'=>'Alamat Merchant','type'=>'string'],
            ['field'=>'kelurahan','label'=>'Kelurahan','type'=>'string'],
            ['field'=>'kecamatan','label'=>'Kecamatan','type'=>'string'],
            ['field'=>'kabupaten','label'=>'Kabupaten','type'=>'string'],
            ['field'=>'provinsi','label'=>'Provinsi','type'=>'string'],
            ['field'=>'aktif_or_staging','label'=>'Aktif / Staging','type'=>'string'],
            ['field'=>'jml_transaksi','label'=>'Jml Transaksi','type'=>'decimal'],
            ['field'=>'sales_volume','label'=>'Sales Volume','type'=>'decimal'],
            ['field'=>'akumulasi_transaksi','label'=>'Akumulasi Transaksi','type'=>'decimal'],
            ['field'=>'akumulasi_sales_volume','label'=>'Akumulasi Sales Volume','type'=>'decimal'],
            ['field'=>'kartu_jml_transaksi_on_us','label'=>'Kartu Jml Transaksi On-Us','type'=>'decimal'],
            ['field'=>'kartu_jml_transaksi_off_us','label'=>'Kartu Jml Transaksi Off-Us','type'=>'decimal'],
            ['field'=>'jml_transaksi_qris','label'=>'Jml Transaksi QRIS','type'=>'decimal'],
            ['field'=>'kartu_sales_volume_on_us','label'=>'Kartu Sales Volume On-Us','type'=>'decimal'],
            ['field'=>'kartu_sales_volume_off_us','label'=>'Kartu Sales Volume Off-Us','type'=>'decimal'],
            ['field'=>'sales_volume_qris','label'=>'Sales Volume QRIS','type'=>'decimal'],
            ['field'=>'ket_mcc','label'=>'Ket MCC','type'=>'string'],
            ['field'=>'kode_mcc','label'=>'Kode MCC','type'=>'string'],
            ['field'=>'norek','label'=>'No Rek','type'=>'string'],
            ['field'=>'cifno','label'=>'CIF No','type'=>'string'],
            ['field'=>'saldo_posisi','label'=>'Saldo Posisi','type'=>'decimal'],
            ['field'=>'ratas_saldo','label'=>'Ratas Saldo','type'=>'decimal'],
            ['field'=>'saldo_posisi_by_cif','label'=>'Saldo Posisi by CIF','type'=>'decimal'],
            ['field'=>'ratas_saldo_by_cif','label'=>'Ratas Saldo by CIF','type'=>'decimal'],
            ['field'=>'tgl_approval','label'=>'Tgl Approval','type'=>'date'],
            ['field'=>'nilai','label'=>'Nilai','type'=>'decimal'],
            ['field'=>'source','label'=>'Source','type'=>'string'],
            ['field'=>'sales_volume_mid','label'=>'Sales Volume MID','type'=>'decimal'],
            ['field'=>'flagging','label'=>'Flagging','type'=>'string'],
            ['field'=>'flagging_bri_merchant','label'=>'Flagging BRI Merchant','type'=>'string'],
            ['field'=>'tiering_sales_volume','label'=>'Tiering Sales Volume','type'=>'string'],
            ['field'=>'status_edc','label'=>'Status EDC','type'=>'string'],
        ];
    }

    private static function edcDisplayColumns(): array
    {
        return [
            ['field'=>'posisi','label'=>'Posisi','type'=>'date'],
            ['field'=>'nama_uker','label'=>'Nama Uker','type'=>'string'],
            ['field'=>'tid','label'=>'TID','type'=>'string'],
            ['field'=>'mid','label'=>'MID','type'=>'string'],
            ['field'=>'nama_merchant','label'=>'Nama Merchant','type'=>'string'],
            ['field'=>'uker_nama_implementor','label'=>'Uker Implementor','type'=>'string'],
            ['field'=>'nama_user_pemrakarsa','label'=>'Nama User Pemrakarsa','type'=>'string'],
            ['field'=>'alamat_merchant','label'=>'Alamat','type'=>'string'],
            ['field'=>'sales_volume','label'=>'Sales Volume','type'=>'decimal'],
            ['field'=>'saldo_posisi','label'=>'Saldo Posisi','type'=>'decimal'],
            ['field'=>'tiering_sales_volume','label'=>'Tiering Sales Volume','type'=>'string'],
            ['field'=>'status_edc','label'=>'Status EDC','type'=>'string'],
        ];
    }

    private static function defaultColumns(): array
    {
        return [
            ['field'=>'periode','label'=>'Periode','type'=>'date'],
            ['field'=>'kode_kanwil','label'=>'Kode Kanwil','type'=>'string'],
            ['field'=>'kanwil','label'=>'Kanwil','type'=>'string'],
            ['field'=>'kode_kanca','label'=>'Kode Kanca','type'=>'string'],
            ['field'=>'kanca','label'=>'Kanca','type'=>'string'],
            ['field'=>'kode_uker','label'=>'Kode Uker','type'=>'string'],
            ['field'=>'uker','label'=>'Uker','type'=>'string'],
            ['field'=>'curr','label'=>'Curr','type'=>'string'],
            ['field'=>'currdesc','label'=>'Curr Desc','type'=>'string'],
            ['field'=>'cifno','label'=>'CIF No','type'=>'string'],
            ['field'=>'account_number','label'=>'Account Number','type'=>'bigint'],
            ['field'=>'product_code','label'=>'Product Code','type'=>'string'],
            ['field'=>'status','label'=>'Status','type'=>'int'],
            ['field'=>'short_name','label'=>'Short Name','type'=>'string'],
            ['field'=>'open_date','label'=>'Open Date','type'=>'date'],
            ['field'=>'balance','label'=>'Balance','type'=>'decimal'],
            ['field'=>'avail_balance','label'=>'Avail Balance','type'=>'decimal'],
            ['field'=>'limit_amount','label'=>'Limit Amount','type'=>'decimal'],
            ['field'=>'cr_int','label'=>'Cr Int','type'=>'decimal'],
            ['field'=>'dr_int','label'=>'Dr Int','type'=>'decimal'],
            ['field'=>'commitment','label'=>'Commitment','type'=>'decimal'],
            ['field'=>'avrg_balance','label'=>'Avrg Balance','type'=>'decimal'],
            ['field'=>'pn_pengelola_single_pn','label'=>'PN Pengelola Single PN','type'=>'string'],
            ['field'=>'pn_customer_service','label'=>'PN Customer Service','type'=>'string'],
            ['field'=>'pn_rm_dana','label'=>'PN RM Dana','type'=>'string'],
            ['field'=>'pn_rm_pinjaman','label'=>'PN RM Pinjaman','type'=>'string'],
            ['field'=>'pn_rm_merchant','label'=>'PN RM Merchant','type'=>'string'],
            ['field'=>'pn_relationship_officer','label'=>'PN Relationship Officer','type'=>'string'],
            ['field'=>'pn_sales_person','label'=>'PN Sales Person','type'=>'string'],
            ['field'=>'pn_pab','label'=>'PN PAB','type'=>'string'],
            ['field'=>'pn_rm_referral','label'=>'PN RM Referral','type'=>'string'],
        ];
    }

    private static function qrisColumns(): array
    {
        return [
            ['field'=>'periode','label'=>'Periode','type'=>'string'],
            ['field'=>'posisi','label'=>'Posisi','type'=>'string'],
            ['field'=>'region','label'=>'Region','type'=>'string'],
            ['field'=>'rgdesc','label'=>'Rgdesc','type'=>'string'],
            ['field'=>'mainbr','label'=>'Mainbr','type'=>'string'],
            ['field'=>'mbdesc','label'=>'Mbdesc','type'=>'string'],
            ['field'=>'branch','label'=>'Branch','type'=>'string'],
            ['field'=>'x','label'=>'X','type'=>'string'],
            ['field'=>'brdesc','label'=>'Brdesc','type'=>'string'],
            ['field'=>'merchant_pan','label'=>'Merchant PAN','type'=>'string'],
            ['field'=>'storeid','label'=>'Store ID','type'=>'string'],
            ['field'=>'nama_merchant','label'=>'Nama Merchant','type'=>'string'],
            ['field'=>'kriteria','label'=>'Kriteria','type'=>'string'],
            ['field'=>'jenis_usaha','label'=>'Jenis Usaha','type'=>'string'],
            ['field'=>'kode_mcc','label'=>'Kode MCC','type'=>'string'],
            ['field'=>'mcc','label'=>'MCC','type'=>'string'],
            ['field'=>'alamat','label'=>'Alamat','type'=>'string'],
            ['field'=>'kode_pos','label'=>'Kode Pos','type'=>'string'],
            ['field'=>'kota','label'=>'Kota','type'=>'string'],
            ['field'=>'provinsi','label'=>'Provinsi','type'=>'string'],
            ['field'=>'no_rek','label'=>'No Rek','type'=>'string'],
            ['field'=>'cif','label'=>'CIF','type'=>'string'],
            ['field'=>'pn','label'=>'PN','type'=>'string'],
            ['field'=>'pn_pemrakasa','label'=>'PN Pemrakasa','type'=>'string'],
            ['field'=>'jabatan','label'=>'Jabatan','type'=>'string'],
            ['field'=>'tgl_balikan_pten','label'=>'Tgl Balikan PTEN','type'=>'string'],
            ['field'=>'status','label'=>'Status','type'=>'string'],
            ['field'=>'merchant_type','label'=>'Merchant Type','type'=>'string'],
            ['field'=>'akumulasi_sv_onus','label'=>'Akumulasi SV Onus','type'=>'decimal'],
            ['field'=>'akumulasi_sv_offus','label'=>'Akumulasi SV Offus','type'=>'decimal'],
            ['field'=>'akumulasi_sv_linkaja','label'=>'Akumulasi SV LinkAja','type'=>'decimal'],
            ['field'=>'akumulasi_sv_total','label'=>'Akumulasi SV Total','type'=>'decimal'],
            ['field'=>'posisi_sv_total','label'=>'Posisi SV Total','type'=>'decimal'],
            ['field'=>'akumulasi_trx_onus','label'=>'Akumulasi TRX Onus','type'=>'decimal'],
            ['field'=>'akumulasi_trx_offus','label'=>'Akumulasi TRX Offus','type'=>'decimal'],
            ['field'=>'akumulasi_trx_linkaja','label'=>'Akumulasi TRX LinkAja','type'=>'decimal'],
            ['field'=>'akumulasi_trx_total','label'=>'Akumulasi TRX Total','type'=>'decimal'],
            ['field'=>'posisi_trx_total','label'=>'Posisi TRX Total','type'=>'decimal'],
            ['field'=>'saldo_posisi','label'=>'Saldo Posisi','type'=>'decimal'],
            ['field'=>'ratas_saldo','label'=>'Ratas Saldo','type'=>'decimal'],
            ['field'=>'flagging_bri_merchant','label'=>'Flagging BRI Merchant','type'=>'string'],
            ['field'=>'status_qris','label'=>'Status QRIS','type'=>'string'],
        ];
    }

    private static function depoColumns(): array
    {
        return [
            ['field'=>'periode','label'=>'Periode','type'=>'string'],
            ['field'=>'kode_uker','label'=>'Kode Uker','type'=>'string'],
            ['field'=>'cur_code','label'=>'Cur Code','type'=>'string'],
            ['field'=>'cur_desc','label'=>'Cur Desc','type'=>'string'],
            ['field'=>'type','label'=>'Type','type'=>'string'],
            ['field'=>'acctno','label'=>'Acctno','type'=>'string'],
            ['field'=>'fdr_srl_no','label'=>'FDR Srl No','type'=>'string'],
            ['field'=>'principal_amount','label'=>'Principal Amount','type'=>'decimal'],
            ['field'=>'short_name','label'=>'Short Name','type'=>'string'],
            ['field'=>'withdrawable_int','label'=>'Withdrawable Int','type'=>'decimal'],
            ['field'=>'issue_dt','label'=>'Issue Dt','type'=>'string'],
            ['field'=>'mat_dt','label'=>'Mat Dt','type'=>'string'],
            ['field'=>'int_rate','label'=>'Int Rate','type'=>'decimal'],
            ['field'=>'int_tenor_disp','label'=>'Int Tenor Disp','type'=>'string'],
            ['field'=>'renew','label'=>'Renew','type'=>'string'],
            ['field'=>'remark','label'=>'Remark','type'=>'string'],
            ['field'=>'pn_customer_service','label'=>'PN Customer Service','type'=>'string'],
            ['field'=>'pn_rm_dana','label'=>'PN RM Dana','type'=>'string'],
            ['field'=>'pn_rm_pinjaman','label'=>'PN RM Pinjaman','type'=>'string'],
            ['field'=>'pn_rm_merchant','label'=>'PN RM Merchant','type'=>'string'],
            ['field'=>'pn_relationship_officer','label'=>'PN Relationship Officer','type'=>'string'],
            ['field'=>'pn_sales_person','label'=>'PN Sales Person','type'=>'string'],
            ['field'=>'pn_pab','label'=>'PN PAB','type'=>'string'],
            ['field'=>'pn_rm_referral','label'=>'PN RM Referral','type'=>'string'],
            ['field'=>'jumlah_pn','label'=>'Jumlah PN','type'=>'decimal'],
            ['field'=>'cbal_base','label'=>'CBAL Base','type'=>'decimal'],
        ];
    }

    private static function di319Columns(): array
    {
        return [
            ['field'=>'periode','label'=>'Periode','type'=>'date'],
            ['field'=>'uker_code','label'=>'Uker Code','type'=>'string'],
            ['field'=>'curr_code','label'=>'Curr Code','type'=>'string'],
            ['field'=>'curr_desc','label'=>'Curr Desc','type'=>'string'],
            ['field'=>'account_number','label'=>'Account Number','type'=>'bigint'],
            ['field'=>'ciff_no','label'=>'CIFF No','type'=>'string'],
            ['field'=>'short_name','label'=>'Short Name','type'=>'string'],
            ['field'=>'open_dt','label'=>'Open Dt','type'=>'date'],
            ['field'=>'balance','label'=>'Balance','type'=>'decimal'],
            ['field'=>'in_balance','label'=>'In Balance','type'=>'decimal'],
            ['field'=>'accrued_int','label'=>'Accrued Int','type'=>'decimal'],
            ['field'=>'average_balance','label'=>'Average Balance','type'=>'decimal'],
            ['field'=>'prod_code','label'=>'Prod Code','type'=>'string'],
            ['field'=>'pn_pengelola_singlepn','label'=>'PN Pengelola SinglePN','type'=>'string'],
            ['field'=>'pn_customer_service','label'=>'PN Customer Service','type'=>'string'],
            ['field'=>'pn_rm_dana_mantri','label'=>'PN RM Dana/Mantri','type'=>'string'],
            ['field'=>'pn_rm_pinjaman','label'=>'PN RM Pinjaman','type'=>'string'],
            ['field'=>'pn_rm_merchant','label'=>'PN RM Merchant','type'=>'string'],
            ['field'=>'pn_relationship_officer_rm_kredit_menengah','label'=>'PN Relationship Officer/RM Kredit Menengah','type'=>'string'],
            ['field'=>'pn_sales_person','label'=>'PN Sales Person','type'=>'string'],
            ['field'=>'pn_pab','label'=>'PN PAB','type'=>'string'],
            ['field'=>'pn_rm_referral','label'=>'PN RM Referral','type'=>'string'],
            ['field'=>'jumlah_pn_pemasar','label'=>'Jumlah PN Pemasar','type'=>'int'],
            ['field'=>'balance_dalam_idr','label'=>'Balance Dalam IDR','type'=>'decimal'],
        ];
    }

    private static function di321Columns(): array
    {
        return [
            ['field'=>'periode','label'=>'Periode','type'=>'date'],
            ['field'=>'kanca','label'=>'Kanca','type'=>'string'],
            ['field'=>'curr','label'=>'Curr','type'=>'string'],
            ['field'=>'cifno','label'=>'CIF No','type'=>'string'],
            ['field'=>'account_number','label'=>'Account Number','type'=>'bigint'],
            ['field'=>'short_name','label'=>'Short Name','type'=>'string'],
            ['field'=>'balance','label'=>'Balance','type'=>'decimal'],
            ['field'=>'pn_rm_dana','label'=>'PN RM Dana','type'=>'string'],
            ['field'=>'pn_rm_pinjaman','label'=>'PN RM Pinjaman','type'=>'string'],
            ['field'=>'pn_rm_merchant','label'=>'PN RM Merchant','type'=>'string'],
            ['field'=>'pn_relationship_officer','label'=>'PN Relationship Officer','type'=>'string'],
        ];
    }

    private static function mtdDualColumns(): array
    {
        return [
            ['field'=>'norek','label'=>'Norek','type'=>'string'],
            ['field'=>'nama_nasabah','label'=>'Nama Nasabah','type'=>'string'],
            ['field'=>'tgl1','label'=>'tgl 1','type'=>'decimal'],
            ['field'=>'tgl2','label'=>'tgl 2','type'=>'decimal'],
            ['field'=>'rm_pengelola','label'=>'RM Pengelola','type'=>'string'],
        ];
    }

    // -----------------------------------------------------------------------
    // Registry & helpers
    // -----------------------------------------------------------------------

    public static function getColumns(string $type): array
    {
        return match ($type) {
            'edc'         => self::edcColumns(),
            'edc_display' => self::edcDisplayColumns(),
            'qris'        => self::qrisColumns(),
            'depo'        => self::depoColumns(),
            'di319'       => self::di319Columns(),
            'di321'       => self::di321Columns(),
            'mtd_dual'    => self::mtdDualColumns(),
            default       => self::defaultColumns(),
        };
    }

    public static function getRegistry(): array
    {
        return [
            'edc'  => ['key'=>'edc',  'label'=>'EDC',      'table'=>'data_edc',  'columns'=>'edc',  'datatable_columns'=>'edc_display', 'group'=>null, 'hidden'=>false, 'row_editable'=>false, 'header_row'=>1],
            'qris' => ['key'=>'qris', 'label'=>'QRIS',     'table'=>'data_qris', 'columns'=>'qris', 'datatable_columns'=>null,          'group'=>null, 'hidden'=>false, 'row_editable'=>false, 'header_row'=>1],

            'di319_data1' => ['key'=>'di319_data1','label'=>'DATA1','table'=>'data_di319_data1','columns'=>'di319','datatable_columns'=>null,'group'=>'DI319','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'di319_data2' => ['key'=>'di319_data2','label'=>'DATA2','table'=>'data_di319_data2','columns'=>'di319','datatable_columns'=>null,'group'=>'DI319','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'di319_data3' => ['key'=>'di319_data3','label'=>'DATA3','table'=>'data_di319_data3','columns'=>'di319','datatable_columns'=>null,'group'=>'DI319','hidden'=>false,'row_editable'=>false,'header_row'=>1],

            'di321_data1' => ['key'=>'di321_data1','label'=>'DATA1','table'=>'data_di321_data1','columns'=>'default','datatable_columns'=>'di321','group'=>'DI321','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'di321_data2' => ['key'=>'di321_data2','label'=>'DATA2','table'=>'data_di321_data2','columns'=>'default','datatable_columns'=>'di321','group'=>'DI321','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'di321_data3' => ['key'=>'di321_data3','label'=>'DATA3','table'=>'data_di321_data3','columns'=>'default','datatable_columns'=>'di321','group'=>'DI321','hidden'=>false,'row_editable'=>false,'header_row'=>1],

            'depo'      => ['key'=>'depo',     'label'=>'DEPO',     'table'=>'data_depo',     'columns'=>'depo',   'datatable_columns'=>null,'group'=>null,     'hidden'=>false,'row_editable'=>false,'header_row'=>4],
            'pic_jalan' => ['key'=>'pic_jalan','label'=>'PIC JALAN','table'=>'data_pic_jalan','columns'=>'default','datatable_columns'=>null,'group'=>null,     'hidden'=>false,'row_editable'=>false,'header_row'=>1],

            'mtd_tab'  => ['key'=>'mtd_tab', 'label'=>'MTD TAB', 'table'=>'data_mtd_tab', 'columns'=>'default','datatable_columns'=>null,'group'=>'MTD YTD','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'ytd_tab'  => ['key'=>'ytd_tab', 'label'=>'YTD TAB', 'table'=>'data_ytd_tab', 'columns'=>'default','datatable_columns'=>null,'group'=>'MTD YTD','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'mtd_giro' => ['key'=>'mtd_giro','label'=>'MTD GIRO','table'=>'data_mtd_giro','columns'=>'default','datatable_columns'=>null,'group'=>'MTD YTD','hidden'=>false,'row_editable'=>false,'header_row'=>1],
            'ytd_giro' => ['key'=>'ytd_giro','label'=>'YTD GIRO','table'=>'data_ytd_giro','columns'=>'default','datatable_columns'=>null,'group'=>'MTD YTD','hidden'=>false,'row_editable'=>false,'header_row'=>1],

            'mtd_tab_penurunan'  => ['key'=>'mtd_tab_penurunan', 'label'=>'Penurunan','table'=>'data_mtd_tab_penurunan', 'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'mtd_tab_kenaikan'   => ['key'=>'mtd_tab_kenaikan',  'label'=>'Kenaikan', 'table'=>'data_mtd_tab_kenaikan',  'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'ytd_tab_penurunan'  => ['key'=>'ytd_tab_penurunan', 'label'=>'Penurunan','table'=>'data_ytd_tab_penurunan', 'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'ytd_tab_kenaikan'   => ['key'=>'ytd_tab_kenaikan',  'label'=>'Kenaikan', 'table'=>'data_ytd_tab_kenaikan',  'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'mtd_giro_penurunan' => ['key'=>'mtd_giro_penurunan','label'=>'Penurunan','table'=>'data_mtd_giro_penurunan','columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'mtd_giro_kenaikan'  => ['key'=>'mtd_giro_kenaikan', 'label'=>'Kenaikan', 'table'=>'data_mtd_giro_kenaikan', 'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'ytd_giro_penurunan' => ['key'=>'ytd_giro_penurunan','label'=>'Penurunan','table'=>'data_ytd_giro_penurunan','columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
            'ytd_giro_kenaikan'  => ['key'=>'ytd_giro_kenaikan', 'label'=>'Kenaikan', 'table'=>'data_ytd_giro_kenaikan', 'columns'=>'mtd_dual','datatable_columns'=>null,'group'=>null,'hidden'=>true,'row_editable'=>true,'header_row'=>1],
        ];
    }

    public static function resolve(string $key): ?array
    {
        return self::getRegistry()[$key] ?? null;
    }

    public static function getDisplayColumns(array $cat): array
    {
        $type = $cat['datatable_columns'] ?? $cat['columns'];
        return self::getColumns($type);
    }

    public static function getImportColumns(array $cat): array
    {
        return self::getColumns($cat['columns']);
    }

    public static function isReadonly(array $cat): bool
    {
        if ($cat['hidden'] && ! $cat['row_editable']) return true;
        if ($cat['group'] === 'MTD YTD') return true;
        return false;
    }

    public static function getNavCategories(): array
    {
        $nav = [];
        foreach (self::getRegistry() as $cat) {
            if ($cat['hidden']) continue;
            $group = $cat['group'] ?? 'ungrouped';
            $nav[$group][] = $cat;
        }
        return $nav;
    }

    /** Return parent key => [penurunan_key, kenaikan_key] for dual-table categories */
    public static function getDualMap(): array
    {
        return [
            'mtd_tab'  => ['mtd_tab_penurunan',  'mtd_tab_kenaikan'],
            'ytd_tab'  => ['ytd_tab_penurunan',  'ytd_tab_kenaikan'],
            'mtd_giro' => ['mtd_giro_penurunan', 'mtd_giro_kenaikan'],
            'ytd_giro' => ['ytd_giro_penurunan', 'ytd_giro_kenaikan'],
        ];
    }
}
