// Function to detect if Shift, Ctrl, Alt, or combinations are pressed
// and return the corresponding key combination string
export const detectModifierKeys = (event: KeyboardEvent): string => {
  const modifiers = [
    event.ctrlKey ? "Ctrl" : "",
    event.altKey ? "Alt" : "",
    event.shiftKey ? "Shift" : "",
    event.metaKey ? "Meta" : "", // Add support for Command/Win key
  ].filter(Boolean);

  // Ignore modifier keys when they're pressed alone
  const isModifierKey = [
    "Control",
    "Shift",
    "Alt",
    "Meta",
    "Ctrl",
    "AltGraph",
    "OS", // Additional modifier key aliases
  ].includes(event.key);

  const mainKey = isModifierKey ? "" : event.key.toUpperCase();

  // Handle special cases for keys with different representations
  const normalizedKey = mainKey === " " ? "Space" : mainKey;

  // Build the combination string
  if (modifiers.length > 0 && normalizedKey) {
    return `${modifiers.join("+")}+${normalizedKey}`;
  } else if (modifiers.length > 0) {
    return modifiers.join("+");
  } else {
    return normalizedKey;
  }
};
