import { emoji } from '../../../core/theme.js';

// Puzzle theme definitions with Arabic names and icons
const THEME_EMOJI_MAP = {
  'sacrifice': ['theme_sacrifice', '💥'],
  'fork': ['theme_fork', '🔱'],
  'pin': ['theme_pin', '📌'],
  'back-rank': ['theme_castle', '🏰'],
  'promotion': ['theme_crown', '👑'],
};

export const THEMES = [
  { key: 'mate', name: 'كش مات', nameEn: 'Checkmate', icon: '♚' },
  { key: 'short', name: 'قصيرة', nameEn: 'Short', icon: '⚡' },
  { key: 'long', name: 'طويلة', nameEn: 'Long', icon: '📏' },
  { key: 'sacrifice', name: 'تضحية', nameEn: 'Sacrifice', icon: '💥' },
  { key: 'fork', name: 'شوكة', nameEn: 'Fork', icon: '🔱' },
  { key: 'pin', name: 'تثبيت', nameEn: 'Pin', icon: '📌' },
  { key: 'skewer', name: 'سيخ', nameEn: 'Skewer', icon: '🗡️' },
  { key: 'back-rank', name: 'الصف الأخير', nameEn: 'Back Rank', icon: '🏰' },
  { key: 'discovery', name: 'كشف', nameEn: 'Discovered Attack', icon: '👁️' },
  { key: 'double-check', name: 'كشف مزدوج', nameEn: 'Double Check', icon: '⚔️' },
  { key: 'attack', name: 'هجوم', nameEn: 'Attack', icon: '⚔️' },
  { key: 'defense', name: 'دفاع', nameEn: 'Defense', icon: '🛡️' },
  { key: 'endgame', name: 'نهايات', nameEn: 'Endgame', icon: '🏁' },
  { key: 'promotion', name: 'ترقية', nameEn: 'Promotion', icon: '👑' },
  { key: 'trapped', name: 'محاصرة', nameEn: 'Trapped Piece', icon: '🪤' },
  { key: 'zugzwang', name: 'تسوغزوانغ', nameEn: 'Zugzwang', icon: '⏳' },
];

export function getThemeName(key, lang = 'ar') {
  const theme = THEMES.find(t => t.key === key);
  if (!theme) return key;
  return lang === 'ar' ? theme.name : theme.nameEn;
}

export function getThemeIcon(key, size = 16) {
  const mapping = THEME_EMOJI_MAP[key];
  if (mapping) return emoji(mapping[0], mapping[1], size);
  const theme = THEMES.find(t => t.key === key);
  return theme?.icon || '♟';
}

export function parseThemes(themesStr) {
  if (!themesStr) return [];
  return themesStr.split(',').map(t => t.trim()).filter(Boolean);
}
