// profile-data.jsx — i18n strings + mock state for the Profile module (پروفایل).
//
// Sprint v1.7 · Profile. Source-of-truth for everything the
// `profile-pieces.jsx` primitives and `profile-app.jsx` canvas render.
// Pure data + pure factories — no DOM, no React, no side effects.
//
// Conventions (locked):
//   • All strings live in PROF_I18N[fa|en|ar]. No hard-coded strings in
//     pieces / app. Full key parity across all three locales.
//   • All numbers go through `toLocaleDigits(num, locale)` at the render
//     layer (this file only ever returns raw numbers).
//   • Token palette reuses canonical tokens.css variables — no new CSS
//     custom properties introduced anywhere in this module.
//   • Mock data mirrors the wireframe values from Wireframes §S14 / S38 / S39
//     exactly so artboards render recognisable numbers without modification.
//
// Shape exported on window:
//   PROF_I18N         — { fa, en, ar } string bundle (master keys)
//   PROF_USER         — mock current-user record (level/XP/coins/lineups/
//                       packs/cards/favoriteTeam/email/phone/avatarSrc)
//   PROF_MENU_ITEMS   — 5-item menu array ({ key, icon, danger? })
//   PROF_VERSION      — app version string '1.0.0'
//
//   getXPProgress(user)          → 0..1  (progress within current level)
//   resolveAvatarPalette(seed)   → { from, to }  (gradient for initials avatar)


// ─── i18n ──────────────────────────────────────────────────────────────────
const PROF_I18N = {
  fa: {
    // ── Chrome ─────────────────────────────────────────────────────────────
    pageTitle:          'پروفایل',
    pageSub:            'حساب کاربری و آمار شما',
    appBarBack:         'برگشت',
    editPill:           'ویرایش',

    // ── Hero ────────────────────────────────────────────────────────────────
    levelPill:          (n)         => `سطح ${n}`,
    xpProgress:         (cur, max)  => `XP ${cur} / ${max}`,

    // ── Stat cards (6 — grid 2-column) ─────────────────────────────────────
    statLevel:          'سطح',
    statTotalXP:        'کل XP',
    statTotalCoins:     'کل سکه کسب‌شده',
    statLineupsCount:   'ترکیب‌های ثبت‌شده',
    statPacksOpened:    'پک‌های بازشده',
    statActiveCards:    'کارت‌های فعال',

    // ── Menu section ────────────────────────────────────────────────────────
    menuSection:        'منو',
    menuLineupHistory:  'تاریخچه ترکیب‌ها',
    menuSettings:       'تنظیمات',
    menuNotifications:  'اعلان‌ها',
    menuAbout:          'درباره ما',
    menuLogout:         'خروج',

    // ── Footer ──────────────────────────────────────────────────────────────
    version:            (v)         => `نسخه ${v}`,

    // ── Edit Profile (S38) ──────────────────────────────────────────────────
    editTitle:          'ویرایش پروفایل',
    editSave:           'ذخیره',
    editChangeAvatar:   'تغییر آواتار',
    editCameraAria:     'تغییر عکس پروفایل',
    editFieldUsername:  'نام کاربری',
    editFieldDisplayName:'نام نمایشی',
    editFieldFavoriteTeam:'تیم مورد علاقه',
    editFieldEmail:     'ایمیل',
    editFieldPhone:     'موبایل',
    editEmailAction:    'تغییر',
    editPhoneVerified:  '✓ تأیید شده',
    editDeleteAccount:  'حذف حساب کاربری',
    editDeleteAria:     'حذف دائمی حساب کاربری',

    // ── Logout confirm modal (S39) ──────────────────────────────────────────
    logoutTitle:        'خروج از حساب؟',
    logoutBody:         'می‌تونی هر وقت برگردی. کارت‌ها، XP، سکه و رتبه‌ت حفظ می‌شن.',
    logoutCancel:       'انصراف',
    logoutConfirm:      'خروج',
    logoutIconAria:     'خروج از سیستم',

    // ── Generic / shared ────────────────────────────────────────────────────
    closeAria:          'بستن',
    coin:               'سکه',
    xpShort:            'XP',
  },

  en: {
    // ── Chrome ─────────────────────────────────────────────────────────────
    pageTitle:          'Profile',
    pageSub:            'Your account and stats',
    appBarBack:         'Back',
    editPill:           'Edit',

    // ── Hero ────────────────────────────────────────────────────────────────
    levelPill:          (n)         => `Level ${n}`,
    xpProgress:         (cur, max)  => `XP ${cur} / ${max}`,

    // ── Stat cards ──────────────────────────────────────────────────────────
    statLevel:          'Level',
    statTotalXP:        'Total XP',
    statTotalCoins:     'Total Coins Earned',
    statLineupsCount:   'Lineups Submitted',
    statPacksOpened:    'Packs Opened',
    statActiveCards:    'Active Cards',

    // ── Menu section ────────────────────────────────────────────────────────
    menuSection:        'Menu',
    menuLineupHistory:  'Lineup History',
    menuSettings:       'Settings',
    menuNotifications:  'Notifications',
    menuAbout:          'About Us',
    menuLogout:         'Sign Out',

    // ── Footer ──────────────────────────────────────────────────────────────
    version:            (v)         => `Version ${v}`,

    // ── Edit Profile (S38) ──────────────────────────────────────────────────
    editTitle:          'Edit Profile',
    editSave:           'Save',
    editChangeAvatar:   'Change Avatar',
    editCameraAria:     'Change profile photo',
    editFieldUsername:  'Username',
    editFieldDisplayName:'Display Name',
    editFieldFavoriteTeam:'Favorite Team',
    editFieldEmail:     'Email',
    editFieldPhone:     'Mobile',
    editEmailAction:    'Change',
    editPhoneVerified:  '✓ Verified',
    editDeleteAccount:  'Delete Account',
    editDeleteAria:     'Permanently delete account',

    // ── Logout confirm modal (S39) ──────────────────────────────────────────
    logoutTitle:        'Sign Out?',
    logoutBody:         'You can always come back. Your cards, XP, coins, and rank will be saved.',
    logoutCancel:       'Cancel',
    logoutConfirm:      'Sign Out',
    logoutIconAria:     'Sign out of account',

    // ── Generic / shared ────────────────────────────────────────────────────
    closeAria:          'Close',
    coin:               'coin',
    xpShort:            'XP',
  },

  ar: {
    // ── Chrome ─────────────────────────────────────────────────────────────
    pageTitle:          'الملف الشخصي',
    pageSub:            'حسابك وإحصائياتك',
    appBarBack:         'رجوع',
    editPill:           'تعديل',

    // ── Hero ────────────────────────────────────────────────────────────────
    levelPill:          (n)         => `مستوى ${n}`,
    xpProgress:         (cur, max)  => `XP ${cur} / ${max}`,

    // ── Stat cards ──────────────────────────────────────────────────────────
    statLevel:          'المستوى',
    statTotalXP:        'مجموع XP',
    statTotalCoins:     'مجموع العملات المكتسبة',
    statLineupsCount:   'التشكيلات المسجلة',
    statPacksOpened:    'الحزم المفتوحة',
    statActiveCards:    'البطاقات النشطة',

    // ── Menu section ────────────────────────────────────────────────────────
    menuSection:        'القائمة',
    menuLineupHistory:  'تاريخ التشكيلات',
    menuSettings:       'الإعدادات',
    menuNotifications:  'الإشعارات',
    menuAbout:          'عن التطبيق',
    menuLogout:         'تسجيل الخروج',

    // ── Footer ──────────────────────────────────────────────────────────────
    version:            (v)         => `الإصدار ${v}`,

    // ── Edit Profile (S38) ──────────────────────────────────────────────────
    editTitle:          'تعديل الملف الشخصي',
    editSave:           'حفظ',
    editChangeAvatar:   'تغيير الصورة الرمزية',
    editCameraAria:     'تغيير صورة الملف الشخصي',
    editFieldUsername:  'اسم المستخدم',
    editFieldDisplayName:'الاسم المعروض',
    editFieldFavoriteTeam:'الفريق المفضل',
    editFieldEmail:     'البريد الإلكتروني',
    editFieldPhone:     'الجوال',
    editEmailAction:    'تغيير',
    editPhoneVerified:  '✓ موثّق',
    editDeleteAccount:  'حذف الحساب',
    editDeleteAria:     'حذف الحساب نهائياً',

    // ── Logout confirm modal (S39) ──────────────────────────────────────────
    logoutTitle:        'تسجيل الخروج؟',
    logoutBody:         'يمكنك العودة في أي وقت. ستبقى بطاقاتك وXP وعملاتك وترتيبك محفوظة.',
    logoutCancel:       'إلغاء',
    logoutConfirm:      'خروج',
    logoutIconAria:     'تسجيل الخروج من الحساب',

    // ── Generic / shared ────────────────────────────────────────────────────
    closeAria:          'إغلاق',
    coin:               'عملة',
    xpShort:            'XP',
  },
};


// ─── Current-user mock ─────────────────────────────────────────────────────
// Values mirror Wireframes §S14 exactly so artboards are recognisable.
// emailMasked is locale-neutral Latin script (the mask is the same in every
// locale). phoneMasked adapts digits per locale via the three-key triplet.
const PROF_USER = {
  id:           'u-current',

  // Tri-lingual display name (switches with locale Tweak).
  displayName:  { fa: 'کیوان احمدی',  en: 'Keyvan Ahmadi',  ar: 'كيفان أحمدي' },
  username:     '@keyvan',            // always Latin script — no locale variant

  // Level & XP — Wireframe §S14: سطح ۲۴, XP ۴۵٬۲۰۰ / ۵۰٬۰۰۰ (bar ≈ 90%)
  level:        24,
  totalXP:      45200,
  nextLevelXP:  50000,

  // Aggregate counters — Wireframe §S14 stat grid
  totalCoins:   89320,
  lineupsCount: 42,
  packsOpened:  18,
  activeCards:  24,

  // Favorite team — TeamCrest primitive (homehub-pieces.jsx) reads `code`
  // + `brandColor`; `name` is used for the read-only edit field label.
  favoriteTeam: {
    name:       { fa: 'پرسپولیس',    en: 'Persepolis',   ar: 'برسبوليس' },
    code:       'PER',
    brandColor: '#D72B2B',            // canonical team red (design-system)
  },

  // Masked credentials — Wireframe §S38
  // emailMasked is always Latin (masks never need digit localisation).
  emailMasked:  'key***@gmail.com',
  // phoneMasked uses locale-native digits for the visible portion.
  phoneMasked:  { fa: '۰۹۱۲...۴۵۶',  en: '0912...456',   ar: '٠٩١٢...٤٥٦' },

  // Avatar — null → initials fallback rendered by ProfileHero (pieces).
  // Set to a real image path when assets are ready.
  avatarSrc:    null,
  avatarInitial:{ fa: 'ک',           en: 'K',            ar: 'ك' },
  avatarSeed:   'keyvan',             // deterministic palette seed

  joinDate:     new Date('2024-08-01'),
};


// ─── Menu items ────────────────────────────────────────────────────────────
// `icon` keys are resolved by PfIcon in profile-pieces.jsx (which wraps
// HHIcon and adds the three profile-specific glyphs: settings / info /
// logout). No new entries should be added without a corresponding icon case.
const PROF_MENU_ITEMS = [
  { key: 'lineupHistory',  icon: 'lineup'        },
  { key: 'settings',       icon: 'settings'      },
  { key: 'notifications',  icon: 'bell'          },
  { key: 'about',          icon: 'info'          },
  { key: 'logout',         icon: 'logout', danger: true },
];


// ─── App version ───────────────────────────────────────────────────────────
const PROF_VERSION = '1.0.0';


// ─── Helpers ───────────────────────────────────────────────────────────────

// Returns a 0..1 fraction representing progress toward the next level
// threshold. Mirrors the wireframe §S14 where the bar shows totalXP /
// nextLevelXP directly (e.g. ۴۵٬۲۰۰ / ۵۰٬۰۰۰ ≈ 90 % fill).
function getXPProgress(user) {
  if (!user || typeof user.totalXP !== 'number' || !user.nextLevelXP) return 0;
  return Math.min(1, Math.max(0, user.totalXP / user.nextLevelXP));
}


// Returns a gradient pair { from, to } for the initials avatar.
// Deterministic: same seed always returns the same palette — safe to use
// inside render without storing state.
function resolveAvatarPalette(seed = '') {
  const PALETTES = [
    { from: '#7163D9', to: '#534AB7' },   // accent purple  (brand-first)
    { from: '#34D399', to: '#059669' },   // success green
    { from: '#60A5FA', to: '#2563EB' },   // info blue
    { from: '#FCD34D', to: '#D97706' },   // gold / bronze
    { from: '#FB7185', to: '#E11D48' },   // danger rose
    { from: '#A78BFA', to: '#7C3AED' },   // violet
    { from: '#93C5FD', to: '#3B82F6' },   // platinum-blue
  ];
  let h = 0;
  for (let i = 0; i < seed.length; i++) {
    h = ((h * 31) + seed.charCodeAt(i)) >>> 0;
  }
  return PALETTES[h % PALETTES.length];
}


// ─── Exports ───────────────────────────────────────────────────────────────
window.PROF_I18N         = PROF_I18N;
window.PROF_USER         = PROF_USER;
window.PROF_MENU_ITEMS   = PROF_MENU_ITEMS;
window.PROF_VERSION      = PROF_VERSION;
window.getXPProgress     = getXPProgress;
window.resolveAvatarPalette = resolveAvatarPalette;
