export const USER_LEVELS = {
  NEW: "تازه وارد",
  STANDARD: "استاندارد",
  PRO: "حرفه‌ای",
  MASTER: "استاد",
} as const;

/** Normalize level from URL slug or query (handles ZWNJ / spacing variants). */
export function normalizeUserLevel(raw?: string | null): string {
  if (!raw) return "";

  const text = raw.trim().replace(/\u200c/g, "").replace(/\s+/g, " ");

  if (text === USER_LEVELS.NEW) return USER_LEVELS.NEW;
  if (text === USER_LEVELS.STANDARD) return USER_LEVELS.STANDARD;
  if (text === USER_LEVELS.MASTER) return USER_LEVELS.MASTER;
  if (text === USER_LEVELS.PRO || text === "حرفه ای") return USER_LEVELS.PRO;

  return raw.trim();
}

/** Extract user level token from Persian SEO slug text. */
export function parseUserLevelFromSlug(fullText: string): string {
  const text = fullText.replace(/\u200c/g, " ");

  if (text.includes(USER_LEVELS.NEW)) return USER_LEVELS.NEW;
  if (text.includes(USER_LEVELS.STANDARD)) return USER_LEVELS.STANDARD;
  if (text.includes(USER_LEVELS.MASTER)) return USER_LEVELS.MASTER;
  if (/حرفه[\s\u200c]*ای/.test(text) || text.includes(USER_LEVELS.PRO)) {
    return USER_LEVELS.PRO;
  }

  return "";
}
