-- Add missing Arabic translations for dashboard pages
-- This script inserts/updates translations for all keys used in the codebase

DO $$
DECLARE
    _lang_code text := 'ar';
    _key_id uuid;
    _key_name text;
    _arabic_value text;
BEGIN

    -- First, ensure all translation keys exist
    -- customer keys
    INSERT INTO translation_keys (key, category, description, default_value) VALUES
        ('customers.added', 'customers', 'Success message after adding customer', 'Customer added'),
        ('customers.addError', 'customers', 'Error message when adding customer fails', 'Failed to add customer'),
        ('customers.addNewCustomer', 'customers', 'Title for add customer form', 'Add New Customer'),
        ('customers.bookingsLoadError', 'customers', 'Error loading reservations', 'Failed to load reservations'),
        ('customers.colCustomer', 'customers', 'Table column header', 'Customer'),
        ('customers.colLastVisit', 'customers', 'Table column header', 'Last Visit'),
        ('customers.colLoyalty', 'customers', 'Table column header', 'Loyalty'),
        ('customers.colMemberSince', 'customers', 'Table column header', 'Member Since'),
        ('customers.colOrders', 'customers', 'Table column header', 'Orders'),
        ('customers.colReservations', 'customers', 'Table column header', 'Reservations'),
        ('customers.colTotalSpent', 'customers', 'Table column header', 'Total Spent'),
        ('customers.customers', 'customers', 'Plural of customer', 'customers'),
        ('customers.fullNamePlaceholder', 'customers', 'Placeholder for full name input', 'Full name *'),
        ('customers.loadError', 'customers', 'Error loading customers', 'Failed to load customers'),
        ('customers.markedOptIn', 'customers', 'Success message for opt-in', 'Customer re-subscribed to marketing'),
        ('customers.markedOptOut', 'customers', 'Success message for opt-out', 'Customer opted out of marketing'),
        ('customers.marketingPrefs', 'customers', 'Label for marketing preferences', 'Marketing messages'),
        ('customers.memberSince', 'customers', 'Label for member since date', 'Member since'),
        ('customers.noContactDetails', 'customers', 'Message when no contact details', 'No contact details on record'),
        ('customers.noCustomersSub', 'customers', 'Empty state description', 'Customers appear when they interact with your AI agent or when you add them manually'),
        ('customers.noOrders', 'customers', 'Message when no orders', 'No orders found'),
        ('customers.noReservations', 'customers', 'Message when no reservations', 'No reservations found'),
        ('customers.optedIn', 'customers', 'Opted in status', 'Opted in'),
        ('customers.optedOut', 'customers', 'Opted out status', 'Opted out'),
        ('customers.optOut', 'customers', 'Opt out button', 'Opt out'),
        ('customers.orderNum', 'customers', 'Order number label', 'Order #'),
        ('customers.preferences', 'customers', 'Customer preferences label', 'Preferences'),
        ('customers.pts', 'customers', 'Points abbreviation', 'pts'),
        ('customers.reSubscribe', 'customers', 'Re-subscribe button', 'Re-subscribe'),
        ('customers.searchPlaceholder', 'customers', 'Search placeholder', 'Search by name, email, or phone…'),
        ('customers.specialRequests', 'customers', 'Special requests label', 'Special Requests'),
        ('customers.statAvgOrder', 'customers', 'Stat label', 'Avg Order'),
        ('customers.statLastVisit', 'customers', 'Stat label', 'Last Visit'),
        ('customers.statReservations', 'customers', 'Stat label', 'Reservations'),
        ('customers.statTotalOrders', 'customers', 'Stat label', 'Total Orders'),
        ('customers.statTotalSpent', 'customers', 'Stat label', 'Total Spent'),
        ('customers.statTotalVisits', 'customers', 'Stat label', 'Total Visits'),
        ('customers.tags', 'customers', 'Customer tags label', 'Tags'),
        ('customers.party', 'customers', 'Party size label', 'Party'),
        ('customers.items', 'customers', 'Items label', 'Items')
    ON CONFLICT (key) DO NOTHING;

    -- staff keys
    INSERT INTO translation_keys (key, category, description, default_value) VALUES
        ('staff.save', 'staff', 'Save button', 'Save'),
        ('staff.saving', 'staff', 'Saving status', 'Saving…'),
        ('staff.cancel', 'staff', 'Cancel button', 'Cancel'),
        ('staff.close', 'staff', 'Close button', 'Close'),
        ('staff.edit', 'staff', 'Edit button', 'Edit'),
        ('staff.delete', 'staff', 'Delete button', 'Delete'),
        ('staff.newRole', 'staff', 'New role button', 'New Role'),
        ('staff.addStaff', 'staff', 'Add staff button', 'Add Staff'),
        ('staff.addStaffMember', 'staff', 'Add staff member title', 'Add Staff Member'),
        ('staff.addNewRole', 'staff', 'Add new role button', 'Add New Role'),
        ('staff.customPermissions', 'staff', 'Custom permissions badge', 'Custom permissions'),
        ('staff.customRoleName', 'staff', 'Custom role name template', '{{name}} (Custom)'),
        ('staff.defaultRoleName', 'staff', 'Default role name', 'Staff'),
        ('staff.deleteRole', 'staff', 'Delete role button', 'Delete role'),
        ('staff.editRole', 'staff', 'Edit role title', 'Edit Role: {{name}}'),
        ('staff.editRoleTitle', 'staff', 'Edit role button title', 'Edit role'),
        ('staff.editStaff', 'staff', 'Edit staff title', 'Edit: {{name}}'),
        ('staff.emailLabel', 'staff', 'Email field label', 'Email'),
        ('staff.errors.deleteRoleFailed', 'staff', 'Error deleting role', 'Failed to delete role'),
        ('staff.errors.deleteStaff', 'staff', 'Error deleting staff', 'Failed to delete staff:'),
        ('staff.errors.deleteSystemRole', 'staff', 'Cannot delete system role error', 'System roles cannot be deleted'),
        ('staff.errors.loadRoles', 'staff', 'Error loading roles', 'Failed to load roles:'),
        ('staff.errors.loadStaff', 'staff', 'Error loading staff', 'Failed to load staff:'),
        ('staff.errors.nameRequired', 'staff', 'Name required error', 'Name is required'),
        ('staff.errors.roleNameRequired', 'staff', 'Role name required error', 'Role name is required'),
        ('staff.errors.saveRoleFailed', 'staff', 'Error saving role', 'Failed to save role'),
        ('staff.errors.saveStaffFailed', 'staff', 'Error saving staff', 'Failed to save staff member'),
        ('staff.errors.updateStaff', 'staff', 'Error updating staff', 'Failed to update staff:'),
        ('staff.fullAccessBadge', 'staff', 'Full access badge', 'Full Access'),
        ('staff.groups.aiAgent', 'staff', 'AI Agent group', 'AI Agent'),
        ('staff.groups.channels', 'staff', 'Channels group', 'Channels'),
        ('staff.groups.growth', 'staff', 'Growth group', 'Growth'),
        ('staff.groups.manage', 'staff', 'Manage group', 'Manage'),
        ('staff.groups.operations', 'staff', 'Operations group', 'Operations'),
        ('staff.groups.overview', 'staff', 'Overview group', 'Overview'),
        ('staff.groups.restaurant', 'staff', 'Store group', 'Store'),
        ('staff.matrix.section', 'staff', 'Permission matrix section header', 'Section'),
        ('staff.member', 'staff', 'Single member', 'member'),
        ('staff.members', 'staff', 'Multiple members', 'members'),
        ('staff.noPermissions', 'staff', 'No permissions message', 'No permissions assigned'),
        ('staff.noRoles', 'staff', 'No roles message', 'No roles yet'),
        ('staff.noStaffMembers', 'staff', 'No staff message', 'No staff members yet'),
        ('staff.roleCreated', 'staff', 'Role created success', 'Role created'),
        ('staff.roleDeleted', 'staff', 'Role deleted success', 'Role deleted'),
        ('staff.rolePermissionsDesc', 'staff', 'Role permissions description', 'Permissions pre-filled from {{name}} role — you can customise below.'),
        ('staff.roleUpdated', 'staff', 'Role updated success', 'Role updated'),
        ('staff.crud.create', 'staff', 'Create permission', 'Create'),
        ('staff.crud.read', 'staff', 'Read permission', 'Read'),
        ('staff.crud.update', 'staff', 'Update permission', 'Update'),
        ('staff.crud.delete', 'staff', 'Delete permission', 'Delete'),
        ('staff.crud.createAbbr', 'staff', 'Create abbreviation', 'C'),
        ('staff.crud.readAbbr', 'staff', 'Read abbreviation', 'R'),
        ('staff.crud.updateAbbr', 'staff', 'Update abbreviation', 'U'),
        ('staff.crud.deleteAbbr', 'staff', 'Delete abbreviation', 'D'),
        ('staff.sections.ai_config', 'staff', 'AI Config section', 'AI Configuration'),
        ('staff.sections.analytics', 'staff', 'Analytics section', 'Analytics'),
        ('staff.sections.branches', 'staff', 'Branches section', 'Branches'),
        ('staff.sections.chat_widget', 'staff', 'Chat Widget section', 'Chat Widget'),
        ('staff.sections.conversations', 'staff', 'Conversations section', 'Conversations'),
        ('staff.sections.coupons', 'staff', 'Coupons section', 'Coupons'),
        ('staff.sections.customers', 'staff', 'Customers section', 'Customers'),
        ('staff.sections.dashboard', 'staff', 'Dashboard section', 'Dashboard'),
        ('staff.sections.gift_cards', 'staff', 'Gift Cards section', 'Gift Cards'),
        ('staff.sections.knowledge_base', 'staff', 'Knowledge Base section', 'Knowledge Base'),
        ('staff.sections.loyalty', 'staff', 'Loyalty Program section', 'Loyalty Program'),
        ('staff.sections.marketing', 'staff', 'Marketing section', 'Marketing'),
        ('staff.sections.menu', 'staff', 'Menu section', 'Menu'),
        ('staff.sections.orders', 'staff', 'Orders section', 'Orders'),
        ('staff.sections.reservations', 'staff', 'Reservations section', 'Reservations'),
        ('staff.sections.staff', 'staff', 'Staff section', 'Staff'),
        ('staff.sections.storefront', 'staff', 'QR Storefront section', 'QR Storefront'),
        ('staff.sections.telephone', 'staff', 'Telephone section', 'Telephone'),
        ('staff.sections.whatsapp', 'staff', 'WhatsApp section', 'WhatsApp'),
        ('staff.sections.settings', 'staff', 'Settings section', 'Settings'),
        ('staff.placeholders.email', 'staff', 'Email placeholder', 'Email address'),
        ('staff.placeholders.fullName', 'staff', 'Full name placeholder', 'Full name'),
        ('staff.placeholders.roleDescription', 'staff', 'Role description placeholder', 'Short description of this role'),
        ('staff.placeholders.roleName', 'staff', 'Role name placeholder', 'e.g. Cashier'),
        ('staff.placeholders.searchStaff', 'staff', 'Search staff placeholder', 'Search staff…'),
        ('staff.permissionsLegend', 'staff', 'Permissions legend', 'C = Create  R = Read  U = Update  D = Delete'),
        ('staff.permissionsTitle', 'staff', 'Permissions title', 'Permissions'),
        ('staff.resetToDefaults', 'staff', 'Reset to defaults button', 'Reset to {{name}} defaults'),
        ('staff.roleNameLabel', 'staff', 'Role name label', 'Role Name *'),
        ('staff.systemBadge', 'staff', 'System badge', 'System'),
        ('staff.systemRole', 'staff', 'System role label', 'System'),
        ('staff.table.lastActive', 'staff', 'Table column', 'Last Active'),
        ('staff.table.permissions', 'staff', 'Table column', 'Permissions'),
        ('staff.table.role', 'staff', 'Table column', 'Role'),
        ('staff.table.staffMember', 'staff', 'Table column', 'Staff Member'),
        ('staff.table.status', 'staff', 'Table column', 'Status'),
        ('staff.tabs.members', 'staff', 'Members tab', 'Team Members'),
        ('staff.tabs.roles', 'staff', 'Roles tab', 'Roles & Permissions'),
        ('staff.status.inactive', 'staff', 'Inactive status', 'inactive'),
        ('staff.status.active', 'staff', 'Active status', 'active'),
        ('staff.statusUpdated', 'staff', 'Status updated message', 'Staff status updated'),
        ('staff.staffAdded', 'staff', 'Staff added message', 'Staff member added'),
        ('staff.staffRemoved', 'staff', 'Staff removed message', 'Staff member removed'),
        ('staff.staffUpdated', 'staff', 'Staff updated message', 'Staff member updated'),
        ('staff.descriptionLabel', 'staff', 'Description label', 'Description'),
        ('staff.fullNameLabel', 'staff', 'Full name label', 'Full Name *'),
        ('staff.roleLabel', 'staff', 'Role label', 'Role'),
        ('staff.noRoleAssigned', 'staff', 'No role assigned', 'No role assigned'),
        ('staff.ownerRoleDesc', 'staff', 'Owner role description', 'Owner role is read-only — all permissions are always enabled'),
        ('staff.viewRole', 'staff', 'View role button', 'View role'),
        ('staff.addFirstMember', 'staff', 'Add first member message', 'Add your first team member to get started'),
        ('staff.createFirstRole', 'staff', 'Create first role message', 'Create a role to define permission sets for your staff'),
        ('staff.pageTitle', 'staff', 'Page title', 'Staff & Team'),
        ('staff.pageSubtitle', 'staff', 'Page subtitle', 'Manage roles, permissions, and staff accounts')
    ON CONFLICT (key) DO NOTHING;

    -- menuManagement keys
    INSERT INTO translation_keys (key, category, description, default_value) VALUES
        ('menuManagement.itemCreated', 'menu', 'Item created message', 'Item created'),
        ('menuManagement.itemUpdated', 'menu', 'Item updated message', 'Item updated'),
        ('menuManagement.itemNameRequired', 'menu', 'Item name required error', 'Item name is required'),
        ('menuManagement.saveFailed', 'menu', 'Save failed error', 'Save failed'),
        ('menuManagement.itemNameStar', 'menu', 'Item name field label', 'Item Name *'),
        ('menuManagement.itemNamePlaceholder', 'menu', 'Item name placeholder', 'e.g. Butter Chicken'),
        ('menuManagement.priceLabel', 'menu', 'Price label', 'Price (₹)'),
        ('menuManagement.category', 'menu', 'Category label', 'Category'),
        ('menuManagement.uncategorized', 'menu', 'Uncategorized option', 'Uncategorized'),
        ('menuManagement.description', 'menu', 'Description label', 'Description'),
        ('menuManagement.descriptionPlaceholder', 'menu', 'Description placeholder', 'Describe the dish…'),
        ('menuManagement.itemImage', 'menu', 'Item image label', 'Item Image'),
        ('menuManagement.upload', 'menu', 'Upload button', 'Upload'),
        ('menuManagement.imageUrlPlaceholder', 'menu', 'Image URL placeholder', 'Or paste URL…'),
        ('menuManagement.properties', 'menu', 'Properties section', 'Properties'),
        ('menuManagement.vegetarian', 'menu', 'Vegetarian label', 'Vegetarian'),
        ('menuManagement.spice', 'menu', 'Spice label', 'Spice'),
        ('menuManagement.spiceNo', 'menu', 'No spice', 'No Spice'),
        ('menuManagement.spiceMild', 'menu', 'Mild spice', 'Mild'),
        ('menuManagement.spiceMedium', 'menu', 'Medium spice', 'Medium'),
        ('menuManagement.spiceHot', 'menu', 'Hot spice', 'Hot'),
        ('menuManagement.prepTime', 'menu', 'Prep time label', 'Prep Time (min)'),
        ('menuManagement.calories', 'menu', 'Calories label', 'Calories (kcal)'),
        ('menuManagement.stock', 'menu', 'Stock section', 'Stock'),
        ('menuManagement.inStock', 'menu', 'In stock label', 'In stock'),
        ('menuManagement.stockCount', 'menu', 'Stock count label', 'Stock count'),
        ('menuManagement.unlimited', 'menu', 'Unlimited placeholder', 'Unlimited'),
        ('menuManagement.stockCountHelp', 'menu', 'Stock count help', 'Leave blank for unlimited. Auto-decrements per order.'),
        ('menuManagement.lowStockThreshold', 'menu', 'Low stock threshold label', 'Low-stock threshold'),
        ('menuManagement.disabled', 'menu', 'Disabled placeholder', 'Disabled'),
        ('menuManagement.lowStockThresholdHelp', 'menu', 'Low stock threshold help', 'Email + dashboard alert when stock drops to this value. Leave blank to disable.'),
        ('menuManagement.dailyResetCount', 'menu', 'Daily reset count label', 'Daily reset target'),
        ('menuManagement.dailyResetCountHelp', 'menu', 'Daily reset help', 'At local midnight, stock resets to this number. Leave blank to disable.'),
        ('menuManagement.thresholdAboveReset', 'menu', 'Threshold error', 'Low-stock threshold must be at most the daily reset target.'),
        ('menuManagement.schedule', 'menu', 'Schedule section', 'Schedule'),
        ('menuManagement.scheduleHelp', 'menu', 'Schedule help', 'Limit when this item is orderable. Times are in the branch timezone.'),
        ('menuManagement.branchAvailability', 'menu', 'Branch availability section', 'Branch availability'),
        ('menuManagement.modifierGroups', 'menu', 'Modifier groups section', 'Modifier Groups'),
        ('menuManagement.addGroup', 'menu', 'Add group button', 'Add Group'),
        ('menuManagement.groupNamePlaceholder', 'menu', 'Group name placeholder', 'Group name (e.g. Choose Size, Add-ons)'),
        ('menuManagement.radioPickOne', 'menu', 'Radio option', 'Radio (Pick one)'),
        ('menuManagement.checkboxPickMany', 'menu', 'Checkbox option', 'Checkbox (Pick many)'),
        ('menuManagement.minSelections', 'menu', 'Min selections label', 'Min selections'),
        ('menuManagement.maxSelections', 'menu', 'Max selections label', 'Max selections'),
        ('menuManagement.noLimit', 'menu', 'No limit placeholder', 'No limit'),
        ('menuManagement.requiredSelection', 'menu', 'Required selection checkbox', 'Required selection'),
        ('menuManagement.create', 'menu', 'Create button', 'Create'),
        ('menuManagement.noModifierGroups', 'menu', 'No modifier groups message', 'No modifier groups yet. Add sizes, add-ons, or sides.'),
        ('menuManagement.radio', 'menu', 'Radio label', 'Radio'),
        ('menuManagement.checkbox', 'menu', 'Checkbox label', 'Checkbox'),
        ('menuManagement.min', 'menu', 'Min abbreviation', 'Min'),
        ('menuManagement.max', 'menu', 'Max abbreviation', 'Max'),
        ('menuManagement.required', 'menu', 'Required label', 'Required'),
        ('menuManagement.priceDeltaPlaceholder', 'menu', 'Price delta placeholder', '₹ delta'),
        ('menuManagement.def', 'menu', 'Default abbreviation', 'Def'),
        ('menuManagement.defBadge', 'menu', 'Default badge', 'Def'),
        ('menuManagement.free', 'menu', 'Free label', 'Free'),
        ('menuManagement.optionName', 'menu', 'Option name placeholder', 'Option name'),
        ('menuManagement.extraPrice', 'menu', 'Extra price placeholder', '₹ extra'),
        ('menuManagement.saveItemFirstToAddModifierGroups', 'menu', 'Save first message', 'Save item first to add modifier groups (sizes, add-ons, sides).'),
        ('menuManagement.addItem', 'menu', 'Add item title', 'Add Menu Item'),
        ('menuManagement.editItem', 'menu', 'Edit item title', 'Edit Item'),
        ('menuManagement.createItem', 'menu', 'Create item button', 'Create Item'),
        ('menuManagement.updateItem', 'menu', 'Update item button', 'Update Item')
    ON CONFLICT (key) DO NOTHING;

    -- Now insert/update all Arabic translations
    INSERT INTO translations (lang_code, key_id, value)
    SELECT
        _lang_code,
        tk.id,
        v.arabic_value
    FROM (
        -- Customers
        VALUES
            ('customers.added', 'تمت إضافة العميل'),
            ('customers.addError', 'فشل في إضافة العميل'),
            ('customers.addNewCustomer', 'إضافة عميل جديد'),
            ('customers.bookingsLoadError', 'فشل في تحميل الحجوزات'),
            ('customers.colCustomer', 'العميل'),
            ('customers.colLastVisit', 'آخر زيارة'),
            ('customers.colLoyalty', 'الولاء'),
            ('customers.colMemberSince', 'عضو منذ'),
            ('customers.colOrders', 'الطلبات'),
            ('customers.colReservations', 'الحجوزات'),
            ('customers.colTotalSpent', 'إجمالي الإنفاق'),
            ('customers.customers', 'العملاء'),
            ('customers.fullNamePlaceholder', 'الاسم الكامل *'),
            ('customers.loadError', 'فشل في تحميل العملاء'),
            ('customers.markedOptIn', 'أعيد اشتراك العميل في التسويق'),
            ('customers.markedOptOut', 'قام العميل بإلغاء الاشتراك في التسويق'),
            ('customers.marketingPrefs', 'رسائل التسويق'),
            ('customers.memberSince', 'عضو منذ'),
            ('customers.noContactDetails', 'لا توجد تفاصيل اتصال في السجل'),
            ('customers.noCustomersSub', 'يظهر العملاء عندما يتفاعلون مع الذكاء الاصطناعي أو عندما تضيفهم يدوياً'),
            ('customers.noOrders', 'لم يتم العثور على طلبات'),
            ('customers.noReservations', 'لم يتم العثور على حجوزات'),
            ('customers.optedIn', 'مشترك'),
            ('customers.optedOut', 'غير مشترك'),
            ('customers.optOut', 'إلغاء الاشتراك'),
            ('customers.orderNum', 'طلب #'),
            ('customers.preferences', 'التفضيلات'),
            ('customers.pts', 'نقطة'),
            ('customers.reSubscribe', 'إعادة الاشتراك'),
            ('customers.searchPlaceholder', 'البحث بالاسم أو البريد الإلكتروني أو الهاتف...'),
            ('customers.specialRequests', 'طلبات خاصة'),
            ('customers.statAvgOrder', 'متوسط الطلب'),
            ('customers.statLastVisit', 'آخر زيارة'),
            ('customers.statReservations', 'الحجوزات'),
            ('customers.statTotalOrders', 'إجمالي الطلبات'),
            ('customers.statTotalSpent', 'إجمالي الإنفاق'),
            ('customers.statTotalVisits', 'إجمالي الزيارات'),
            ('customers.tags', 'العلامات'),
            ('customers.party', 'المجموعة'),
            ('customers.items', 'العناصر'),

            -- Staff
            ('staff.save', 'حفظ'),
            ('staff.saving', 'جارٍ الحفظ...'),
            ('staff.cancel', 'إلغاء'),
            ('staff.close', 'إغلاق'),
            ('staff.edit', 'تعديل'),
            ('staff.delete', 'حذف'),
            ('staff.newRole', 'دور جديد'),
            ('staff.addStaff', 'إضافة موظف'),
            ('staff.addStaffMember', 'إضافة عضو في الفريق'),
            ('staff.addNewRole', 'إضافة دور جديد'),
            ('staff.customPermissions', 'صلاحيات مخصصة'),
            ('staff.customRoleName', '{{name}} (مخصص)'),
            ('staff.defaultRoleName', 'موظف'),
            ('staff.deleteRole', 'حذف الدور'),
            ('staff.editRole', 'تعديل الدور: {{name}}'),
            ('staff.editRoleTitle', 'تعديل الدور'),
            ('staff.editStaff', 'تعديل: {{name}}'),
            ('staff.emailLabel', 'البريد الإلكتروني'),
            ('staff.errors.deleteRoleFailed', 'فشل في حذف الدور'),
            ('staff.errors.deleteStaff', 'فشل في حذف الموظف:'),
            ('staff.errors.deleteSystemRole', 'لا يمكن حذف أدوار النظام'),
            ('staff.errors.loadRoles', 'فشل في تحميل الأدوار:'),
            ('staff.errors.loadStaff', 'فشل في تحميل الموظفين:'),
            ('staff.errors.nameRequired', 'الاسم مطلوب'),
            ('staff.errors.roleNameRequired', 'اسم الدور مطلوب'),
            ('staff.errors.saveRoleFailed', 'فشل في حفظ الدور'),
            ('staff.errors.saveStaffFailed', 'فشل في حفظ الموظف'),
            ('staff.errors.updateStaff', 'فشل في تحديث الموظف:'),
            ('staff.fullAccessBadge', 'صلاحية كاملة'),
            ('staff.groups.aiAgent', 'الوكيل الذكي'),
            ('staff.groups.channels', 'القنوات'),
            ('staff.groups.growth', 'النمو'),
            ('staff.groups.manage', 'الإدارة'),
            ('staff.groups.operations', 'العمليات'),
            ('staff.groups.overview', 'نظرة عامة'),
            ('staff.groups.restaurant', 'المتجر'),
            ('staff.matrix.section', 'القسم'),
            ('staff.member', 'عضو'),
            ('staff.members', 'أعضاء'),
            ('staff.noPermissions', 'لم يتم تعيين صلاحيات'),
            ('staff.noRoles', 'لا توجد أدوار بعد'),
            ('staff.noStaffMembers', 'لا يوجد أعضاء في الفريق بعد'),
            ('staff.roleCreated', 'تم إنشاء الدور'),
            ('staff.roleDeleted', 'تم حذف الدور'),
            ('staff.rolePermissionsDesc', 'الصلاحيات مملوءة مسبقاً من دور {{name}} — يمكنك تخصيصها أدناه.'),
            ('staff.roleUpdated', 'تم تحديث الدور'),
            ('staff.crud.create', 'إنشاء'),
            ('staff.crud.read', 'قراءة'),
            ('staff.crud.update', 'تحديث'),
            ('staff.crud.delete', 'حذف'),
            ('staff.crud.createAbbr', 'إ'),
            ('staff.crud.readAbbr', 'ق'),
            ('staff.crud.updateAbbr', 'ح'),
            ('staff.crud.deleteAbbr', 'حذف'),
            ('staff.sections.ai_config', 'إعداد الذكاء الاصطناعي'),
            ('staff.sections.analytics', 'التحليلات'),
            ('staff.sections.branches', 'الفروع'),
            ('staff.sections.chat_widget', 'أداة الدردشة'),
            ('staff.sections.conversations', 'المحادثات'),
            ('staff.sections.coupons', 'القسائم'),
            ('staff.sections.customers', 'العملاء'),
            ('staff.sections.dashboard', 'لوحة القيادة'),
            ('staff.sections.gift_cards', 'بطاقات الهدايا'),
            ('staff.sections.knowledge_base', 'قاعدة المعرفة'),
            ('staff.sections.loyalty', 'برنامج الولاء'),
            ('staff.sections.marketing', 'التسويق'),
            ('staff.sections.menu', 'القائمة'),
            ('staff.sections.orders', 'الطلبات'),
            ('staff.sections.reservations', 'الحجوزات'),
            ('staff.sections.staff', 'الموظفون'),
            ('staff.sections.storefront', 'واجهة المتجر بالرمز'),
            ('staff.sections.telephone', 'الهاتف'),
            ('staff.sections.whatsapp', 'واتساب'),
            ('staff.sections.settings', 'الإعدادات'),
            ('staff.placeholders.email', 'عنوان البريد الإلكتروني'),
            ('staff.placeholders.fullName', 'الاسم الكامل'),
            ('staff.placeholders.roleDescription', 'وصف قصير لهذا الدور'),
            ('staff.placeholders.roleName', 'مثال: أمين الصندوق'),
            ('staff.placeholders.searchStaff', 'البحث في الموظفين...'),
            ('staff.permissionsLegend', 'إ = إنشاء  ق = قراءة  ح = تحديث  حذف = حذف'),
            ('staff.permissionsTitle', 'الصلاحيات'),
            ('staff.resetToDefaults', 'إعادة تعيين إلى افتراضيات {{name}}'),
            ('staff.roleNameLabel', 'اسم الدور *'),
            ('staff.systemBadge', 'النظام'),
            ('staff.systemRole', 'نظام'),
            ('staff.table.lastActive', 'آخر نشاط'),
            ('staff.table.permissions', 'الصلاحيات'),
            ('staff.table.role', 'الدور'),
            ('staff.table.staffMember', 'عضو الفريق'),
            ('staff.table.status', 'الحالة'),
            ('staff.tabs.members', 'أعضاء الفريق'),
            ('staff.tabs.roles', 'الأدوار والصلاحيات'),
            ('staff.status.inactive', 'غير نشط'),
            ('staff.status.active', 'نشط'),
            ('staff.statusUpdated', 'تم تحديث حالة الموظف'),
            ('staff.staffAdded', 'تم إضافة عضو الفريق'),
            ('staff.staffRemoved', 'تم إزالة عضو الفريق'),
            ('staff.staffUpdated', 'تم تحديث عضو الفريق'),
            ('staff.descriptionLabel', 'الوصف'),
            ('staff.fullNameLabel', 'الاسم الكامل *'),
            ('staff.roleLabel', 'الدور'),
            ('staff.noRoleAssigned', 'لم يتم تعيين دور'),
            ('staff.ownerRoleDesc', 'دور المالك للقراءة فقط — جميع الصلاحيات دائماً مفعلة'),
            ('staff.viewRole', 'عرض الدور'),
            ('staff.addFirstMember', 'أضف أول عضو في فريقك للبدء'),
            ('staff.createFirstRole', 'أنشئ دوراً لتعريف مجموعات الصلاحيات لموظفيك'),
            ('staff.pageTitle', 'الموظفون والفريق'),
            ('staff.pageSubtitle', 'إدارة الأدوار والصلاحيات وحسابات الموظفين'),

            -- Menu Management
            ('menuManagement.itemCreated', 'تم إنشاء العنصر'),
            ('menuManagement.itemUpdated', 'تم تحديث العنصر'),
            ('menuManagement.itemNameRequired', 'اسم العنصر مطلوب'),
            ('menuManagement.saveFailed', 'فشل الحفظ'),
            ('menuManagement.itemNameStar', 'اسم العنصر *'),
            ('menuManagement.itemNamePlaceholder', 'مثال: زبدة الدجاج'),
            ('menuManagement.priceLabel', 'السعر (₹)'),
            ('menuManagement.category', 'الفئة'),
            ('menuManagement.uncategorized', 'غير مصنف'),
            ('menuManagement.description', 'الوصف'),
            ('menuManagement.descriptionPlaceholder', 'صف الطبق...'),
            ('menuManagement.itemImage', 'صورة العنصر'),
            ('menuManagement.upload', 'رفع'),
            ('menuManagement.imageUrlPlaceholder', 'أو الصق الرابط...'),
            ('menuManagement.properties', 'الخصائص'),
            ('menuManagement.vegetarian', 'نباتي'),
            ('menuManagement.spice', 'التوابل'),
            ('menuManagement.spiceNo', 'بدون توابل'),
            ('menuManagement.spiceMild', 'خفيف'),
            ('menuManagement.spiceMedium', 'متوسط'),
            ('menuManagement.spiceHot', 'حار'),
            ('menuManagement.prepTime', 'وقت التحضير (دقيقة)'),
            ('menuManagement.calories', 'السعرات الحرارية (سعرة)'),
            ('menuManagement.stock', 'المخزون'),
            ('menuManagement.inStock', 'متوفر'),
            ('menuManagement.stockCount', 'كمية المخزون'),
            ('menuManagement.unlimited', 'غير محدود'),
            ('menuManagement.stockCountHelp', 'اتركه فارغاً لغير محدود. ينقص تلقائياً مع كل طلب.'),
            ('menuManagement.lowStockThreshold', 'حد المخزون المنخفض'),
            ('menuManagement.disabled', 'معطل'),
            ('menuManagement.lowStockThresholdHelp', 'تنبيه بالبريد الإلكتروني + لوحة القيادة عندما ينخفض المخزون إلى هذه القيمة. اتركه فارغاً للتعطيل.'),
            ('menuManagement.dailyResetCount', 'هدف إعادة التعيين اليومي'),
            ('menuManagement.dailyResetCountHelp', 'في منتصف الليل المحلي، يعيد المخزون تعيين نفسه إلى هذا الرقم. اتركه فارغاً للتعطيل.'),
            ('menuManagement.thresholdAboveReset', 'يجب أن يكون حد المخزون المنخفض على الأقل مساوياً لهدف إعادة التعيين اليومي.'),
            ('menuManagement.schedule', 'الجدول'),
            ('menuManagement.scheduleHelp', 'حدد متى يمكن طلب هذا العنصر. الأوقات حسب توقيت الفرع.'),
            ('menuManagement.branchAvailability', 'توفر الفرع'),
            ('menuManagement.modifierGroups', 'مجموعات المعدلات'),
            ('menuManagement.addGroup', 'إضافة مجموعة'),
            ('menuManagement.groupNamePlaceholder', 'اسم المجموعة (مثال: اختر الحجم، الإضافات)'),
            ('menuManagement.radioPickOne', 'راديو (اختر واحداً)'),
            ('menuManagement.checkboxPickMany', 'مربع اختيار (اختر عدداً)'),
            ('menuManagement.minSelections', 'الحد الأدنى للاختيارات'),
            ('menuManagement.maxSelections', 'الحد الأقصى للاختيارات'),
            ('menuManagement.noLimit', 'بدون حد'),
            ('menuManagement.requiredSelection', 'اختيار مطلوب'),
            ('menuManagement.create', 'إنشاء'),
            ('menuManagement.noModifierGroups', 'لا توجد مجموعات معدلات بعد. أضف أحجاماً أو إضافات أو جوانب.'),
            ('menuManagement.radio', 'راديو'),
            ('menuManagement.checkbox', 'مربع اختيار'),
            ('menuManagement.min', 'الحد الأدنى'),
            ('menuManagement.max', 'الحد الأقصى'),
            ('menuManagement.required', 'مطلوب'),
            ('menuManagement.priceDeltaPlaceholder', '₹ فرق'),
            ('menuManagement.def', 'افتراضي'),
            ('menuManagement.defBadge', 'افتراضي'),
            ('menuManagement.free', 'مجاني'),
            ('menuManagement.optionName', 'اسم الخيار'),
            ('menuManagement.extraPrice', '₹ إضافي'),
            ('menuManagement.saveItemFirstToAddModifierGroups', 'احفظ العنصر أولاً لإضافة مجموعات المعدلات (أحجام، إضافات، جوانب).'),
            ('menuManagement.addItem', 'إضافة عنصر في القائمة'),
            ('menuManagement.editItem', 'تعديل العنصر'),
            ('menuManagement.createItem', 'إنشاء عنصر'),
            ('menuManagement.updateItem', 'تحديث العنصر')
    ) AS v(key, arabic_value)
    JOIN translation_keys tk ON tk.key = v.key
    ON CONFLICT (lang_code, key_id) DO UPDATE SET value = EXCLUDED.value;

    RAISE NOTICE 'Missing Arabic translations added successfully';
END $$;
