/**
 * Shared Rarity Configuration
 * Provides the canonical rarity display config (colors, emoji, labels)
 * used by lootbox pull results and shop loot table views.
 */
export const RARITY_CONFIG: Record<string, { color: number; emoji: string; squareEmoji: string; label: string }> = {
  C:        { color: 0x95A5A6, emoji: "📦", squareEmoji: "🟤", label: "Common" },
  R:        { color: 0x3498DB, emoji: "📦", squareEmoji: "🔵", label: "Rare" },
  SR:       { color: 0x9B59B6, emoji: "✨", squareEmoji: "🟣", label: "Super Rare" },
  SSR:      { color: 0xF1C40F, emoji: "🌟", squareEmoji: "🟡", label: "SSR" },
  CURRENCY: { color: 0x2ECC71, emoji: "💰", squareEmoji: "💰", label: "Currency" },
  XP:       { color: 0x1ABC9C, emoji: "🔮", squareEmoji: "🔮", label: "Experience" },
  NOTHING:  { color: 0x636363, emoji: "💨", squareEmoji: "💨", label: "Empty" },
};

export function getRarityConfig(rarity: string): { color: number; emoji: string; squareEmoji: string; label: string } {
  return RARITY_CONFIG[rarity] ?? (RARITY_CONFIG["C"]!);
}

export function defaultName(path: string): string {
  return stripQuery(path).split("/").pop() || "image.png";
}

/** Strip query parameters from a URL/path (e.g. "foo.png?v=123" → "foo.png") */
export function stripQuery(url: string): string {
  const idx = url.indexOf("?");
  return idx === -1 ? url : url.slice(0, idx);
}
