import { $ as m } from "./FocusScope-DI1zU4s2.es.js";
import { $ as g } from "./filterDOMProps-Cxz9cAAv.es.js";
import { b as y } from "./mergeProps-B-cqsBhL.es.js";
import { useState as x, useRef as T } from "react";
import { $ as h } from "./context-BfHy4NgG.es.js";
function D(c, a) {
  const { "aria-label": u, "aria-labelledby": f, orientation: e = "horizontal" } = c;
  let [n, d] = x(!1);
  y(() => {
    var r;
    d(!!(a.current && (!((r = a.current.parentElement) === null || r === void 0) && r.closest('[role="toolbar"]'))));
  });
  const { direction: b } = h(), s = b === "rtl" && e === "horizontal";
  let t = m(a);
  const p = (r) => {
    if (r.currentTarget.contains(r.target)) {
      if (e === "horizontal" && r.key === "ArrowRight" || e === "vertical" && r.key === "ArrowDown")
        s ? t.focusPrevious() : t.focusNext();
      else if (e === "horizontal" && r.key === "ArrowLeft" || e === "vertical" && r.key === "ArrowUp")
        s ? t.focusNext() : t.focusPrevious();
      else if (r.key === "Tab") {
        r.stopPropagation(), o.current = document.activeElement, r.shiftKey ? t.focusFirst() : t.focusLast();
        return;
      } else
        return;
      r.stopPropagation(), r.preventDefault();
    }
  }, o = T(null), $ = (r) => {
    !r.currentTarget.contains(r.relatedTarget) && !o.current && (o.current = r.target);
  }, v = (r) => {
    var i;
    if (o.current && !r.currentTarget.contains(r.relatedTarget) && (!((i = a.current) === null || i === void 0) && i.contains(r.target))) {
      var l;
      (l = o.current) === null || l === void 0 || l.focus(), o.current = null;
    }
  };
  return {
    toolbarProps: {
      ...g(c, {
        labelable: !0
      }),
      role: n ? "group" : "toolbar",
      "aria-orientation": e,
      "aria-label": u,
      "aria-labelledby": u == null ? f : void 0,
      onKeyDownCapture: n ? void 0 : p,
      onFocusCapture: n ? void 0 : v,
      onBlurCapture: n ? void 0 : $
    }
  };
}
export {
  D as $
};
//# sourceMappingURL=useToolbar-NGUPId3z.es.js.map
