export type PlenaryLanguage = "kh" | "en";

export type LocalizedText =
    | string
    | {
        en: string;
        kh: string;
    };

export const plenaryText = {
    en: {
        dashboard: "Dashboard",
        dashboardSubtitle:
            "Monitor G-PSF implementation. Use filters and click charts to drill down.",

        reset: "RESET",

        totalIssues: "Total Issues",
        solved: "Solved",
        inProgress: "In Progress",
        notAddressed: "Not Addressed",
        totalPrimaryAgencies: "Total Primary Agencies",

        export: "Export",
        newItem: "New",
        addIssue: "Add Issue",
        requestMeeting: "Request Meeting",
        csv: "CSV",
        xlsx: "XLSX",
        image: "Image",
        lastUpdated: "Last updated",
        lastUpdatedDate: "14 September 2025, 23:00",
    },

    kh: {
        dashboard: "ផ្ទាំងគ្រប់គ្រង",
        dashboardSubtitle:
            "តាមដានការអនុវត្ត G-PSF។ ប្រើតម្រង និងចុចលើក្រាហ្វ ដើម្បីមើលព័ត៌មានលម្អិត។",

        reset: "កំណត់ឡើងវិញ",

        totalIssues: "បញ្ហាសរុប",
        solved: "បានដោះស្រាយ",
        inProgress: "កំពុងដំណើរការ",
        notAddressed: "មិនទាន់ដោះស្រាយ",
        totalPrimaryAgencies: "ស្ថាប័នទទួលបន្ទុកសរុប",

        export: "នាំចេញ",
        newItem: "បង្កើតថ្មី",
        addIssue: "បន្ថែមបញ្ហា",
        requestMeeting: "ស្នើសុំកិច្ចប្រជុំ",
        csv: "CSV",
        xlsx: "XLSX",
        image: "រូបភាព",
        lastUpdated: "ធ្វើបច្ចុប្បន្នភាពចុងក្រោយ",
        lastUpdatedDate: "១៤ កញ្ញា ២០២៥, ២៣:០០",
    },
} as const;

const plenaryValueTranslations: Record<string, string> = {
    Plenary: "កិច្ចប្រជុំពេញអង្គ",
    Status: "ស្ថានភាព",
    "Working Group": "ក្រុមការងារ",
    "Primary Agency": "ស្ថាប័នទទួលបន្ទុក",
    "19th G-PSF Measure Category": "ប្រភេទវិធានការ G-PSF លើកទី១៩",
    "Effective Date of Decision": "កាលបរិច្ឆេទចូលជាធរមាននៃសេចក្តីសម្រេច",

    "19th G-PSF Plenary": "កិច្ចប្រជុំពេញអង្គ G-PSF លើកទី១៩",
    "20th G-PSF Plenary": "កិច្ចប្រជុំពេញអង្គ G-PSF លើកទី២០",
    "21st G-PSF Plenary": "កិច្ចប្រជុំពេញអង្គ G-PSF លើកទី២១",
    "22nd G-PSF Plenary": "កិច្ចប្រជុំពេញអង្គ G-PSF លើកទី២២",

    Solved: "បានដោះស្រាយ",
    "In Progress": "កំពុងដំណើរការ",
    "Not Addressed": "មិនទាន់ដោះស្រាយ",

    "Law, Tax, and Governance": "ច្បាប់ ពន្ធ និងអភិបាលកិច្ច",
    Tourism: "ទេសចរណ៍",
    "Construction and Real Estate": "សំណង់ និងអចលនទ្រព្យ",
    "Energy and Mineral Resources": "ថាមពល និងធនធានរ៉ែ",
    "Industrial Relations": "ទំនាក់ទំនងឧស្សាហកម្ម",

    "5. Improving transportation and infrastructure":
        "៥. កែលម្អការដឹកជញ្ជូន និងហេដ្ឋារចនាសម្ព័ន្ធ",
    "8. Banking and Finance Sector": "៨. វិស័យធនាគារ និងហិរញ្ញវត្ថុ",
    "11. Other issues": "១១. បញ្ហាផ្សេងៗ",
    "7. Agricultural and agro-industrial": "៧. កសិកម្ម និងកសិឧស្សាហកម្ម",
    "2. Easing the burden on compliance": "២. កាត់បន្ថយបន្ទុកនៃការអនុវត្តតាមច្បាប់",
    "9. Mining and energy sector": "៩. វិស័យរ៉ែ និងថាមពល",

    "Not Specified": "មិនបានបញ្ជាក់",
    "Not Applicable": "មិនអនុវត្ត",
};

export function normalizePlenaryLanguage(
    language: string | null | undefined
): PlenaryLanguage {
    return language === "en" ? "en" : "kh";
}

export function getPlenaryLocalizedText(
    value: LocalizedText | null | undefined,
    language: PlenaryLanguage
): string {
    if (!value) {
        return "";
    }

    if (typeof value === "object") {
        return value[language] || value.en || value.kh || "";
    }

    if (language === "en") {
        return value;
    }

    return plenaryValueTranslations[value] ?? value;
}