import { html as c, attr as n, aria as m, WithElement as v, OnDispose as A } from "@tempots/dom";
import { B as x } from "./translations-DoBmuZ5v.js";
const l = [
  "button:not([disabled])",
  '[role="button"]:not([aria-disabled="true"])',
  "a[href]",
  "input:not([disabled])",
  "select:not([disabled])",
  "textarea:not([disabled])",
  '[tabindex]:not([tabindex="-1"])'
].join(", ");
function y(...a) {
  return c.div(
    n.class("bc-toolbar"),
    n.role("toolbar"),
    m.orientation("horizontal"),
    // Keyboard navigation with roving tabindex among focusable children
    v((o) => {
      const h = () => {
        const e = Array.from(
          o.querySelectorAll(l)
        );
        e.length !== 0 && e.forEach(
          (t, r) => t.setAttribute("tabindex", r === 0 ? "0" : "-1")
        );
      }, u = (e) => {
        const t = Array.from(
          o.querySelectorAll(l)
        );
        if (t.length === 0) return;
        const r = t.findIndex(
          (b) => b === document.activeElement
        );
        let s = (r === -1 ? 0 : r) + e;
        s < 0 && (s = t.length - 1), s >= t.length && (s = 0), t.forEach((b) => b.setAttribute("tabindex", "-1"));
        const f = t[s];
        f.setAttribute("tabindex", "0"), f.focus();
      };
      setTimeout(h, 0);
      const d = (e) => {
        switch (e.key) {
          case "ArrowRight":
            e.preventDefault(), u(1);
            break;
          case "ArrowLeft":
            e.preventDefault(), u(-1);
            break;
          case "Home":
            e.preventDefault(), u(-1);
            {
              const t = Array.from(
                o.querySelectorAll(l)
              );
              if (t.length) {
                t.forEach((i) => i.setAttribute("tabindex", "-1"));
                const r = t[0];
                r.setAttribute("tabindex", "0"), r.focus();
              }
            }
            break;
          case "End":
            e.preventDefault();
            {
              const t = Array.from(
                o.querySelectorAll(l)
              );
              if (t.length) {
                t.forEach((i) => i.setAttribute("tabindex", "-1"));
                const r = t[t.length - 1];
                r.setAttribute("tabindex", "0"), r.focus();
              }
            }
            break;
        }
      };
      return o.addEventListener("keydown", d), A(() => {
        o.removeEventListener("keydown", d);
      });
    }),
    ...a
  );
}
function E(a, ...o) {
  return x(
    {
      color: "neutral",
      roundedness: "md",
      variant: "light",
      ...a
    },
    n.class("bc-toolbar__button"),
    ...o
  );
}
function _(...a) {
  return c.div(
    n.class("bc-toolbar__group"),
    n.role("group"),
    ...a
  );
}
function k() {
  return c.div(
    n.class("bc-toolbar__divider"),
    n.role("separator"),
    m.orientation("vertical")
  );
}
function T() {
  return c.div(n.class("bc-toolbar__spacer"));
}
export {
  y as T,
  E as a,
  _ as b,
  k as c,
  T as d
};
