import { KeyboardCode as o } from "@dnd-kit/core";
import { ROOT_ID as L } from "./constants.es.js";
const y = (r, h, d, I, x, b) => {
  const e = document.activeElement;
  if (!(e != null && e.parentElement) || e.getAttribute("role") !== "treeitem" || !(e instanceof HTMLLIElement))
    return;
  const t = Array.from(e.parentElement.children).filter(
    (n) => n.nodeName === "LI"
  ), c = t.indexOf(e), f = d[c], s = f.props.id, p = h.has(s), a = f.props.parentId, i = e.getAttribute("data-has-children") === "true", { code: g } = r, l = () => {
    r.preventDefault(), I(s);
  }, u = () => {
    r.preventDefault(), b(s);
  }, k = () => {
    r.preventDefault(), x(s);
  }, D = () => {
    const n = (c + t.length - 1) % t.length;
    t[n].focus();
  }, m = () => {
    const n = (c + 1) % t.length;
    t[n].focus();
  };
  switch (g) {
    case o.Enter:
      l();
      break;
    case o.Space:
      i ? u() : l();
      break;
    case o.Right:
      if (!i)
        break;
      p ? m() : u();
      break;
    case o.Left:
      if (i && p)
        k();
      else if (a && a !== L) {
        const n = d.findIndex((E) => E.props.id === a);
        t[n].focus();
      }
      break;
    case o.Up:
      r.preventDefault(), D();
      break;
    case o.Down:
      r.preventDefault(), m();
      break;
  }
};
export {
  y as handleKeyDownEvent
};
//# sourceMappingURL=treeHandleKeyDown.es.js.map
