// Specialty names and stage titles are taken from the approved panel-flow plan.

export type Lang = "fa" | "en" | "ar";

export type ServiceItem = { id: string; en: string };

export type Specialty = {
  id: string;
  groupId: "cosmetic" | "medical";
  fa: string;
  en: string;
  ar: string;
  services: ServiceItem[];
};

export type Stage = {
  id: string;
  kind: "path" | "side";
  order: number;
  title: Record<Lang, string>;
  sentence: Record<Lang, string>;
};

export const GROUPS = [
  {
    id: "cosmetic" as const,
    fa: "جراحی‌های زیبایی",
    en: "Cosmetic Surgeries",
    ar: "جراحات التجميل",
  },
  {
    id: "medical" as const,
    fa: "درمان‌های پزشکی",
    en: "Medical Treatments",
    ar: "العلاجات الطبية",
  },
];

export const SPECIALTIES: Specialty[] = [
  {
    id: "rhinoplasty",
    groupId: "cosmetic",
    fa: "رینوپلاستی",
    en: "Rhinoplasty",
    ar: "تجميل الأنف",
    services: [
      { id: "revision-rhinoplasty", en: "Revision rhinoplasty" },
      { id: "ethnic-rhinoplasty", en: "Ethnic rhinoplasty" },
      { id: "septoplasty", en: "Septoplasty" },
    ],
  },
  {
    id: "hair-transplant",
    groupId: "cosmetic",
    fa: "کاشت مو",
    en: "Hair transplant",
    ar: "زراعة الشعر",
    services: [
      { id: "eyebrow-transplant", en: "Eyebrow Transplant" },
      { id: "hair-line-transplant", en: "Hair line transplant" },
      { id: "beard-transplant", en: "Beard Transplant" },
    ],
  },
  {
    id: "non-surgical",
    groupId: "cosmetic",
    fa: "اقدام غیرجراحی",
    en: "None surgical Procedures",
    ar: "إجراءات غير جراحية",
    services: [
      { id: "prp", en: "Prp" },
      { id: "botox", en: "Botox" },
      { id: "mesotherapy", en: "Mesotherapy" },
      { id: "filler", en: "Filler" },
    ],
  },
  {
    id: "weight-loss",
    groupId: "cosmetic",
    fa: "جراحی کاهش وزن",
    en: "Weight loss surgery",
    ar: "جراحة إنقاص الوزن",
    services: [
      { id: "gastric-sleeve", en: "Gastric Sleeve" },
      { id: "gastric-bypass", en: "Gastric bypass" },
    ],
  },
  {
    id: "dentistry",
    groupId: "cosmetic",
    fa: "دندان‌پزشکی",
    en: "Dentistry",
    ar: "طب الأسنان",
    services: [
      { id: "dental-veneers", en: "Dental veneers" },
      { id: "dental-implant", en: "Dental implant" },
      { id: "tooth-whitening", en: "Tooth Whitening" },
      { id: "dentures", en: "Dentures" },
      { id: "orthodontics", en: "Orthodontics" },
      { id: "wisdom-teeth-removal", en: "Wisdom Teeth Removal" },
      { id: "tooth-extraction", en: "Tooth Extraction" },
    ],
  },
  {
    id: "body-contouring",
    groupId: "cosmetic",
    fa: "فرم‌دهی بدن",
    en: "Body contouring Surgery",
    ar: "نحت الجسم",
    services: [
      { id: "butt-lift", en: "Butt lift" },
      { id: "butt-implant", en: "Butt Implant" },
      { id: "bbl", en: "BBL" },
      { id: "breast-implant", en: "Breast implant" },
      { id: "breast-implant-revision", en: "Breast implant revision" },
      { id: "liposuction", en: "Liposuction" },
      { id: "breast-lift", en: "Breast lift" },
      { id: "mommy-makeover", en: "Mommy Makeover" },
      { id: "tummy-tuck", en: "Tummy Tuck" },
      { id: "breast-reduction", en: "Breast reduction" },
      { id: "arm-lift", en: "Arm lift" },
      { id: "thigh-lift", en: "Thigh lift" },
      { id: "gynecomastia", en: "Gynecomastia" },
      { id: "abdominal-etching", en: "Abdominal Etching" },
      { id: "inverted-nipple-correction", en: "Inverted nipple correction" },
      { id: "trans-gender-surgery", en: "Trans Gender Surgery" },
      { id: "labiaplasty", en: "Labiaplasty" },
    ],
  },
  {
    id: "facial-plastic",
    groupId: "cosmetic",
    fa: "پلاستیک صورت",
    en: "Facial plastic surgery",
    ar: "تجميل الوجه",
    services: [
      { id: "face-lift", en: "Face lift" },
      { id: "cat-eye", en: "Cat eye (Brow lift)" },
      { id: "forehead-reduction", en: "Forehead reduction" },
      { id: "central-lip-lift", en: "Central lip lift" },
      { id: "buccal-fat-removal", en: "Buccal fat removal" },
      { id: "genioplasty", en: "Genioplasty in Iran" },
      { id: "chin-implant", en: "Chin Implant" },
      { id: "otoplasty", en: "Ear Surgery (Otoplasty)" },
      { id: "facial-bone-reduction", en: "Facial Bone Reduction" },
      { id: "blepharoplasty", en: "Blepharoplasty" },
      { id: "facial-feminization", en: "Facial Feminization Surgery" },
      { id: "cleft-lip-palate", en: "Cleft Lip and Palate Repair" },
      { id: "reconstructive-burn", en: "Reconstructive Burn Surgery" },
    ],
  },
  {
    id: "fertility",
    groupId: "medical",
    fa: "درمان ناباروری",
    en: "Fertility Treatments",
    ar: "علاج العقم",
    services: [
      { id: "iui", en: "Intrauterine Insemination (IUI)" },
      { id: "surrogacy", en: "Surrogacy" },
      { id: "ivm", en: "In Vitro Maturation (IVM)" },
      { id: "ivf", en: "In vitro fertilization (IVF)" },
      { id: "icsi", en: "Intracytoplasmic Sperm Injection (ICSI)" },
      { id: "egg-donation", en: "Egg Donation In Iran" },
      { id: "sperm-donation", en: "Sperm Donation in Iran" },
    ],
  },
  {
    id: "lasik",
    groupId: "medical",
    fa: "لیزیک",
    en: "Lasik",
    ar: "الليزك",
    services: [],
  },
  {
    id: "organ-transplant",
    groupId: "medical",
    fa: "پیوند اعضا",
    en: "Organ Transplants",
    ar: "زراعة الأعضاء",
    services: [
      { id: "small-bowel-transplant", en: "Small Bowel Transplant" },
      { id: "kidney-transplant", en: "Kidney Transplant" },
      { id: "liver-transplant", en: "Liver Transplant" },
    ],
  },
  {
    id: "breast-cancer",
    groupId: "medical",
    fa: "سرطان پستان",
    en: "Breast Cancer",
    ar: "سرطان الثدي",
    services: [],
  },
];

export const STAGES: Stage[] = [
  {
    id: "file-created",
    kind: "path",
    order: 1,
    title: { fa: "پرونده تشکیل شد", en: "File opened", ar: "تم فتح الملف" },
    sentence: {
      fa: "پرونده شما نزد ایران هلث ساخته شد.",
      en: "Your file has been opened at Iran Health.",
      ar: "تم فتح ملفك لدى إيران هلث.",
    },
  },
  {
    id: "request-review",
    kind: "path",
    order: 2,
    title: {
      fa: "درخواست در حال بررسی است",
      en: "Request under review",
      ar: "الطلب قيد المراجعة",
    },
    sentence: {
      fa: "درخواست در حال بررسی است.",
      en: "Your request is under review.",
      ar: "طلبك قيد المراجعة.",
    },
  },
  {
    id: "plan-set",
    kind: "path",
    order: 3,
    title: {
      fa: "برنامه درمان هماهنگ شد",
      en: "Treatment plan arranged",
      ar: "تم تنسيق خطة العلاج",
    },
    sentence: {
      fa: "برنامه درمان هماهنگ شد.",
      en: "Your treatment plan has been arranged.",
      ar: "تم تنسيق خطة علاجك.",
    },
  },
  {
    id: "travel-ready",
    kind: "path",
    order: 4,
    title: {
      fa: "مقدمات سفر آماده شد",
      en: "Travel prepared",
      ar: "تم تجهيز مقدمات السفر",
    },
    sentence: {
      fa: "مقدمات سفر آماده شد.",
      en: "Your travel preparations are ready.",
      ar: "تم تجهيز مقدمات سفرك.",
    },
  },
  {
    id: "arrived-iran",
    kind: "path",
    order: 5,
    title: {
      fa: "ورود به ایران ثبت شد",
      en: "Arrival in Iran recorded",
      ar: "تم تسجيل الدخول إلى إيران",
    },
    sentence: {
      fa: "ورود به ایران ثبت شد.",
      en: "Your arrival in Iran has been recorded.",
      ar: "تم تسجيل دخولك إلى إيران.",
    },
  },
  {
    id: "visited-company",
    kind: "path",
    order: 6,
    title: {
      fa: "مراجعه به ایران هلث ثبت شد",
      en: "Visit to Iran Health recorded",
      ar: "تم تسجيل المراجعة لدى إيران هلث",
    },
    sentence: {
      fa: "مراجعه به ایران هلث ثبت شد.",
      en: "Your visit to Iran Health has been recorded.",
      ar: "تم تسجيل مراجعتك لدى إيران هلث.",
    },
  },
  {
    id: "admitted-center",
    kind: "path",
    order: 7,
    title: {
      fa: "پذیرش در مرکز درمانی ثبت شد",
      en: "Admission recorded",
      ar: "تم تسجيل القبول في المركز العلاجي",
    },
    sentence: {
      fa: "پذیرش در مرکز درمانی ثبت شد.",
      en: "Your admission at the medical center has been recorded.",
      ar: "تم تسجيل قبولك في المركز العلاجي.",
    },
  },
  {
    id: "service-underway",
    kind: "path",
    order: 8,
    title: {
      fa: "خدمت در حال انجام است",
      en: "Care in progress",
      ar: "الخدمة قيد التنفيذ",
    },
    sentence: {
      fa: "خدمت در حال انجام است.",
      en: "The care you requested is in progress.",
      ar: "الخدمة التي طلبتها قيد التنفيذ.",
    },
  },
  {
    id: "aftercare",
    kind: "path",
    order: 9,
    title: {
      fa: "مراقبت بعد از درمان شروع شد",
      en: "Aftercare started",
      ar: "بدأت الرعاية بعد العلاج",
    },
    sentence: {
      fa: "مراقبت بعد از درمان شروع شد.",
      en: "Aftercare has started.",
      ar: "بدأت الرعاية بعد علاجك.",
    },
  },
  {
    id: "departed-iran",
    kind: "path",
    order: 10,
    title: {
      fa: "خروج از ایران ثبت شد",
      en: "Departure from Iran recorded",
      ar: "تم تسجيل الخروج من إيران",
    },
    sentence: {
      fa: "خروج از ایران ثبت شد.",
      en: "Your departure from Iran has been recorded.",
      ar: "تم تسجيل خروجك من إيران.",
    },
  },
  {
    id: "journey-complete",
    kind: "path",
    order: 11,
    title: {
      fa: "مسیر این پرونده تمام شد",
      en: "Journey complete",
      ar: "اكتمل المسار",
    },
    sentence: {
      fa: "مسیر این پرونده تمام شد.",
      en: "This journey is complete.",
      ar: "اكتمل مسار هذا الملف.",
    },
  },
  {
    id: "waiting-patient",
    kind: "side",
    order: 0,
    title: {
      fa: "منتظر اقدام بیمار",
      en: "Waiting for the patient",
      ar: "بانتظار إجراء منك",
    },
    sentence: {
      fa: "برای ادامه مسیر، یک اقدام از سمت شما لازم است.",
      en: "A step from you is needed before the journey can continue.",
      ar: "قبل متابعة المسار، نحتاج إلى إجراء منك.",
    },
  },
  {
    id: "paused",
    kind: "side",
    order: 0,
    title: { fa: "توقف موقت", en: "Paused", ar: "توقف مؤقت" },
    sentence: {
      fa: "این مسیر موقتاً متوقف شده است.",
      en: "This journey is paused for now.",
      ar: "هذا المسار متوقف مؤقتاً.",
    },
  },
];

export function isLang(value: string): value is Lang {
  return value === "fa" || value === "en" || value === "ar";
}

export function groupById(id: string) {
  return GROUPS.find((group) => group.id === id) ?? null;
}

export function specialtyById(id: string) {
  return SPECIALTIES.find((item) => item.id === id) ?? null;
}

export function stageById(id: string) {
  return STAGES.find((item) => item.id === id) ?? null;
}

export function serviceChoices(specialty: Specialty): ServiceItem[] {
  if (specialty.services.length === 0) {
    return [{ id: specialty.id, en: specialty.en }];
  }
  return specialty.services;
}

export function serviceById(id: string): ServiceItem | null {
  for (const specialty of SPECIALTIES) {
    if (specialty.id === id && specialty.services.length === 0) {
      return { id: specialty.id, en: specialty.en };
    }
    const found = specialty.services.find((item) => item.id === id);
    if (found) return found;
  }
  return null;
}

export function serviceLabel(id: string) {
  return serviceById(id)?.en ?? id;
}

export function specialtyTitle(id: string, lang: Lang) {
  const specialty = specialtyById(id);
  if (!specialty) return id;
  if (lang === "en") return specialty.en;
  if (lang === "ar") return specialty.ar;
  return specialty.fa;
}

export function groupTitle(id: string, lang: Lang) {
  const group = groupById(id);
  if (!group) return id;
  if (lang === "en") return group.en;
  if (lang === "ar") return group.ar;
  return group.fa;
}

export function defaultSentence(stageId: string, lang: Lang) {
  return stageById(stageId)?.sentence[lang] ?? "";
}

export function pathStages() {
  return STAGES.filter((stage) => stage.kind === "path");
}

export function sideStages() {
  return STAGES.filter((stage) => stage.kind === "side");
}
