// Persian number and price formatters for ZanaShop

export function formatPrice(amount: number): string {
  if (amount === undefined || amount === null || isNaN(amount)) return '۰ تومان';
  return `${amount.toLocaleString('fa-IR')} تومان`;
}

export function toPersianDigits(n: number | string): string {
  if (n === undefined || n === null) return '';
  const persianDigits = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
  return n.toString().replace(/\d/g, (x) => persianDigits[parseInt(x, 10)]);
}

export function formatDate(dateString: string): string {
  if (!dateString) return '';
  try {
    const d = new Date(dateString);
    return new Intl.DateTimeFormat('fa-IR', {
      year: 'numeric',
      month: 'long',
      day: 'numeric',
      hour: '2-digit',
      minute: '2-digit',
    }).format(d);
  } catch {
    return dateString;
  }
}

export function getOrderStatusBadge(status: string): { label: string; bg: string; text: string; border: string } {
  switch (status) {
    case 'completed':
      return { label: 'تکمیل شده و تحویل داده شد', bg: 'bg-emerald-950/60', text: 'text-emerald-400', border: 'border-emerald-500/30' };
    case 'processing':
      return { label: 'در حال پردازش و آماده‌سازی', bg: 'bg-purple-950/60', text: 'text-purple-400', border: 'border-purple-500/30' };
    case 'paid':
      return { label: 'پرداخت موفق', bg: 'bg-blue-950/60', text: 'text-blue-400', border: 'border-blue-500/30' };
    case 'pending_payment':
      return { label: 'در انتظار پرداخت', bg: 'bg-amber-950/60', text: 'text-amber-400', border: 'border-amber-500/30' };
    case 'cancelled':
      return { label: 'لغو شده', bg: 'bg-red-950/60', text: 'text-red-400', border: 'border-red-500/30' };
    default:
      return { label: status, bg: 'bg-zinc-900', text: 'text-zinc-400', border: 'border-zinc-700' };
  }
}
