export const ADMIN_EMAIL = "competences.plus30@gmail.com";

export const STATUSES = [
  "new",
  "contacted",
  "documents_pending",
  "under_review",
  "committee_ready",
  "completed",
] as const;

export type ApplicationStatus = (typeof STATUSES)[number];

export const statusMeta: Record<
  ApplicationStatus,
  { label: string; short: string; progress: number; next: string }
> = {
  new: {
    label: "طلب جديد",
    short: "جديد",
    progress: 12,
    next: "التواصل الأولي وتأكيد المعلومات",
  },
  contacted: {
    label: "تم التواصل",
    short: "تم التواصل",
    progress: 28,
    next: "تحديد موعد التشخيص الأولي",
  },
  documents_pending: {
    label: "في انتظار الوثائق",
    short: "وثائق ناقصة",
    progress: 46,
    next: "استكمال الوثائق والأدلة المهنية",
  },
  under_review: {
    label: "الملف قيد الدراسة",
    short: "قيد الدراسة",
    progress: 68,
    next: "مراجعة الخبرة وربطها بالكفاءات",
  },
  committee_ready: {
    label: "التحضير للتقييم",
    short: "جاهز للتقييم",
    progress: 86,
    next: "التحضير للمقابلة ولجنة التقييم",
  },
  completed: {
    label: "تمت المواكبة",
    short: "مكتمل",
    progress: 100,
    next: "الاحتفاظ بنسخة الملف ومتابعة الخطوة الأكاديمية",
  },
};

export function isApplicationStatus(value: string): value is ApplicationStatus {
  return STATUSES.includes(value as ApplicationStatus);
}

export const defaultDocuments = [
  ["cv", "السيرة الذاتية المحدثة"],
  ["work_certificates", "شواهد العمل أو الخبرة"],
  ["job_description", "وصف المهام والمسؤوليات"],
  ["training", "الشهادات والدورات التكوينية"],
  ["projects", "أدلة المشاريع والإنجازات"],
] as const;

export function safeJsonArray(value: string | null | undefined): string[] {
  if (!value) return [];
  try {
    const parsed = JSON.parse(value);
    return Array.isArray(parsed) ? parsed.map(String) : [];
  } catch {
    return [];
  }
}

export function parseEmail(value: unknown) {
  const email = String(value ?? "").trim().toLowerCase();
  return /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email) ? email : "";
}
