import { KeymapKey, KeymapLayer } from "@keymapkit/ui";
import { keyLegends } from "./keyLegends";

const btProfileKeys = {
  selection: ["l-f-1-1", "l-f-6-1", "l-f-10-1", "l-f-14-1", "l-f-18-1", "l-f-22-1"],
  info: [
    `Select a Bluetooth profile.`,
    `The Advantage360 supports five Bluetooth profiles, which can be used to connect to five different devices.`,
    `These keys do the same thing as on the Action layer: toggle USB/Bluetooth output or select one of five Bluetooth profiles (0–4).`,
  ],
};

const backlightKeys = {
  selection: ["l-f-14-17", "l-f-18-17", "r-t-5-5"],
  info: [
    `Change the backlight brightness.`,
    `I don't use these except to play around, since I use blank keycaps and the backlight is useless for those.`,
  ],
};

const bootKeys = {
  name: "boot",
  selection: ["l-f-26-5", "r-f-1-5"],
  info: [`The Kinesis bootloader keys.`],
};

export const layer3mod = KeymapLayer.fromKeyList({
  displayName: "Advantage360 Layer",
  shortName: "Adv360",
  welcome: [
    `The Advantage360 layer.`,
    `(Kinesis refers to this as the "Mod Layer").`,
    `Most of these are just left in their default positions`,
    `Select a key from the board above to learn more about it.`,
  ],
  layerEntryKeys: ["r-f-13-17"],
  keys: [
    // #region Left Finger Grid (l-f)
    new KeymapKey({
      name: "Toggle Output",
      textLegend: "OUT",
      id: "l-f-1-1",
      ...btProfileKeys,
    }),
    new KeymapKey({ name: "BT0", id: "l-f-6-1", ...btProfileKeys }),
    new KeymapKey({ name: "BT1", id: "l-f-10-1", ...btProfileKeys }),
    new KeymapKey({ name: "BT2", id: "l-f-14-1", ...btProfileKeys }),
    new KeymapKey({ name: "BT3", id: "l-f-18-1", ...btProfileKeys }),
    new KeymapKey({ name: "BT4", id: "l-f-22-1", ...btProfileKeys }),
    new KeymapKey({ id: "l-f-26-5", ...bootKeys }),
    new KeymapKey({
      name: "Unlock",
      id: "l-f-1-9",
      htmlLegend: `<span style="font-size: 0.8em;">Unlock</span>`,
      info: [
        `Unlock the keyboard for programming.`,
        `When programming the keyboard with <a href="https://zmk.studio">ZMK Studio</a>, you will need to unlock it periodically.`,
        `It's very important to remember what key this is mapped to, or else you won't be able to program the keyboard or even see the existing layout!`,
      ],
    }),
    new KeymapKey({
      name: "vers",
      id: "l-f-18-13",
      info: [
        `Print the version string for the keyboard formware.`,
        `At the time of this writing, this results in the string <code>20250210-v3.0-091a5d4-clique</code>, plus a newline.`,
      ],
    }),
    new KeymapKey({
      name: "backlight decrease",
      textLegend: "BL-",
      id: "l-f-14-17",
      ...backlightKeys,
    }),
    new KeymapKey({
      name: "backlight increase",
      textLegend: "BL+",
      id: "l-f-18-17",
      ...backlightKeys,
    }),
    // #endregion Left Finger Grid (l-f)

    // #region Right Finger Grid (r-f)
    new KeymapKey({ id: "r-f-1-5", ...bootKeys }),
    new KeymapKey({
      name: "batt",
      id: "r-f-1-9",
      info: [
        "Show the battery level for each half of the keyboard via its LEDs.",
      ],
    }),
    // #endregion Right Finger Grid (r-f)

    // #region Right Thumb Grid (r-t)
    new KeymapKey({
      name: "Clear Bluetooth Profile",
      htmlLegend: `<span style="font-size: 0.8em;">BTCLR</span>`,
      id: "r-t-1-1",
      info: [
        "Clear the Bluetooth profile pairing",
        "Hit this key to forget the device paired to the current Bluetooth profile and allow it to connect to a new device.",
      ],
    }),
    new KeymapKey({
      name: "backlight toggle",
      textLegend: "BL0",
      id: "r-t-5-5",
      ...backlightKeys,
    }),
    new KeymapKey({
      name: "RGB toggle",
      textLegend: "RGB",
      id: "r-t-9-5",
      info: [`Toggle RGB lighting (&rgb_ug RGB_TOG).`],
    }),
    // #endregion Right Thumb Grid (r-t)
  ],
});
