export const INSTITUTION_TYPES = [
  "PRIMARY_AND_HIGH_SCHOOL",
  "COLLEGE_AND_UNIVERSITY",
  "COACHING",
  "MADRASHA",
] as const;

export type InstitutionTypeValue = (typeof INSTITUTION_TYPES)[number];

/* ------------------ Bangladesh education registry ------------------ */

/** Education boards Bangladeshi institutions register with (9 general
    boards + technical + madrasah; colleges also affiliate with the
    National University). Used by Institution Info maintenance. */
export const EDUCATION_BOARDS = [
  "DHAKA",
  "RAJSHAHI",
  "CHATTOGRAM",
  "CUMILLA",
  "JASHORE",
  "BARISHAL",
  "SYLHET",
  "DINAJPUR",
  "MYMENSINGH",
  "TECHNICAL",
  "MADRASAH",
  "NATIONAL_UNIVERSITY",
  "OTHER",
] as const;

export type EducationBoardValue = (typeof EDUCATION_BOARDS)[number];

export const ACADEMIC_CATEGORIES = [
  "CLASS",
  "SECTION",
  "DEPARTMENT",
  "SESSION",
  "SUBJECT",
  "GROUP",
  "SHIFT",
  "ROOM",
] as const;

export type AcademicCategoryValue = (typeof ACADEMIC_CATEGORIES)[number];

export const PAYMENT_METHODS = [
  "BKASH",
  "NAGAD",
  "ROCKET",
  "CARD",
  "BANK_TRANSFER",
  "CASH",
] as const;

export type PaymentMethodValue = (typeof PAYMENT_METHODS)[number];

/* ------------------ Login roles ------------------
   Client-safe role lists (imported by both the server auth helpers and the
   member layouts). STAFF_SIDE_ROLES are the employee-type member logins —
   they all link to a Staff record and share the staff /me area. */
export const STAFF_SIDE_ROLES = [
  "TEACHER",
  "STAFF",
  "PRINCIPAL",
  "VICE_PRINCIPAL",
  "EXECUTIVE_MEMBER",
] as const;

export type StaffSideRole = (typeof STAFF_SIDE_ROLES)[number];

export const MEMBER_ROLES = ["STUDENT", "PARENT", ...STAFF_SIDE_ROLES] as const;

export type MemberRoleValue = (typeof MEMBER_ROLES)[number];

/* ------------------ Student identity ------------------ */

/** Blood groups for admission forms and student ID cards. */
export const BLOOD_GROUPS = ["A+", "A-", "B+", "B-", "O+", "O-", "AB+", "AB-"] as const;

export type BloodGroupValue = (typeof BLOOD_GROUPS)[number];

/* ------------------ HR ------------------ */

export const STAFF_DESIGNATIONS = [
  "PRINCIPAL",
  "VICE_PRINCIPAL",
  "HEAD_TEACHER",
  "TEACHER",
  "ASSISTANT_TEACHER",
  "LIBRARIAN",
  "ACCOUNTANT",
  "OFFICE_ASSISTANT",
  "LAB_ASSISTANT",
  "DRIVER",
  "SECURITY_GUARD",
  "OTHER",
] as const;

export const STAFF_DEPARTMENTS = [
  "ACADEMIC",
  "SCIENCE",
  "ARTS",
  "COMMERCE",
  "ADMINISTRATION",
  "ACCOUNTS",
  "LIBRARY",
  "IT",
  "OTHER",
] as const;

export const ATTENDANCE_STATUSES = ["PRESENT", "ABSENT", "LEAVE"] as const;

export type AttendanceStatusValue = (typeof ATTENDANCE_STATUSES)[number];

/** Staff designations counted as teaching staff (for monitoring statistics). */
export const TEACHER_DESIGNATIONS = [
  "PRINCIPAL",
  "VICE_PRINCIPAL",
  "HEAD_TEACHER",
  "TEACHER",
  "ASSISTANT_TEACHER",
] as const;

/* ------------------ Communication ------------------ */

export const BROADCAST_CHANNELS = ["SMS", "EMAIL", "WHATSAPP"] as const;

export type BroadcastChannelValue = (typeof BROADCAST_CHANNELS)[number];

export const AUDIENCE_TYPES = [
  "ALL_STUDENTS",
  "BY_CLASS",
  "STUDENT",
  "ALL_STAFF",
  "STAFF",
] as const;

export type AudienceTypeValue = (typeof AUDIENCE_TYPES)[number];

/** Purchasable SMS bundles (qty, price in BDT). */
export const SMS_PACKAGES = [
  { qty: 100, price: 150 },
  { qty: 500, price: 600 },
  { qty: 1000, price: 1000 },
  { qty: 5000, price: 4500 },
] as const;

export const SMS_TYPES = ["MASKING", "NON_MASKING"] as const;

/* ------------------ Transport ------------------ */

export const VEHICLE_TYPES = [
  "BUS",
  "MINIBUS",
  "MICROBUS",
  "VAN",
  "OTHER",
] as const;

/* ------------------ Hostel ------------------ */

export const HOSTEL_TYPES = ["BOYS", "GIRLS", "MIXED"] as const;

export type HostelTypeValue = (typeof HOSTEL_TYPES)[number];

export const ROOM_TYPES = ["SINGLE", "DOUBLE", "TRIPLE", "DORMITORY"] as const;

export type RoomTypeValue = (typeof ROOM_TYPES)[number];

/* ------------------ Notice board ------------------ */

export const NOTICE_AUDIENCES = ["ALL", "STUDENTS", "STAFF"] as const;

export type NoticeAudienceValue = (typeof NOTICE_AUDIENCES)[number];

/* ------------------ Complaint box ------------------ */

export const COMPLAINT_TYPES = ["STUDENT", "PARENT", "STAFF", "OTHER"] as const;

export type ComplaintTypeValue = (typeof COMPLAINT_TYPES)[number];

export const COMPLAINT_CATEGORIES = [
  "GENERAL",
  "ACADEMIC",
  "FACILITY",
  "HARASSMENT",
  "FINANCIAL",
  "OTHER",
] as const;

export type ComplaintCategoryValue = (typeof COMPLAINT_CATEGORIES)[number];

export const COMPLAINT_STATUSES = ["PENDING", "IN_REVIEW", "RESOLVED", "REJECTED"] as const;

export type ComplaintStatusValue = (typeof COMPLAINT_STATUSES)[number];

/* ------------------ Events ------------------ */

export const EVENT_CATEGORIES = [
  "ACADEMIC",
  "CULTURAL",
  "SPORTS",
  "EXAM",
  "HOLIDAY",
  "MEETING",
] as const;

export type EventCategoryValue = (typeof EVENT_CATEGORIES)[number];

/* ------------------ Promotions ------------------ */

export const PROMOTION_TYPES = ["CLASS", "SECTION", "SHIFT", "GROUP"] as const;

export type PromotionTypeValue = (typeof PROMOTION_TYPES)[number];

/* ------------------ Lesson plans ------------------ */

export const LESSON_STATUSES = ["PLANNED", "IN_PROGRESS", "COMPLETED"] as const;

export type LessonStatusValue = (typeof LESSON_STATUSES)[number];

/* ------------------ Admission application types ------------------ */

export const APPLICATION_TYPES = ["RAPID", "DETAILS"] as const;

export type ApplicationTypeValue = (typeof APPLICATION_TYPES)[number];

/* ------------------ Committee ------------------ */

export const COMMITTEE_ROLES = [
  "PRESIDENT",
  "VICE_PRESIDENT",
  "SECRETARY",
  "TREASURER",
  "MEMBER",
] as const;

export type CommitteeRoleValue = (typeof COMMITTEE_ROLES)[number];

/* ------------------ Class routine ------------------ */

/** Week order per the Bangladeshi academic week (Friday last). */
export const WEEK_DAYS = [
  "SAT",
  "SUN",
  "MON",
  "TUE",
  "WED",
  "THU",
  "FRI",
] as const;

export type WeekDayValue = (typeof WEEK_DAYS)[number];

/* ------------------ Library ------------------ */

/** Library fine per overdue day (BDT). */
export const LIBRARY_FINE_PER_DAY = 10;

/** Default issue period in days. */
export const LIBRARY_ISSUE_DAYS = 14;

export const BOOK_CATEGORIES = [
  "TEXTBOOK",
  "REFERENCE",
  "LITERATURE",
  "SCIENCE",
  "HISTORY",
  "RELIGIOUS",
  "CHILDREN",
  "OTHER",
] as const;

/* ------------------ Inventory ------------------ */

export const INVENTORY_CATEGORIES = [
  "FURNITURE",
  "EQUIPMENT",
  "STATIONERY",
  "LAB",
  "IT",
  "CLEANING",
  "OTHER",
] as const;

export const INVENTORY_UNITS = [
  "PCS",
  "BOX",
  "SET",
  "PACK",
  "LITER",
  "KG",
  "REAM",
] as const;

/** Soft badge classes for each status value. */
export const STATUS_BADGE: Record<string, string> = {
  PENDING: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  ACTIVE: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  APPROVED: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  REJECTED: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  SUSPENDED: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  EXPIRED: "bg-slate-100 text-slate-600 ring-1 ring-slate-200",
  CANCELLED: "bg-slate-100 text-slate-600 ring-1 ring-slate-200",
  PAID: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  PARTIAL: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  DUE: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  SUPER_ADMIN: "bg-violet-50 text-violet-700 ring-1 ring-violet-200",
  INSTITUTION_ADMIN: "bg-sky-50 text-sky-700 ring-1 ring-sky-200",
  PRESENT: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  ABSENT: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  LEAVE: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  ISSUED: "bg-sky-50 text-sky-700 ring-1 ring-sky-200",
  RETURNED: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  OVERDUE: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  SENT: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  FAILED: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  IN: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  OUT: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  LOW: "bg-rose-50 text-rose-700 ring-1 ring-rose-200",
  IN_REVIEW: "bg-sky-50 text-sky-700 ring-1 ring-sky-200",
  RESOLVED: "bg-emerald-50 text-emerald-700 ring-1 ring-emerald-200",
  UPCOMING: "bg-sky-50 text-sky-700 ring-1 ring-sky-200",
  RUNNING: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  FINISHED: "bg-slate-100 text-slate-600 ring-1 ring-slate-200",
};

/** Distinct soft colors for the 4 institution types. */
export const TYPE_BADGE: Record<string, string> = {
  PRIMARY_AND_HIGH_SCHOOL: "bg-sky-50 text-sky-700 ring-1 ring-sky-200",
  COLLEGE_AND_UNIVERSITY: "bg-violet-50 text-violet-700 ring-1 ring-violet-200",
  COACHING: "bg-amber-50 text-amber-700 ring-1 ring-amber-200",
  MADRASHA: "bg-teal-50 text-teal-700 ring-1 ring-teal-200",
};

/** Gradient accents for institution-type cards on the landing page. */
export const TYPE_GRADIENT: Record<string, string> = {
  PRIMARY_AND_HIGH_SCHOOL: "from-sky-500 to-indigo-400",
  COLLEGE_AND_UNIVERSITY: "from-violet-500 to-purple-400",
  COACHING: "from-amber-500 to-orange-400",
  MADRASHA: "from-teal-500 to-green-400",
};

/* ------------------------------------------------------------------ */
/*  Exam Result system                                                  */
/* ------------------------------------------------------------------ */

/**
 * Result systems are specific to the institution type. Primary education
 * is fully operational now; the others are planned/setup-only — they are
 * listed in the module's setup screen but cannot operate yet.
 */
export const RESULT_SYSTEM_TYPES = [
  "PRIMARY_AND_HIGH_SCHOOL",
  "COACHING",
  "COLLEGE_AND_UNIVERSITY",
] as const;

export type ResultSystemType = (typeof RESULT_SYSTEM_TYPES)[number];

/** Institution types whose result system is operational today. */
export const RESULT_OPERATIONAL_TYPES: readonly string[] = ["PRIMARY", "HIGH_SCHOOL", "COACHING"];

/** Primary education letter-grade scale (percentage of full marks). */
export const PRIMARY_GRADE_SCALE = [
  { min: 80, grade: "A+", point: 5.0 },
  { min: 70, grade: "A", point: 4.0 },
  { min: 60, grade: "A-", point: 3.5 },
  { min: 50, grade: "B", point: 3.0 },
  { min: 40, grade: "C", point: 2.0 },
  { min: 33, grade: "D", point: 1.0 },
  { min: 0, grade: "F", point: 0.0 },
] as const;

/** Letter grade for a percentage, per the primary scale above. */
export function gradeFromPercent(percent: number): { grade: string; point: number } {
  for (const step of PRIMARY_GRADE_SCALE) {
    if (percent >= step.min) return { grade: step.grade, point: step.point };
  }
  return { grade: "F", point: 0.0 };
}

const BN_DIGITS = ["০", "১", "২", "৩", "৪", "৫", "৬", "৭", "৮", "৯"];

/** Convert ASCII digits in any string/number to Bangla numerals (০-৯). */
export function toBnDigits(value: string | number): string {
  return String(value).replace(/[0-9]/g, (d) => BN_DIGITS[Number(d)]);
}

/** Percentage range label for a grade-scale row: "≥80%", "70–79%", "<33%".
    locale "bn" renders Bangla numerals. */
export function gradeScaleRange(min: number, locale: string): string {
  const higher = PRIMARY_GRADE_SCALE.filter((s) => s.min > min).map((s) => s.min);
  const top = Math.min(...higher, Infinity);
  const text =
    higher.length === 0
      ? `≥${min}%`
      : min === 0
        ? `<${top}%`
        : `${min}–${top - 1}%`;
  return locale === "bn" ? toBnDigits(text) : text;
}

/** Portal modules institutions can toggle from the Control Panel.
    Core items (dashboard, admissions, students, academic, results…) stay on. */
export const PORTAL_MODULES = [
  { key: "fees", href: "/portal/fees" },
  { key: "accounts", href: "/portal/accounts" },
  { key: "omr", href: "/portal/omr" },
  { key: "schedule", href: "/portal/schedule" },
  { key: "lessonPlans", href: "/portal/lesson-plans" },
  { key: "hr", href: "/portal/hr" },
  { key: "library", href: "/portal/library" },
  { key: "hostel", href: "/portal/hostel" },
  { key: "inventory", href: "/portal/inventory" },
  { key: "transport", href: "/portal/transport" },
  { key: "notices", href: "/portal/notices" },
  { key: "events", href: "/portal/events" },
  { key: "committees", href: "/portal/committees" },
  { key: "complaints", href: "/portal/complaints" },
  { key: "messages", href: "/portal/messages" },
  { key: "communication", href: "/portal/communication" },
  { key: "certificates", href: "/portal/certificates" },
  { key: "competitions", href: "/portal/competitions" },
  { key: "promotions", href: "/portal/promotions" },
  { key: "campus", href: "/portal/campus/academic" },
  { key: "support", href: "/portal/support" },
] as const;

export type PortalModuleKey = (typeof PORTAL_MODULES)[number]["key"];
