import type {
  TranslationSeedItem,
  TranslationSeedModule,
} from './translation-seed.types';

// Shared UI defaults; records are independently editable under each module.
const labels: Array<[string, string, string]> = [
  [
    'evaluation.page_title',
    'Evaluation Form Management',
    'ការគ្រប់គ្រងទម្រង់វាយតម្លៃ',
  ],
  [
    'evaluation.page_subtitle',
    'Review evaluation forms submitted by PSWG Secretariat.',
    'ពិនិត្យទម្រង់វាយតម្លៃដែលបានដាក់ស្នើដោយលេខាធិការដ្ឋាន PSWG។',
  ],
  ['evaluation.total_submissions', 'Total Submissions', 'ការដាក់ស្នើសរុប'],
  [
    'evaluation.total_submissions_subtitle',
    'Evaluation forms from API',
    'ទម្រង់វាយតម្លៃពីប្រព័ន្ធ',
  ],
  ['evaluation.pending_review', 'Pending Review', 'រង់ចាំពិនិត្យ'],
  [
    'evaluation.pending_review_subtitle',
    'Awaiting admin review',
    'កំពុងរង់ចាំអ្នកគ្រប់គ្រងពិនិត្យ',
  ],
  ['evaluation.reviewed', 'Reviewed', 'បានពិនិត្យ'],
  ['evaluation.reviewed_subtitle', 'Already reviewed', 'បានពិនិត្យរួចរាល់'],
  ['evaluation.completed', 'Completed', 'បានបញ្ចប់'],
  ['evaluation.completed_subtitle', 'Completed', 'បានបញ្ចប់រួចរាល់'],
  ['evaluation.no', 'No.', 'ល.រ'],
  ['evaluation.progress_report', 'Progress Report', 'របាយការណ៍វឌ្ឍនភាព'],
  ['evaluation.total_issues', 'Total Issues', 'បញ្ហាសរុប'],
  ['evaluation.submitted_by', 'Submitted By', 'ដាក់ស្នើដោយ'],
  ['evaluation.submitted_date', 'Submitted Date', 'កាលបរិច្ឆេទដាក់ស្នើ'],
  ['evaluation.status', 'Status', 'ស្ថានភាព'],
  ['evaluation.actions', 'Actions', 'សកម្មភាព'],
  ['evaluation.previous', 'Previous', 'មុន'],
  ['evaluation.next', 'Next', 'បន្ទាប់'],
  ['evaluation.view', 'View', 'មើល'],
  ['evaluation.edit', 'Edit', 'កែប្រែ'],
  [
    'evaluation.loading',
    'Loading evaluation form...',
    'កំពុងទាញទម្រង់វាយតម្លៃ...',
  ],
  [
    'evaluation.no_data',
    'No evaluation submission found.',
    'មិនមានទម្រង់វាយតម្លៃទេ។',
  ],
  ['evaluation.pending_review_status', 'Pending Review', 'រង់ចាំពិនិត្យ'],
  ['evaluation.reviewed_status', 'Reviewed', 'បានពិនិត្យ'],
  ['evaluation.completed_status', 'Completed', 'បានបញ្ចប់'],
  [
    'evaluation.detail_title',
    'Evaluation Form Detail',
    'ព័ត៌មានលម្អិតនៃទម្រង់វាយតម្លៃ',
  ],
  ['evaluation.edit_title', 'Edit Evaluation Form', 'កែប្រែទម្រង់វាយតម្លៃ'],
  [
    'evaluation.detail_subtitle',
    'Full response submitted by PSWG Secretariat.',
    'ព័ត៌មានដែលបានដាក់ស្នើដោយលេខាធិការដ្ឋាន PSWG។',
  ],
  [
    'evaluation.edit_subtitle',
    'Update response submitted by PSWG Secretariat.',
    'កែប្រែព័ត៌មានដែលបានដាក់ស្នើដោយលេខាធិការដ្ឋាន PSWG។',
  ],
  ['evaluation.year', 'Year', 'ឆ្នាំ'],
  ['evaluation.semester', 'Semester', 'ឆមាស'],
  ['evaluation.ministry', 'Ministry', 'ក្រសួង'],
  ['evaluation.assignment_status', 'Assignment Status', 'ស្ថានភាព'],
  [
    'evaluation.overview',
    'Evaluation Response Overview',
    'សង្ខេបលទ្ធផលវាយតម្លៃ',
  ],
  ['evaluation.resolved', 'Resolved', 'បានដោះស្រាយ'],
  ['evaluation.not_resolved', 'Not Resolved', 'មិនទាន់បានដោះស្រាយ'],
  ['evaluation.not_evaluated', 'Not Evaluated', 'មិនទាន់វាយតម្លៃ'],
  ['evaluation.issues', 'Issues', 'បញ្ហា'],
  ['evaluation.issue', 'Issue', 'បញ្ហា'],
  ['evaluation.government_agencies', 'Government Agencies', 'ស្ថាប័នពាក់ព័ន្ធ'],
  ['evaluation.evaluation_result', 'Evaluation Result', 'លទ្ធផលវាយតម្លៃ'],
  ['evaluation.rating', 'Rating', 'ការវាយតម្លៃ'],
  ['evaluation.not_rated', 'Not rated', 'មិនទាន់វាយតម្លៃ'],
  ['evaluation.feedback', 'Feedback', 'មតិយោបល់'],
  ['evaluation.no_feedback', 'No feedback.', 'មិនមានមតិយោបល់។'],
  ['evaluation.cancel', 'Cancel', 'បោះបង់'],
  ['evaluation.save_changes', 'Save Changes', 'រក្សាទុកការផ្លាស់ប្តូរ'],
  ['evaluation.saving', 'Saving...', 'កំពុងរក្សាទុក...'],
  ['evaluation.close', 'Close', 'បិទ'],
  ['evaluation.write_feedback', 'Write feedback...', 'សរសេរមតិយោបល់...'],
  [
    'evaluation.load_error',
    'Unable to load evaluation form.',
    'មិនអាចទាញទម្រង់វាយតម្លៃបានទេ។',
  ],
  [
    'evaluation.update_error',
    'Unable to update evaluation form.',
    'មិនអាចកែប្រែទម្រង់វាយតម្លៃបានទេ។',
  ],
  [
    'evaluation.update_success',
    'Evaluation updated successfully.',
    'បានកែប្រែទម្រង់វាយតម្លៃដោយជោគជ័យ។',
  ],
  ['evaluation.actions_label', 'Evaluation actions', 'សកម្មភាពវាយតម្លៃ'],
  ['grid_locale.no_rows_label', 'No data', 'គ្មានទិន្នន័យ'],
  [
    'grid_locale.no_results_overlay_label',
    'No results found',
    'រកមិនឃើញលទ្ធផល',
  ],
  ['grid_locale.column_menu_label', 'Column menu', 'ម៉ឺនុយជួរឈរ'],
  ['grid_locale.column_menu_sort_asc', 'Sort by ASC', 'តម្រៀបពីតូចទៅធំ'],
  ['grid_locale.column_menu_sort_desc', 'Sort by DESC', 'តម្រៀបពីធំទៅតូច'],
  ['grid_locale.column_menu_unsort', 'Unsort', 'លុបការតម្រៀប'],
  ['grid_locale.column_menu_filter', 'Filter', 'តម្រង'],
  ['grid_locale.column_menu_hide_column', 'Hide column', 'លាក់ជួរឈរ'],
  ['grid_locale.column_menu_show_columns', 'Show columns', 'បង្ហាញជួរឈរ'],
  [
    'grid_locale.column_menu_manage_columns',
    'Manage columns',
    'គ្រប់គ្រងជួរឈរ',
  ],
  ['grid_locale.columns_management_search_title', 'Search', 'ស្វែងរក'],
  [
    'grid_locale.columns_management_show_hide_all_text',
    'Show/Hide All',
    'បង្ហាញ/លាក់ទាំងអស់',
  ],
  ['grid_locale.columns_management_reset', 'Reset', 'កំណត់ឡើងវិញ'],
  ['grid_locale.filter_panel_add_filter', 'Add filter', 'បន្ថែមតម្រង'],
  ['grid_locale.filter_panel_remove_all', 'Remove all', 'លុបទាំងអស់'],
  ['grid_locale.filter_panel_delete_icon_label', 'Delete', 'លុប'],
  ['grid_locale.filter_panel_operator', 'Operator', 'ប្រតិបត្តិការ'],
  ['grid_locale.filter_panel_columns', 'Columns', 'ជួរឈរ'],
  ['grid_locale.filter_panel_input_label', 'Value', 'តម្លៃ'],
  ['grid_locale.filter_panel_input_placeholder', 'Filter value', 'តម្លៃតម្រង'],
  [
    'grid_locale.checkbox_selection_header_name',
    'Checkbox selection',
    'ជ្រើសរើស',
  ],
  [
    'grid_locale.checkbox_selection_select_all_rows',
    'Select all rows',
    'ជ្រើសរើសទាំងអស់',
  ],
  [
    'grid_locale.checkbox_selection_unselect_all_rows',
    'Unselect all rows',
    'ដកការជ្រើសរើសទាំងអស់',
  ],
  ['grid_locale.checkbox_selection_select_row', 'Select row', 'ជ្រើសរើសជួរ'],
  [
    'grid_locale.checkbox_selection_unselect_row',
    'Unselect row',
    'ដកការជ្រើសរើសជួរ',
  ],
  ['grid_locale.column_header_sort_icon_label', 'Sort', 'តម្រៀប'],
  ['page_title', 'Issue Matrix', 'តារាងបញ្ហា'],
  ['subtitle', 'Issue Matrix', 'តារាងបញ្ហា'],
  ['search', 'Search', 'ស្វែងរក'],
  ['export_xlsx', 'Export as xlsx', 'នាំចេញជា xlsx'],
  ['exporting', 'Exporting...', 'កំពុងនាំចេញ...'],
  [
    'export_error',
    'Unable to export issue matrix.',
    'មិនអាចនាំចេញតារាងបញ្ហាបានទេ។',
  ],
  ['previous', 'Previous', 'មុន'],
  ['next', 'Next', 'បន្ទាប់'],
  ['view_detail', 'View Detail', 'មើលលម្អិត'],
  ['download', 'Download', 'ទាញយក'],
  ['no_data', 'No data found', 'មិនមានទិន្នន័យ'],
  ['status_change_dialog.title', 'Change issue status?', 'ប្តូរស្ថានភាពបញ្ហា?'],
  [
    'status_change_dialog.description',
    'Are you sure you want to change the status to "{status}"?',
    'តើអ្នកប្រាកដថាចង់ប្តូរស្ថានភាពទៅជា «{status}» ឬទេ?',
  ],
  ['status_change_dialog.confirm', 'Change status', 'ប្តូរស្ថានភាព'],
  ['status_change_dialog.cancel', 'Cancel', 'បោះបង់'],
  [
    'ministry_change_dialog.title',
    'Change primary ministry?',
    'ប្តូរក្រសួងទទួលបន្ទុក?',
  ],
  [
    'ministry_change_dialog.description',
    'Are you sure you want to change the primary ministry to "{ministry}"?',
    'តើអ្នកប្រាកដថាចង់ប្តូរក្រសួងទទួលបន្ទុកទៅជា «{ministry}» ឬទេ?',
  ],
  ['ministry_change_dialog.confirm', 'Change ministry', 'ប្តូរក្រសួង'],
  ['ministry_change_dialog.cancel', 'Cancel', 'បោះបង់'],
  [
    'row_update_toast.ministry_updated',
    'Ministry updated.',
    'បានប្តូរក្រសួងទទួលបន្ទុក។',
  ],
  ['row_update_toast.status_updated', 'Status updated.', 'បានប្តូរស្ថានភាព។'],
  [
    'plenary_escalation_dialog.escalate_title',
    'Escalate this issue to Plenary?',
    'លើកឡើងបញ្ហានេះទៅអង្គប្រជុំពេញអង្គ?',
  ],
  [
    'plenary_escalation_dialog.escalate_description',
    'The issue will be flagged for the plenary so it can be prepared and tracked there.',
    'បញ្ហានេះនឹងត្រូវបានសម្គាល់សម្រាប់អង្គប្រជុំពេញអង្គ ដើម្បីរៀបចំ និងតាមដាន។',
  ],
  ['plenary_escalation_dialog.escalate_confirm', 'Escalate', 'លើកឡើង'],
  [
    'plenary_escalation_dialog.remove_title',
    'Remove this issue from Plenary?',
    'ដកបញ្ហានេះចេញពីអង្គប្រជុំពេញអង្គ?',
  ],
  [
    'plenary_escalation_dialog.remove_description',
    'The issue will no longer be flagged for the plenary.',
    'បញ្ហានេះនឹងលែងត្រូវបានសម្គាល់សម្រាប់អង្គប្រជុំពេញអង្គទៀតហើយ។',
  ],
  ['plenary_escalation_dialog.remove_confirm', 'Remove', 'ដកចេញ'],
  ['plenary_escalation_dialog.cancel', 'Cancel', 'បោះបង់'],
  [
    'plenary_escalation_toast.escalated',
    'Issue escalated to Plenary.',
    'បានលើកឡើងបញ្ហាទៅអង្គប្រជុំពេញអង្គ។',
  ],
  [
    'plenary_escalation_toast.removed',
    'Issue removed from Plenary.',
    'បានដកបញ្ហាចេញពីអង្គប្រជុំពេញអង្គ។',
  ],
  ['plenary_escalation_toast.close', 'Close notification', 'បិទការជូនដំណឹង'],
  [
    'plenary_escalation_error',
    'Unable to update the plenary escalation.',
    'មិនអាចធ្វើបច្ចុប្បន្នភាពការលើកឡើងបានទេ។',
  ],
  ['list', 'List', 'បញ្ជី'],
  ['grid', 'Grid', 'ក្រឡា'],
  ['grid_card.no', 'No.', 'ល.រ'],
  ['grid_card.ministry', 'Ministry', 'ក្រសួង'],
  ['grid_card.status', 'Status', 'ស្ថានភាព'],
  ['grid_card.category_of_issue', 'Category of Issue', 'ប្រភេទបញ្ហា'],
  ['grid_card.issue', 'Issue', 'បញ្ហា'],
  ['grid_card.escalation', 'Escalation', 'ការលើកឡើង'],
  ['grid_card.issue_description', 'Issue Description', 'ការពិពណ៌នាបញ្ហា'],
  ['grid_card.recommendation', 'Recommendation', 'អនុសាសន៍'],
  ['grid_card.rgc_decision', 'RGC Decision', 'សេចក្តីសម្រេចរបស់រាជរដ្ឋាភិបាល'],
  ['grid_card.plenary', 'Plenary', 'អង្គប្រជុំពេញអង្គ'],
  ['grid_card.not_plenary', '-', '-'],
  ['filter.working_group', 'Working Group', 'ក្រុមការងារ'],
  ['filter.status', 'Status', 'ស្ថានភាព'],
  ['filter.category', 'Category', 'ប្រភេទ'],
  ['filter.primary_agency', 'Primary Agency', 'ស្ថាប័នទទួលបន្ទុក'],
  ['filter.year', 'Year', 'ឆ្នាំ'],
  ['filter.progress_report', 'Progress Report', 'របាយការណ៍វឌ្ឍនភាព'],
  ['filter.attachment', 'Attachment', 'ឯកសារភ្ជាប់'],
  ['detail.back', 'Back', 'ត្រឡប់ក្រោយ'],
  ['detail.page_title', 'Issue Detail', 'ព័ត៌មានលម្អិតបញ្ហា'],
  [
    'detail.breadcrumb',
    'Issue Matrix / Issue Detail',
    'តារាងបញ្ហា / ព័ត៌មានលម្អិតបញ្ហា',
  ],
  ['detail.evaluation_form', 'Evaluation Form', 'ទម្រង់វាយតម្លៃ'],
  ['stats.total_issues', 'Total Issues', 'បញ្ហាសរុប'],
  ['stats.solved', 'Solved', 'បានដោះស្រាយ'],
  ['stats.in_progress', 'In Progress', 'កំពុងដោះស្រាយ'],
  ['stats.not_addressed', 'Not Addressed', 'មិនទាន់ដោះស្រាយ'],
  [
    'stats.total_primary_agencies',
    'Total Primary Agencies',
    'ស្ថាប័នទទួលបន្ទុកសរុប',
  ],
  ['column.no', 'No.', 'ល.រ'],
  ['column.working_group', 'Working Group', 'ក្រុមការងារ'],
  ['column.issue', 'Issue', 'បញ្ហា'],
  ['column.issue_category', 'Issue Category', 'ប្រភេទបញ្ហា'],
  ['column.issue_description', 'Issue Description', 'ការពិពណ៌នាបញ្ហា'],
  ['column.recommendation', 'Recommendation', 'អនុសាសន៍'],
  [
    'column.government_decision',
    'Government Decision',
    'សេចក្តីសម្រេចរបស់រាជរដ្ឋាភិបាល',
  ],
  ['column.status', 'Status', 'ស្ថានភាព'],
  [
    'column.plenary_escalation',
    'Plenary Escalation',
    'ការលើកឡើងក្នុងអង្គប្រជុំពេញអង្គ',
  ],
  ['column.date_of_solution', 'Date of Solution', 'កាលបរិច្ឆេទដោះស្រាយ'],
  ['column.primary_agency', 'Primary Agency', 'ស្ថាប័នទទួលបន្ទុក'],
  ['column.meeting_type', 'Meeting Type', 'ប្រភេទកិច្ចប្រជុំ'],
  [
    'column.wg_meeting_date',
    'WG Meeting Date',
    'កាលបរិច្ឆេទកិច្ចប្រជុំក្រុមការងារ',
  ],
  ['column.second_agency', 'Second Agency', 'ស្ថាប័នទី២'],
  ['column.third_agency', 'Third Agency', 'ស្ថាប័នទី៣'],
  ['column.fourth_agency', 'Fourth Agency', 'ស្ថាប័នទី៤'],
  ['column.fifth_agency', 'Fifth Agency', 'ស្ថាប័នទី៥'],
  ['column.indicator', 'Indicator', 'សូចនាករ'],
  [
    'column.source_of_verification',
    'Source of Verification',
    'ប្រភពផ្ទៀងផ្ទាត់',
  ],
  [
    'column.link_to_verification_source',
    'Link to Verification Source',
    'តំណភ្ជាប់ប្រភពផ្ទៀងផ្ទាត់',
  ],
  ['column.action', 'Action', 'សកម្មភាព'],
  ['no_progress_report', 'No progress report', 'មិនមានរបាយការណ៍វឌ្ឍនភាព'],
  ['report_tab', 'Report {semester} {year}', 'របាយការណ៍ {semester} {year}'],
  ['issue_attachment', 'Issue attachment', 'ឯកសារភ្ជាប់បញ្ហា'],
  ['load_error', 'Unable to load issue matrix.', 'មិនអាចទាញយកតារាងបញ្ហាបានទេ។'],
  ['update_error', 'Unable to update issue.', 'មិនអាចកែប្រែបញ្ហាបានទេ។'],
  ['close', 'Close', 'បិទ'],
  ['submitted_detail.submitted_detail', 'Submitted Detail', 'ព័ត៌មានដាក់ស្នើ'],
  [
    'submitted_detail.government_primary_agency',
    'Government Primary Agency',
    'ស្ថាប័នរដ្ឋាភិបាលទទួលបន្ទុក',
  ],
  ['submitted_detail.submitted_date', 'Submitted Date', 'កាលបរិច្ឆេទដាក់ស្នើ'],
  ['submitted_detail.meeting_date', 'Meeting Date', 'កាលបរិច្ឆេទប្រជុំ'],
  ['submitted_detail.category', 'Category', 'ប្រភេទ'],
  ['submitted_detail.status', 'Status', 'ស្ថានភាព'],
  [
    'submitted_detail.meeting_reference_document',
    'Meeting Reference Document',
    'ឯកសារយោងកិច្ចប្រជុំ',
  ],
  [
    'submitted_detail.issue_description',
    'Issue Description',
    'ការពិពណ៌នាបញ្ហា',
  ],
  ['submitted_detail.recommendation', 'Recommendation', 'អនុសាសន៍'],
  ['submitted_detail.not_available', 'Not available', 'មិនមាន'],
  [
    'report_labels.implementation_date',
    'Implementation date',
    'កាលបរិច្ឆេទអនុវត្ត',
  ],
  ['report_labels.reference_name', 'Reference Name', 'ឈ្មោះឯកសារយោង'],
  ['report_labels.reference_link', 'Reference Link', 'តំណភ្ជាប់ឯកសារយោង'],
  [
    'report_labels.progress_solution',
    'Progress Solution',
    'វឌ្ឍនភាពនៃដំណោះស្រាយ',
  ],
  [
    'report_labels.solution_indicators',
    'Solution Indicators',
    'សូចនាករដំណោះស្រាយ',
  ],
  ['report_labels.challenges', 'Challenges', 'បញ្ហាប្រឈម'],
  ['report_labels.requests', 'Requests', 'សំណូមពរ'],
  [
    'report_labels.rgc_decision',
    'RGC Decision',
    'សេចក្តីសម្រេចរបស់រាជរដ្ឋាភិបាល',
  ],
  ['filter_panel.filter', 'Filter', 'តម្រង'],
  ['filter_panel.filter_by', 'Filter by...', 'តម្រងតាម...'],
  ['filter_panel.back', 'Back', 'ត្រឡប់ក្រោយ'],
  ['filter_panel.remove_filter', 'Remove filter', 'លុបតម្រង'],
  ['filter_panel.no_options', 'No options available', 'មិនមានជម្រើស'],
  ['filter_panel.clear_all', 'Clear all', 'សម្អាតទាំងអស់'],
  ['filter_panel.select_all', 'Select all', 'ជ្រើសរើសទាំងអស់'],
  ['filter_panel.clear_selection', 'Clear', 'សម្អាត'],
  ['filter_panel.year', 'Year', 'ឆ្នាំ'],
  ['filter_panel.month', 'Month', 'ខែ'],
  ['filter_panel.filters', 'Filters', 'តម្រង'],
  ['filter_panel.view_all', 'View All', 'មើលទាំងអស់'],
  ['filter_panel.view_less', 'View Less', 'មើលតិច'],
  ['filter_panel.apply_filters', 'Apply Filters', 'អនុវត្តតម្រង'],
  ['value_labels.draft', 'Draft', 'ព្រាង'],
  ['value_labels.saved', 'Saved', 'បានរក្សាទុក'],
  ['value_labels.new_submission', 'New Submission', 'បានដាក់ស្នើថ្មី'],
  ['value_labels.in_progress', 'In Progress', 'កំពុងដោះស្រាយ'],
  ['value_labels.solved', 'Solved', 'បានដោះស្រាយ'],
  ['value_labels.not_addressed', 'Not Addressed', 'មិនទាន់ដោះស្រាយ'],
  ['value_labels.download', 'Download', 'ទាញយក'],
  ['value_labels.working_group', 'Working Group', 'ក្រុមការងារ'],
  ['value_labels.all_status', 'All Status', 'ស្ថានភាពទាំងអស់'],
  ['value_labels.category', 'Category', 'ប្រភេទ'],
  ['value_labels.primary_agency', 'Primary Agency', 'ស្ថាប័នទទួលបន្ទុក'],
  ['value_labels.year', 'Year', 'ឆ្នាំ'],
  ['value_labels.progress_report', 'Progress Report', 'របាយការណ៍វឌ្ឍនភាព'],
  ['value_labels.attachment', 'Attachment', 'ឯកសារភ្ជាប់'],
  ['value_labels.has_attachment', 'Has Attachment', 'មានឯកសារភ្ជាប់'],
  ['value_labels.no_attachment', 'No Attachment', 'មិនមានឯកសារភ្ជាប់'],
  ['value_labels.yes', 'Yes', 'បាទ/ចាស'],
  ['value_labels.no', 'No', 'ទេ'],
  ['value_labels.both', 'Both', 'ទាំងពីរ'],
  ['value_labels.s1', 'S1', 'ឆមាសទី១'],
  ['value_labels.s2', 'S2', 'ឆមាសទី២'],
  ['value_labels.view', 'View', 'មើល'],
  ['value_labels.no_data', 'No data', 'មិនមានទិន្នន័យ'],
  ['value_labels.not_available', 'Not available', 'មិនមាន'],
  ['value_labels.not_applicable', 'Not applicable', 'មិនពាក់ព័ន្ធ'],
  ['value_labels.to_be_provided', 'To be provided', 'នឹងផ្តល់ជូន'],
];

/** Include only the page and its required sidebar ancestors, in parent-first order. */
export function selectIssueMatrixSeeds(
  all: TranslationSeedItem[],
): TranslationSeedItem[] {
  const selected: TranslationSeedItem[] = [];
  const seen = new Set<string>();
  function add(item: TranslationSeedItem) {
    const key = item.module + '/' + item.page + '/' + item.translationKey;
    if (seen.has(key)) return;
    seen.add(key);
    if (item.parent) {
      const parent = all.find(
        (candidate) =>
          candidate.module === item.parent?.module &&
          candidate.page === item.parent.page &&
          candidate.translationKey === item.parent.translationKey,
      );
      if (!parent) throw new Error('Missing seed parent for ' + key);
      add(parent);
    }
    selected.push(item);
  }
  all.filter((item) => item.page === 'issue_matrix').forEach(add);
  return selected;
}

export function withIssueMatrixLabels(
  module: TranslationSeedModule,
  existing: TranslationSeedItem[],
): TranslationSeedItem[] {
  const keys = new Set(
    existing
      .filter((item) => item.page === 'issue_matrix')
      .map((item) => item.translationKey),
  );
  const shared = [
    ...existing,
    ...labels
      .filter(([key]) => !keys.has(key))
      .map(([translationKey, englishText, khmerText]) => ({
        module,
        page: 'issue_matrix',
        translationKey,
        englishText,
        khmerText,
        isActive: true,
      })),
  ];

  // The CDC matrix screen is also mounted by CEFP. Its UI records belong to
  // each module's own page, so Admin edits never cross module boundaries.
  if (module !== 'cdc' && module !== 'cefp') return shared;
  const page = module === 'cdc' ? 'cdc_issue_matrix' : 'cefp_issue_matrix';
  const pageKeys = new Set(
    shared.filter((item) => item.page === page).map((item) => item.translationKey),
  );
  const screenLabels: Array<[string, string, string]> = [
    ['form.edit_issue.title', 'Edit Issue', 'កែសម្រួលបញ្ហា'],
    ['form.button.save_changes', 'Save Changes', 'រក្សាទុកការកែប្រែ'],
    ['form.saving', 'Saving...', 'កំពុងរក្សាទុក...'],
    ['form.loading_agency', 'Loading agency...', 'កំពុងផ្ទុកស្ថាប័ន...'],
    ['form.loading_issue_categories', 'Loading issue categories', 'កំពុងផ្ទុកប្រភេទបញ្ហា'],
    ['form.loading_issue', 'Loading issue...', 'កំពុងផ្ទុកបញ្ហា...'],
    ['form.loading_options', 'Loading form options...', 'កំពុងផ្ទុកជម្រើសទម្រង់...'],
    ['form.upload_completed', 'Completed', 'បានបញ្ចប់'],
    ['form.uploading', 'Uploading', 'កំពុងផ្ទុកឡើង'],
    ['form.click_to_upload', 'Click to upload', 'ចុចដើម្បីបញ្ចូលឯកសារ'],
    ['form.or_drag_and_drop', 'or drag and drop', 'ឬអូសទម្លាក់'],
    ['error.load_issue', 'Unable to load issue.', 'មិនអាចផ្ទុកបញ្ហាបានទេ។'],
    ['error.load_agency', 'Unable to load related government agency.', 'មិនអាចផ្ទុកស្ថាប័នរដ្ឋាភិបាលពាក់ព័ន្ធបានទេ។'],
    ['error.attachment_size', 'Attachment file size must not exceed 10 MB.', 'ទំហំឯកសារភ្ជាប់មិនត្រូវលើស 10 MB ទេ។'],
    ['error.issue_status', 'Issue status was not found.', 'រកមិនឃើញស្ថានភាពបញ្ហា។'],
    ['validation.working_group', 'Please select a working group.', 'សូមជ្រើសរើសក្រុមការងារ។'],
    ['validation.government_agency', 'Please select at least one government agency.', 'សូមជ្រើសរើសស្ថាប័នរដ្ឋាភិបាលយ៉ាងហោចណាស់មួយ។'],
    ['validation.issue_category', 'Please select an issue category.', 'សូមជ្រើសរើសប្រភេទបញ្ហា។'],
    ['exporting', 'Exporting...', 'កំពុងនាំចេញ...'],
    ['status.solved', 'Solved', 'បានដោះស្រាយ'],
    ['status.in_progress', 'In Progress', 'កំពុងដោះស្រាយ'],
    ['status.not_addressed', 'Not Addressed', 'មិនទាន់ដោះស្រាយ'],
    ['status.draft', 'Draft', 'ព្រាង'],
    ['status.saved', 'Saved', 'បានរក្សាទុក'],
    ['status.new_submission', 'New Submission', 'បានដាក់ស្នើថ្មី'],
    ['status.select', 'Select Status', 'ជ្រើសរើសស្ថានភាព'],
    ['status.loading', 'Loading...', 'កំពុងទាញទិន្នន័យ...'],
    ['action.more', 'More actions', 'សកម្មភាពផ្សេងទៀត'],
    ['action.edit', 'Edit', 'កែប្រែ'],
    ['action.remove', 'Remove Issue', 'លុបបញ្ហា'],
    ['pagination.previous', 'Previous', 'មុន'],
    ['pagination.next', 'Next', 'បន្ទាប់'],
    ['detail.loading', 'Loading issue detail...', 'កំពុងទាញព័ត៌មានលម្អិតបញ្ហា...'],
    ['detail.not_found', 'Issue detail was not found.', 'រកមិនឃើញព័ត៌មានលម្អិតបញ្ហា។'],
    ['error.load', 'Unable to load issue matrix.', 'មិនអាចទាញយកតារាងបញ្ហាបានទេ។'],
    ['detail.load_error', 'Unable to load issue detail.', 'មិនអាចទាញយកព័ត៌មានលម្អិតបញ្ហាបានទេ។'],
    ['detail.no_document', 'No document', 'មិនមានឯកសារ'],
    ['grid_locale.column_menu_aria_label', 'Column menu {columnName}', 'ម៉ឺនុយជួរឈរ {columnName}'],
  ];
  screenLabels.push(...labels.filter(([key]) => key.startsWith('grid_locale.')));
  screenLabels.push(
    ['filter_panel.filter', 'Filter', 'តម្រង'],
    ['filter_panel.filterBy', 'Filter by...', 'តម្រងតាម...'],
    ['filter_panel.back', 'Back', 'ត្រឡប់ក្រោយ'],
    ['filter_panel.removeFilter', 'Remove filter', 'លុបតម្រង'],
    ['filter_panel.noOptions', 'No options available', 'មិនមានជម្រើស'],
    ['filter_panel.clearAll', 'Clear all', 'សម្អាតទាំងអស់'],
    ['filter_panel.selectAll', 'Select all', 'ជ្រើសរើសទាំងអស់'],
    ['filter_panel.clearSelection', 'Clear', 'សម្អាត'],
    ['filter_panel.year', 'Year', 'ឆ្នាំ'],
    ['filter_panel.month', 'Month', 'ខែ'],
    ['filter_panel.filters', 'Filters', 'តម្រង'],
    ['filter_panel.viewAll', 'View All', 'មើលទាំងអស់'],
    ['filter_panel.viewLess', 'View Less', 'មើលតិច'],
    ['filter_panel.applyFilters', 'Apply Filters', 'អនុវត្តតម្រង'],
  );
  return [
    ...shared,
    ...screenLabels
      .filter(([key]) => !pageKeys.has(key))
      .map(([translationKey, englishText, khmerText]) => ({
        module, page, translationKey, englishText, khmerText, isActive: true,
      })),
  ];
}
