/**
 * Category-aware measurement suggestions for the product size chart (راهنمای سایز).
 *
 * Sellers can always type their own columns; these just power the quick-add
 * chips and seed a sensible default column set per garment type. Matching is by
 * Persian keyword substring against the product's category name, most-specific
 * groups first, falling back to a general garment set.
 */

interface SuggestionGroup {
  keys: string[];
  suggestions: string[];
}

// Order matters: the first group whose keyword appears in the category name wins.
const GROUPS: SuggestionGroup[] = [
  // ---- bottoms ----
  { keys: ["شلوار", "شلوارک"], suggestions: ["دور کمر", "دور باسن", "فاق", "دور ران", "قد", "دمپا"] },
  { keys: ["دامن"], suggestions: ["دور کمر", "دور باسن", "قد", "دمپا"] },
  { keys: ["مایو"], suggestions: ["دور سینه", "دور کمر", "دور باسن", "قد"] },

  // ---- footwear ----
  { keys: ["کفش", "صندل", "دمپایی", "پاشنه"], suggestions: ["سایز اروپایی", "طول کف پا"] },

  // ---- small accessories with their own sizing ----
  { keys: ["جوراب"], suggestions: ["سایز", "طول ساق"] },
  { keys: ["کلاه"], suggestions: ["دور سر"] },
  { keys: ["کمربند"], suggestions: ["طول", "عرض"] },
  { keys: ["دستکش"], suggestions: ["دور مچ", "طول دست"] },
  { keys: ["انگشتر"], suggestions: ["سایز انگشتر", "دور انگشت"] },
  { keys: ["دستبند", "پابند"], suggestions: ["دور مچ", "طول"] },
  { keys: ["گردنبند", "آویز"], suggestions: ["طول زنجیر"] },
  { keys: ["گوشواره", "گل سینه", "زیورآلات", "سردست"], suggestions: ["طول", "عرض"] },
  { keys: ["شال", "روسری", "دستمال"], suggestions: ["طول", "عرض"] },
  { keys: ["عینک"], suggestions: ["عرض فریم", "طول دسته"] },

  // ---- bags ----
  { keys: ["کیف", "کوله"], suggestions: ["طول", "عرض", "ارتفاع", "طول بند"] },

  // ---- one-piece / manteau ----
  { keys: ["مانتو", "کیمونو"], suggestions: ["دور سینه", "قد", "سرشانه", "آستین", "دور کمر"] },
  { keys: ["اورال", "پیراهن و اورال"], suggestions: ["دور سینه", "دور کمر", "دور باسن", "قد", "آستین"] },

  // ---- tops & outerwear (broad garment fallback) ----
  {
    keys: [
      "کاپشن", "بارانی", "پالتو", "کت", "ژاکت", "بامبر", "جلیقه", "دورس",
      "سویشرت", "هودی", "پلیور", "بلوز", "شومیز", "تیشرت", "تاپ", "پلوشرت", "پیراهن",
    ],
    suggestions: ["دور سینه", "قد", "سرشانه", "آستین", "عرض سینه", "دور کمر"],
  },
];

// Generic fallback for anything unmatched (also the base defaults the seller named).
const DEFAULT_SUGGESTIONS = ["عرض سینه", "قد", "دور کمر", "دور باسن", "سرشانه", "آستین"];

/** All measurement suggestions for a category (used for the quick-add chips). */
export function getSizeSuggestions(categoryName?: string | null): string[] {
  const name = (categoryName || "").trim();
  if (name) {
    for (const group of GROUPS) {
      if (group.keys.some((k) => name.includes(k))) return group.suggestions;
    }
  }
  return DEFAULT_SUGGESTIONS;
}

/** The columns to seed a brand-new (empty) chart with for this category. */
export function getDefaultColumns(categoryName?: string | null): string[] {
  return getSizeSuggestions(categoryName).slice(0, 2);
}
