import { j as jsxRuntimeExports } from "./jsx-runtime-mMz73N64.js";
import { createContext, useContext as useContext$1, isValidElement, Fragment } from "react";
import { A, j as LevelComponentSizes } from "./aggregator-Dl2jHye5.js";
import { S as Space } from "./Center-hbwH7rg9.js";
import { I as Icon, ar as Divider, B as Button, W as WithIcon } from "./Toggle-DcOiWiHG.js";
import { C as CSS } from "./css-DoalWJF6.js";
const Context = createContext({
  divided: false,
  level: "h1"
});
const useContext = () => useContext$1(Context);
const Header = ({
  children,
  className,
  level = "h1",
  divided = false,
  ...props
}) => /* @__PURE__ */ jsxRuntimeExports.jsx(Context.Provider, { value: { level, divided }, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
  Space,
  {
    el: "header",
    direction: "x",
    justify: "spaceBetween",
    className: CSS(
      CSS.B("header"),
      CSS.bordered("bottom"),
      divided && CSS.BM("header", "divided"),
      className
    ),
    ...props,
    children
  }
) });
const Actions = ({ children = [] }) => {
  const { level, divided } = useContext();
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    Space,
    {
      direction: "x",
      size: "small",
      align: "center",
      className: CSS.BE("header", "actions"),
      children: A(children).map((action, i) => /* @__PURE__ */ jsxRuntimeExports.jsx(Action, { index: i, level, divided, children: action }, i))
    }
  );
};
const Action = ({ index, level, children, divided }) => {
  let content = children;
  if (!isValidElement(children)) {
    const props = children;
    content = /* @__PURE__ */ jsxRuntimeExports.jsx(
      Icon,
      {
        onClick: (e) => {
          var _a;
          e.stopPropagation();
          e.preventDefault();
          (_a = props.onClick) == null ? void 0 : _a.call(props, e);
        },
        size: LevelComponentSizes[level],
        ...props
      },
      index
    );
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(Fragment, { children: [
    divided && /* @__PURE__ */ jsxRuntimeExports.jsx(Divider, {}),
    content
  ] }, index);
};
const ButtonTitle = ({
  children = "",
  className,
  onClick,
  ...props
}) => {
  const { level } = useContext();
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    Button,
    {
      variant: "text",
      size: LevelComponentSizes[level],
      onClick,
      className: CSS(CSS.B("header-button-title"), className),
      sharp: true,
      ...props,
      children
    }
  );
};
const Title = ({
  className,
  level: propsLevel,
  ...props
}) => {
  const { level, divided } = useContext();
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    WithIcon,
    {
      className: CSS(CSS.BE("header", "text"), className),
      level: propsLevel ?? level,
      divided,
      size: 1.5,
      ...props
    }
  );
};
const external = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  Actions,
  ButtonTitle,
  Header,
  Title,
  useContext
}, Symbol.toStringTag, { value: "Module" }));
export {
  Actions as A,
  ButtonTitle as B,
  Header as H,
  external as e
};
//# sourceMappingURL=external-B695Iunb.js.map
