import { j as jsxRuntimeExports } from "../../../../../_virtual/jsx-runtime.js";
import { a as h } from "../../../../sdk/dist/shared/chunk-IKHZD2JH.js";
import "../../../../sdk/dist/shared/chunk-3YVJ2ELD.js";
import "../../../../sdk/dist/shared/chunk-AFVJZPLS.js";
import "@sinclair/typebox";
import "../../../../sdk/dist/shared/chunk-A3GF4PYW.js";
import "../../../../sdk/dist/shared/chunk-W33JMRRN.js";
import { tx as D, css as E } from "../../../../style-system/dist/twind.js";
import { useBrickStyle } from "../hooks/use-brick-style.js";
import BrickRoot from "../components/BrickRoot.js";
import { useSitemap } from "../../../../../use-page-data.js";
function Button({ brick, editable }) {
  const styles = useBrickStyle(brick);
  const { props } = brick;
  const classes = Object.values(styles);
  const sitemap = useSitemap();
  const handleClick = (e) => {
    if (editable) {
      e.preventDefault();
      return;
    }
    if (props.link) {
      if (props.link.startsWith("http")) {
        window.open(props.link, "_blank");
      } else {
        const page = sitemap.find((p) => p.id === props.link);
        if (page) {
          window.location.href = page.attributes.path;
        }
      }
    }
  };
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
    BrickRoot,
    {
      brick,
      manifest: h,
      editable,
      as: "button",
      type: "button",
      className: D(
        classes,
        "btn",
        E({
          "&:hover": {
            filter: "brightness(1.15)"
          }
        }),
        editable && "pointer-events-none"
      ),
      "data-prevented-by-editor": editable ? "true" : "false",
      onClick: handleClick,
      children: props.label
    }
  );
}
export {
  Button as default
};
//# sourceMappingURL=button.js.map
