-- =====================================================================
-- Orders + Customers lists: repeat-customer badge next to the name
-- (resources/views/backend/customer/partials/order_history_badge.blade.php)
--
-- No schema change needed. Same strings as migration
-- 2026_09_29_000004_seed_repeat_customer_badge_translations.
-- Re-running the file changes nothing (only missing keys are inserted).
-- After running: php artisan cache:clear (translations are cached).
-- =====================================================================

SET NAMES utf8mb4;

INSERT INTO `translations` (`lang`, `lang_key`, `lang_value`, `created_at`, `updated_at`)
SELECT s.lang, s.lang_key, s.lang_value, NOW(), NOW()
FROM (
        SELECT 'en' AS lang, 'new_customer' AS lang_key, 'New customer' AS lang_value
        UNION ALL SELECT 'ar', 'new_customer', 'عميل جديد'
        UNION ALL SELECT 'sa', 'new_customer', 'عميل جديد'
        UNION ALL SELECT 'en', 'repeat_customer', 'Repeat customer'
        UNION ALL SELECT 'ar', 'repeat_customer', 'زبون عائد'
        UNION ALL SELECT 'sa', 'repeat_customer', 'زبون عائد'
        UNION ALL SELECT 'en', 'loyal_customer', 'Loyal customer'
        UNION ALL SELECT 'ar', 'loyal_customer', 'زبون دائم'
        UNION ALL SELECT 'sa', 'loyal_customer', 'زبون دائم'
        UNION ALL SELECT 'en', 'previous_orders', 'Previous orders'
        UNION ALL SELECT 'ar', 'previous_orders', 'الطلبات السابقة'
        UNION ALL SELECT 'sa', 'previous_orders', 'الطلبات السابقة'
        UNION ALL SELECT 'en', 'first_order', 'First Order'
        UNION ALL SELECT 'ar', 'first_order', 'أول طلب'
        UNION ALL SELECT 'sa', 'first_order', 'أول طلب'
        UNION ALL SELECT 'en', 'orders_placed', 'Orders placed'
        UNION ALL SELECT 'ar', 'orders_placed', 'الطلبات'
        UNION ALL SELECT 'sa', 'orders_placed', 'الطلبات'
        UNION ALL SELECT 'en', 'no_orders_yet', 'No orders yet'
        UNION ALL SELECT 'ar', 'no_orders_yet', 'لا طلبات بعد'
        UNION ALL SELECT 'sa', 'no_orders_yet', 'لا طلبات بعد'
        UNION ALL SELECT 'en', 'fully_cancelled_orders', 'Fully cancelled orders'
        UNION ALL SELECT 'ar', 'fully_cancelled_orders', 'طلبات ملغاة بالكامل'
        UNION ALL SELECT 'sa', 'fully_cancelled_orders', 'طلبات ملغاة بالكامل'
        UNION ALL SELECT 'en', 'click_to_see_all_orders_of_this_customer', 'Click to see all orders of this customer'
        UNION ALL SELECT 'ar', 'click_to_see_all_orders_of_this_customer', 'اضغط لعرض كل طلبات هذا الزبون'
        UNION ALL SELECT 'sa', 'click_to_see_all_orders_of_this_customer', 'اضغط لعرض كل طلبات هذا الزبون'
) AS s
WHERE NOT EXISTS (
    SELECT 1 FROM `translations` t WHERE t.lang = s.lang AND t.lang_key = s.lang_key
);

-- ---------------------------------------------------------------------
-- OPTIONAL, not required by the badge: the badge reads orders by user_id
-- (one grouped query per page for the ~15 customers shown), and
-- orders.user_id has no index. While the table is a few thousand rows the
-- scan costs milliseconds; once it grows, run this once (MySQL has no
-- "IF NOT EXISTS" for indexes — check SHOW INDEX FROM orders first):
--
-- ALTER TABLE `orders` ADD INDEX `orders_user_id_index` (`user_id`);
-- ---------------------------------------------------------------------
