/**
 * @typedef {"steam-deck" | "xbox" | "playstation" | "switch" | "generic"} ControllerType
 */

/**
 * Mapping of logical actions to glyph labels.
 * Glyphs are plain strings or asset keys – render them however you like.
 * @type {Record<ControllerType, Record<string, string>>}
 */
export const glyphMap = {
  "steam-deck": {
    confirm: "A",
    back: "B",
    menu: "Menu",
    view: "View",
    leftBumper: "L1",
    rightBumper: "R1"
  },
  xbox: {
    confirm: "A",
    back: "B",
    menu: "Menu",
    view: "View",
    leftBumper: "LB",
    rightBumper: "RB"
  },
  playstation: {
    confirm: "Cross",
    back: "Circle",
    menu: "Options",
    view: "Share",
    leftBumper: "L1",
    rightBumper: "R1"
  },
  switch: {
    confirm: "A",
    back: "B",
    menu: "Plus",
    view: "Minus",
    leftBumper: "LB",
    rightBumper: "RB"
  },
  generic: {
    confirm: "1",
    back: "2",
    menu: "Menu",
    view: "View",
    leftBumper: "L",
    rightBumper: "R"
  }
};

/**
 * Asset filenames for common actions per controller.
 * @type {Record<ControllerType, Record<string, string>>}
 */
export const glyphAssetMap = {
  "steam-deck": {
    confirm: "assets/Steam Deck/SteamDeck_A.png",
    back: "assets/Steam Deck/SteamDeck_B.png",
    menu: "assets/Steam Deck/SteamDeck_Menu.png",
    view: "assets/Steam Deck/SteamDeck_Dots.png",
    leftBumper: "assets/Steam Deck/SteamDeck_L1.png",
    rightBumper: "assets/Steam Deck/SteamDeck_R1.png"
  },
  xbox: {
    confirm: "assets/Xbox Series/XboxSeriesX_A.png",
    back: "assets/Xbox Series/XboxSeriesX_B.png",
    menu: "assets/Xbox Series/XboxSeriesX_Menu.png",
    view: "assets/Xbox Series/XboxSeriesX_View.png",
    leftBumper: "assets/Xbox Series/XboxSeriesX_LB.png",
    rightBumper: "assets/Xbox Series/XboxSeriesX_RB.png"
  },
  playstation: {
    confirm: "assets/PS5/PS5_Cross.png",
    back: "assets/PS5/PS5_Circle.png",
    menu: "assets/PS5/PS5_Options.png",
    view: "assets/PS5/PS5_Share.png",
    leftBumper: "assets/PS5/PS5_L1.png",
    rightBumper: "assets/PS5/PS5_R1.png"
  },
  switch: {
    confirm: "assets/Switch/Switch_A.png",
    back: "assets/Switch/Switch_B.png",
    menu: "assets/Switch/Switch_Plus.png",
    view: "assets/Switch/Switch_Minus.png",
    leftBumper: "assets/Switch/Switch_LB.png",
    rightBumper: "assets/Switch/Switch_RB.png"
  },
  generic: {
    confirm: "assets/Xbox Series/XboxSeriesX_A.png",
    back: "assets/Xbox Series/XboxSeriesX_B.png",
    menu: "assets/Xbox Series/XboxSeriesX_Menu.png",
    view: "assets/Xbox Series/XboxSeriesX_View.png",
    leftBumper: "assets/Xbox Series/XboxSeriesX_LB.png",
    rightBumper: "assets/Xbox Series/XboxSeriesX_RB.png"
  }
};

/**
 * Get a glyph label for a controller type and action key.
 * @param {ControllerType} controller
 * @param {string} action
 * @returns {string | null}
 */
export function getGlyph(controller, action) {
  return glyphMap[controller]?.[action] ?? null;
}

/**
 * Get a relative asset path for a controller type and action key.
 * @param {ControllerType} controller
 * @param {string} action
 * @returns {string | null}
 */
export function getGlyphAssetPath(controller, action) {
  return glyphAssetMap[controller]?.[action] ?? null;
}
