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

const btProfileKeys = {
  selection: ["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.`,
  ],
};

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 Advantace360 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: "", id: "l-f-1-1", info: [""] }),
    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({ name: "", id: "l-f-26-1", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-1-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-6-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-10-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-14-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-18-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-22-5", info: [""] }),
    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, like when using <a href="https://clique.kinesis-ergo.com/>Kinesis Clique</a> or <a href="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: "", id: "l-f-6-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-10-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-14-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-18-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-22-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-26-9", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-1-13", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-6-13", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-10-13", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-14-13", info: [""] }),
    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: "", id: "l-f-22-13", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-1-17", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-6-17", info: [""] }),
    new KeymapKey({ name: "", id: "l-f-10-17", info: [""] }),
    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 Left Thumb Grid (l-t)
    new KeymapKey({ name: "", id: "l-t-5-1", info: [""] }),
    new KeymapKey({ name: "", id: "l-t-9-1", info: [""] }),
    new KeymapKey({ name: "", id: "l-t-1-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-t-5-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-t-9-5", info: [""] }),
    new KeymapKey({ name: "", id: "l-t-9-9", info: [""] }),
    // #endregion Left Thumb Grid (l-t)

    // #region Right Finger Grid (r-f)
    new KeymapKey({ name: "", id: "r-f-1-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-5-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-9-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-13-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-17-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-21-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-25-1", info: [""] }),
    new KeymapKey({ id: "r-f-1-5", ...bootKeys }),
    new KeymapKey({ name: "", id: "r-f-5-5", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-9-5", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-13-5", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-17-5", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-21-5", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-25-5", info: [""] }),
    new KeymapKey({
      name: "batt",
      id: "r-f-1-9",
      info: [
        "Show the battery level for each half of the keyboard via its LEDs.",
      ],
    }),
    new KeymapKey({ name: "", id: "r-f-5-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-9-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-13-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-17-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-21-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-25-9", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-5-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-9-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-13-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-17-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-21-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-25-13", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-9-17", info: [""] }),
    new KeymapKey({
      id: "r-f-13-17",
      ...keyLegends.adv360Layer,
      info: ["The key to enter this layer."],
    }),
    new KeymapKey({ name: "", id: "r-f-17-17", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-21-17", info: [""] }),
    new KeymapKey({ name: "", id: "r-f-25-17", info: [""] }),
    // #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 paring",
        "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: "", id: "r-t-5-1", info: [""] }),
    new KeymapKey({ name: "", id: "r-t-1-5", info: [""] }),
    new KeymapKey({
      name: "backlight toggle",
      textLegend: "BL0",
      id: "r-t-5-5",
      ...backlightKeys,
    }),
    new KeymapKey({
      name: "indicator light toggle",
      textLegend: "LED",
      id: "r-t-9-5",
      info: [
        `Toggle the LEDs on the keyboard on and off.`,
        `Allows you to fully disable the LEDs indicating capslock, bluetooth profile, and layer, if you like.`,
        `I always keep them on.`,
      ],
    }),
    new KeymapKey({ name: "", id: "r-t-1-9", info: [""] }),
    // #endregion Right Thumb Grid (r-t)
  ],
});
