// Single source of truth for the avatar-decoration CDN base URL.
// scripts/syncDecorations.mjs reads this exact `DECORATION_CDN` declaration out
// of this file at runtime (by regex) instead of re-declaring it, so the two can
// never drift. If you migrate the CDN, change it here ONLY — keep the
// `export const DECORATION_CDN = '...'` shape so the sync script can still parse it.
export const DECORATION_CDN =
  'https://drive.lotusguild.org/public.php/dav/files/bHswJ9pNKp2t26N/cinny-decorations';

// Runtime base. A deployment can repoint the decorations at a different host
// without editing the catalog literal above (which scripts/syncDecorations.mjs
// and the build read) by setting `VITE_DECORATION_CDN`; otherwise it falls back
// to DECORATION_CDN. `import.meta.env` is undefined under the tsx test runner,
// hence the guard. Trailing slashes are trimmed so `decorationUrl` stays clean.
const envDecorationCdn = (import.meta as unknown as { env?: Record<string, string | undefined> })
  .env?.VITE_DECORATION_CDN;
const RESOLVED_DECORATION_CDN = (envDecorationCdn || DECORATION_CDN).replace(/\/+$/, '');

export type AvatarDecoration = {
  slug: string;
  name: string;
};

export type DecorationCategory = {
  id: string;
  label: string;
  decorations: AvatarDecoration[];
};

export const DECORATION_CATEGORIES: DecorationCategory[] = [
  {
    id: 'gaming',
    label: 'Gaming',
    decorations: [
      { slug: 'slither_n_snack', name: "Slither 'n Snack" },
      { slug: 'joystick', name: 'Joystick' },
      { slug: 'clyde_invaders', name: 'Space Invaders' },
      { slug: 'mallow_jump', name: 'Mallow Jump' },
      { slug: 'hot_shot', name: 'Hot Shot' },
      { slug: 'pipedream', name: 'Pipedream' },
      { slug: 'disxcore_headset', name: 'Gaming Headset' },
      { slug: 'pink_headset', name: 'Pink Headset' },
      { slug: 'green_headset', name: 'Green Headset' },
      { slug: 'feelin_awe', name: "Feelin' Awe" },
      { slug: 'feelin_panic', name: "Feelin' Panic" },
      { slug: 'feelin_nervous', name: "Feelin' Nervous" },
      { slug: 'feelin_scrumptious', name: "Feelin' Scrumptious" },
    ],
  },
  {
    id: 'cyber',
    label: 'Cyber',
    decorations: [
      { slug: 'cybernetic', name: 'Cybernetic' },
      { slug: 'glitch', name: 'Glitch' },
      { slug: 'digital_sunrise', name: 'Digital Sunrise' },
      { slug: 'implant', name: 'Implant' },
      { slug: 'blue_futuristic_ui', name: 'Futuristic UI (Blue)' },
      { slug: 'green_futuristic_ui', name: 'Futuristic UI (Green)' },
      { slug: 'pink_futuristic_ui', name: 'Futuristic UI (Pink)' },
      { slug: 'chromawave', name: 'Chromawave' },
      { slug: 'hex_lights', name: 'Hex Lights' },
    ],
  },
  {
    id: 'space',
    label: 'Space',
    decorations: [
      { slug: 'stardust', name: 'Stardust' },
      { slug: 'black_hole', name: 'Black Hole' },
      { slug: 'constellations', name: 'Constellations' },
      { slug: 'solar_orbit', name: 'Solar Orbit' },
      { slug: 'astronaut_helmet', name: 'Astronaut Helmet' },
      { slug: 'ufo', name: 'UFO' },
      { slug: 'warp_helmet', name: 'Warp Helmet' },
      { slug: 'aurora', name: 'Aurora' },
    ],
  },
  {
    id: 'fantasy',
    label: 'Fantasy',
    decorations: [
      { slug: 'kitsune', name: 'Kitsune' },
      { slug: 'phoenix', name: 'Phoenix' },
      { slug: 'unicorn', name: 'Unicorn' },
      { slug: 'flaming_sword', name: 'Flaming Sword' },
      { slug: 'skull_medallion', name: 'Skull Medallion' },
      { slug: 'glowing_runes', name: 'Glowing Runes' },
      { slug: 'eldritch_ring', name: 'Eldritch Ring' },
      { slug: 'arcane_sigil', name: 'Arcane Sigil' },
      { slug: 'midnight_sorceress', name: 'Midnight Sorceress' },
      { slug: 'deaths_edge', name: "Death's Edge" },
      { slug: 'malefic_crown', name: 'Malefic Crown' },
      { slug: 'spirit_embers', name: 'Spirit Embers' },
      { slug: 'defensive_shield', name: 'Defensive Shield' },
      { slug: 'magical_potion', name: 'Magical Potion' },
      { slug: 'wizards_staff', name: "Wizard's Staff" },
      { slug: 'crystal_ball_purple', name: 'Crystal Ball (Purple)' },
      { slug: 'crystal_ball_blue', name: 'Crystal Ball (Blue)' },
      { slug: 'owlbear_cub', name: 'Owlbear Cub' },
      { slug: 'owlbear_cub_snowy', name: 'Snowy Owlbear Cub' },
      { slug: 'baby_displacer_beast', name: 'Baby Displacer Beast' },
      { slug: 'dice_violet', name: 'Violet Dice' },
      { slug: 'dice_azure', name: 'Azure Dice' },
    ],
  },
  {
    id: 'elements',
    label: 'Elements',
    decorations: [
      { slug: 'fire', name: 'Fire' },
      { slug: 'water', name: 'Water' },
      { slug: 'air', name: 'Air' },
      { slug: 'earth', name: 'Earth' },
      { slug: 'lightning', name: 'Lightning' },
      { slug: 'balance', name: 'Balance' },
      { slug: 'ki_energy', name: 'Ki Energy' },
    ],
  },
  {
    id: 'japanese',
    label: 'Japanese',
    decorations: [
      { slug: 'kabuto', name: 'Kabuto' },
      { slug: 'oni_mask', name: 'Oni Mask' },
      { slug: 'sakura_warrior', name: 'Sakura Warrior' },
      { slug: 'sakura_ink', name: 'Sakura Ink' },
      { slug: 'shurikens_mask', name: "Shuriken's Mask" },
      { slug: 'straw_hat', name: 'Straw Hat' },
    ],
  },
  {
    id: 'nature',
    label: 'Nature',
    decorations: [
      { slug: 'lotus_flower', name: 'Lotus Flower' },
      { slug: 'koi_pond', name: 'Koi Pond' },
      { slug: 'sakura', name: 'Sakura' },
      { slug: 'sakura_pink', name: 'Pink Sakura' },
      { slug: 'fall_leaves', name: 'Fall Leaves' },
      { slug: 'fall_leaves_scarlet', name: 'Scarlet Leaves' },
      { slug: 'butterflies', name: 'Butterflies' },
      { slug: 'honeyblossom', name: 'Honeyblossom' },
      { slug: 'dandelion_duo', name: 'Dandelion Duo' },
      { slug: 'lunar_lanterns', name: 'Lunar Lanterns' },
      { slug: 'firecrackers', name: 'Firecrackers' },
      { slug: 'dragons_smile', name: "Dragon's Smile" },
    ],
  },
  {
    id: 'spooky',
    label: 'Spooky',
    decorations: [
      { slug: 'candlelight', name: 'Candlelight' },
      { slug: 'candlelight_crimson', name: 'Crimson Candlelight' },
      { slug: 'witch_hat_midnight', name: 'Midnight Witch Hat' },
      { slug: 'witch_hat_plum', name: 'Plum Witch Hat' },
      { slug: 'hood_dark', name: 'Dark Hood' },
      { slug: 'hood_crimson', name: 'Crimson Hood' },
      { slug: 'zombie_food', name: 'Zombie Food' },
      { slug: 'bloodthirsty', name: 'Bloodthirsty' },
      { slug: 'bloodthirsty_gold', name: 'Bloodthirsty (Gold)' },
      { slug: 'jack_o_lantern', name: "Jack-o'-Lantern" },
      { slug: 'pumpkin_spice', name: 'Pumpkin Spice' },
      { slug: 'spooky_cat_ears', name: 'Spooky Cat Ears' },
      { slug: 'ghosts', name: 'Ghosts' },
    ],
  },
  {
    id: 'cozy',
    label: 'Cozy',
    decorations: [
      { slug: 'cozy_cat', name: 'Cozy Cat' },
      { slug: 'rainy_mood', name: 'Rainy Mood' },
      { slug: 'oasis', name: 'Oasis' },
      { slug: 'cozy_headphones', name: 'Cozy Headphones' },
      { slug: 'doodling', name: 'Doodling' },
      { slug: 'fox_hat', name: 'Fox Hat' },
      { slug: 'fox_hat_chestnut', name: 'Chestnut Fox Hat' },
      { slug: 'fox_hat_snow', name: 'Snow Fox Hat' },
      { slug: 'cat_ears', name: 'Cat Ears' },
      { slug: 'frog_hat', name: 'Frog Hat' },
      { slug: 'polar_bear_hat', name: 'Polar Bear Hat' },
    ],
  },
];

export const ALL_DECORATIONS: AvatarDecoration[] = DECORATION_CATEGORIES.flatMap(
  (c) => c.decorations,
);

export function decorationUrl(slug: string): string {
  return `${RESOLVED_DECORATION_CDN}/${slug}.png`;
}
