export const roleLabels: Record<string, string> = {
  super_admin: 'مدیر کل سامانه',
  owner: 'مدیر ارشد',
  principal: 'مدیر مدرسه',
  moaven: 'معاون',
  teacher: 'معلم',
  student: 'دانش‌آموز',
  support: 'پشتیبانی',
  finance: 'مالی',
};

export function roleLabel(roleKey: string | null | undefined): string {
  if (!roleKey) return '';
  return roleLabels[roleKey] ?? roleKey;
}

/** رنگ ثابت آواتار از روی نام — همیشه برای یک نام یکسان است. */
export function avatarColor(name: string): string {
  const palette = ['#0EA678', '#0EA5E9', '#8B5CF6', '#F59E0B', '#EF4444', '#14B8A6', '#6366F1', '#EC4899'];
  let hash = 0;
  for (let i = 0; i < name.length; i += 1) hash = (hash * 31 + name.charCodeAt(i)) | 0;
  return palette[Math.abs(hash) % palette.length];
}

export function initials(name: string): string {
  const parts = name.trim().split(/\s+/).filter(Boolean);
  if (parts.length === 0) return '؟';
  if (parts.length === 1) return parts[0].slice(0, 1);
  return parts[0].slice(0, 1) + parts[parts.length - 1].slice(0, 1);
}
