<?php

declare(strict_types=1);

namespace PpPhp\Core\I18n;

/**
 * Canonical catalogue of the generated app's UI "chrome" strings — every fixed
 * label the shell, toolbars, dashboard, notifications, auth menu, admin area and
 * common pages render through `pp_t('ui.<key>', '<English default>')`.
 *
 * ONE source of truth so that:
 *   • the build seeds the English dictionary + emits the full list to translate,
 *   • the Misc → Label Editor → "App Strings" tab lists exactly these keys with
 *     their English reference, and
 *   • a translator can localise the whole interface for ANY language (not just
 *     the historical hard-coded Nepali subset).
 *
 * Keys are WITHOUT the `ui.` prefix (the build adds it). Grouped only for human
 * readability; `all()` flattens them.
 */
final class UiStrings
{
    /** @return array<string, array<string, string>> group => [key => English default] */
    public static function groups(): array
    {
        return [
            'Navigation' => [
                'calendar'         => 'Calendar',
                'home'             => 'Home',
                'main_nav'         => 'Main navigation',
                'toggle_menu'      => 'Toggle menu',
                'skip_to_content'  => 'Skip to content',
                'back_home'        => 'Back to Home',
                'search'           => 'Search…',
            ],
            'List & records' => [
                'add'              => 'Add',
                'add_new'          => 'Add New',
                'view_all'         => 'View all',
                'inline_add'       => 'Inline Add',
                'actions'          => 'Actions',
                'view'             => 'View',
                'edit'             => 'Edit',
                'edit_inline'      => 'Edit inline',
                'delete'           => 'Delete',
                'clear'            => 'Clear',
                'clear_search'     => 'Clear search',
                'search_records'   => 'Search records…',
                'filter'           => 'Filter',
                'filter_records'   => 'Filter records',
                'apply'            => 'Apply',
                'keep_current'     => 'keep current',
                'all'              => 'All',
                'all_data'         => 'All data',
                'record'           => 'Record',
                'record_info'      => 'Displaying %from% – %to% of %total%',
                'records_per_page' => 'Records per page',
                'no_records'       => 'No records found.',
                'search_to_view'   => 'Enter a search to view records.',
                'details'          => 'Details',
                'proceed_details'  => 'Proceed to details',
                'data'             => 'Data',
                'export'           => 'Export',
                'export_records'   => 'Export records…',
                'import_records'   => 'Import records…',
                'quick_download'   => 'Quick download',
                'print'            => 'Print',
                'pdf'              => 'PDF',
                'download_pdf'     => 'Download as PDF',
                'view_mode'        => 'View mode',
                'table_view'       => 'Table view',
                'card_view'        => 'Card view',
                'refresh'          => 'Refresh',
                'density'          => 'Density',
                'columns'          => 'Columns',
                'more'             => 'More',
                'update'           => 'Update',
                'selected'         => 'selected',
                'min'              => 'Min',
                'max'              => 'Max',
                'from'             => 'From',
                'to'               => 'To',
                'select_all'       => 'Select all',
                'select'           => 'Select',
                'loading'          => 'Loading…',
                'ok'               => 'OK',
                'yes'              => 'Yes',
                'no'               => 'No',
                'copy'             => 'Copy',
                'copy_clipboard'   => 'Copy to clipboard',
                'copy_view_link'   => 'Copy link to this view',
                'copied'           => 'Copied',
                'no_match'         => 'No records match your filters.',
                'clear_filters'    => 'Clear filters',
                'add_first'        => 'Add the first record',
            ],
            'Forms' => [
                'new_record'       => 'New Record',
                'edit_record'      => 'Edit Record',
                'record_details'   => 'Record Details',
                'save'             => 'Save',
                'save_new'         => 'Save & New',
                'save_close'       => 'Save & Close',
                'cancel'           => 'Cancel',
                'back'             => 'Back',
                'reset'            => 'Reset',
                'back_to_list'     => 'Back to List',
            ],
            'Account & notifications' => [
                'user'             => 'User',
                'profile'          => 'Profile',
                'logout'           => 'Logout',
                'sign_out'         => 'Sign out',
                'notifications'    => 'Notifications',
                'all_caught_up'    => "You're all caught up.",
                'mark_all_read'    => 'Mark all read',
                'time_just_now'    => 'Just now',
                'time_min_ago'     => 'min ago',
                'time_hr_ago'      => 'hr ago',
                'time_yesterday'   => 'Yesterday',
                'time_days_ago'    => 'days ago',
            ],
            'Admin & security' => [
                'admin_area'       => 'Admin Area',
                'exit_admin_area'  => 'Exit Admin Area',
                'audit_log'        => 'Audit Log',
                'record_locks'     => 'Record Locks',
                'translations'     => 'Translations',
                'two_factor'       => 'Two-Factor Authentication',
            ],
            'Theme' => [
                'theme'            => 'Theme',
                'theme_system'     => 'System',
                'theme_light'      => 'Light',
                'theme_dark'       => 'Dark',
            ],
        ];
    }

    /** @return array<string,string> flat key => English default */
    public static function all(): array
    {
        $out = [];
        foreach (self::groups() as $keys) {
            foreach ($keys as $k => $v) {
                $out[$k] = $v;
            }
        }
        return $out;
    }

    /**
     * Bundled translations shipped for well-known languages, used to SEED the
     * dictionary so a project gets a sensible default before anyone opens the
     * editor. The owner's Label Editor values always override these.
     *
     * @return array<string,string> key => translated value ('' / [] when none)
     */
    public static function seed(string $lang): array
    {
        $lang = strtolower($lang);
        $seeds = [
            'np' => [
                'search' => 'खोज्नुहोस्', 'add_new' => 'नयाँ थप्नुहोस्', 'actions' => 'कार्यहरू',
                'view' => 'हेर्नुहोस्', 'edit' => 'सम्पादन', 'delete' => 'मेटाउनुहोस्',
                'dashboard' => 'ड्यासबोर्ड', 'logout' => 'लगआउट', 'profile' => 'प्रोफाइल',
                'sign_out' => 'साइन आउट', 'welcome_back' => 'पुनः स्वागत छ',
                'no_records' => 'कुनै रेकर्ड फेला परेन', 'save' => 'सुरक्षित गर्नुहोस्',
                'cancel' => 'रद्द गर्नुहोस्', 'back_to_list' => 'सूचीमा फर्कनुहोस्',
                'records' => 'रेकर्डहरू', 'clear' => 'हटाउनुहोस्', 'notifications' => 'सूचनाहरू',
                'no_notifications' => 'कुनै सूचना छैन', 'search_to_view' => 'रेकर्ड हेर्न खोज्नुहोस्',
                'inline_add' => 'इनलाइन थप्नुहोस्', 'spreadsheet' => 'स्प्रेडसिट',
                'back_home' => 'गृह पृष्ठमा फर्कनुहोस्', 'calendar' => 'पात्रो',
                'update' => 'अद्यावधिक गर्नुहोस्', 'selected' => 'चयनित',
                'min' => 'न्यून', 'max' => 'अधिक', 'from' => 'देखि', 'to' => 'सम्म',
                'all' => 'सबै', 'filter' => 'फिल्टर', 'apply' => 'लागू गर्नुहोस्', 'reset' => 'रिसेट',
                'select_all' => 'सबै छान्नुहोस्', 'loading' => 'लोड हुँदै…', 'ok' => 'ठीक छ',
                // List & records chrome — fills the Nepali experience end-to-end.
                'add' => 'थप्नुहोस्', 'view_all' => 'सबै हेर्नुहोस्', 'edit_inline' => 'इनलाइन सम्पादन',
                'clear_search' => 'खोजी हटाउनुहोस्', 'search_records' => 'रेकर्ड खोज्नुहोस्…',
                'filter_records' => 'रेकर्ड फिल्टर गर्नुहोस्', 'keep_current' => 'हालको राख्नुहोस्',
                'all_data' => 'सबै डेटा', 'record' => 'रेकर्ड', 'records_per_page' => 'प्रति पृष्ठ रेकर्ड',
                'record_info' => '%total% मध्ये %from% – %to% देखाइँदै',
                'details' => 'विवरण', 'proceed_details' => 'विवरणमा जानुहोस्', 'data' => 'डेटा',
                'export' => 'निर्यात', 'export_records' => 'रेकर्ड निर्यात गर्नुहोस्…',
                'import_records' => 'रेकर्ड आयात गर्नुहोस्…', 'quick_download' => 'द्रुत डाउनलोड',
                'print' => 'छाप्नुहोस्', 'download_pdf' => 'PDF डाउनलोड गर्नुहोस्',
                'view_mode' => 'दृश्य शैली', 'table_view' => 'तालिका दृश्य', 'card_view' => 'कार्ड दृश्य',
                'refresh' => 'ताजा गर्नुहोस्', 'density' => 'घनत्व', 'columns' => 'स्तम्भहरू', 'more' => 'थप',
                'home' => 'गृह', 'new_record' => 'नयाँ रेकर्ड', 'edit_record' => 'रेकर्ड सम्पादन',
                'record_details' => 'रेकर्ड विवरण', 'save_new' => 'सुरक्षित गरी नयाँ',
                'save_close' => 'सुरक्षित गरी बन्द', 'back' => 'पछाडि',
            ],
        ];
        $seeds['ne'] = $seeds['np'];
        return $seeds[$lang] ?? [];
    }
}
