import { jsxs, Fragment, jsx } from "react/jsx-runtime";
import { IconChevronLeft } from "../../icons/index.mjs";
/* empty css                                                                                                                                                                                       */
/* empty css                                                                                                                                                                                        */
/* empty css                                                                                                                                                                                                */
/* empty css                                                                                                                                                                                           */
/* empty css                                                                                                                                                                                           */
import { Typography } from "../../primitive/Typography/index.mjs";
import { clsx } from "clsx";
import { mergeSxList } from "../../utils/styles.mjs";
import { Box } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/core/Box/Box.mjs";
import { Group } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/Group/Group.mjs";
import { ActionIcon } from "../../node_modules/.pnpm/@mantine_core@7.15.2_patch_hash_jclkxeaefn6uz54h34k3r3yjsq_@mantine_hooks@7.15.2_react@18.3.1_szqfuioo5damkjdixckhzmwycq/node_modules/@mantine/core/esm/components/ActionIcon/ActionIcon.mjs";
const PageHeader = ({ sticky, leftSection, rightSection, children, ...restProps }) => {
  const rightExisted = !!rightSection;
  return /* @__PURE__ */ jsxs(
    Group,
    {
      ...restProps,
      className: clsx(restProps == null ? void 0 : restProps.className, "pageshell-header"),
      wrap: "nowrap",
      justify: "space-between",
      gap: "xl",
      sx: mergeSxList([
        {
          paddingLeft: 24,
          paddingRight: 24,
          height: 64
        },
        sticky ? (theme) => ({
          position: "sticky",
          zIndex: 1,
          top: 0,
          left: 0,
          background: theme.other.white
        }) : void 0,
        restProps.sx
      ]),
      children: [
        /* @__PURE__ */ jsxs(Group, { wrap: "nowrap", children: [
          leftSection,
          /* @__PURE__ */ jsx(Typography, { variant: "headline-lg", component: "div", fw: 300, sx: { flex: 1 }, children })
        ] }),
        rightExisted && /* @__PURE__ */ jsx(Group, { gap: 0, wrap: "nowrap", children: rightSection })
      ]
    }
  );
};
const PageShell = ({
  className,
  headerClassName,
  bodyClassName,
  headerSticky,
  headerRightSection,
  headerBack,
  title,
  wrapped = false,
  wrapperProps = {},
  headerProps: { withBack, onBackClick, ...headerProps } = {},
  bodyProps = {},
  children
}) => {
  const headerVisible = !!title || !!headerRightSection;
  const leftSection = (!!withBack || !!headerBack) && /* @__PURE__ */ jsx(
    ActionIcon,
    {
      "aria-label": "Navigate Back",
      variant: "default",
      onClick: () => {
        if (onBackClick) {
          onBackClick();
        } else if (typeof headerBack === "function") {
          headerBack();
        } else {
          history.back();
        }
      },
      children: /* @__PURE__ */ jsx(IconChevronLeft, { size: 20 })
    }
  );
  const page = /* @__PURE__ */ jsxs(Fragment, { children: [
    headerVisible && /* @__PURE__ */ jsx(
      PageHeader,
      {
        className: headerClassName,
        sticky: headerSticky,
        leftSection,
        rightSection: headerRightSection,
        ...headerProps,
        children: title
      }
    ),
    /* @__PURE__ */ jsx(
      Box,
      {
        ...bodyProps,
        className: clsx(bodyClassName, bodyProps == null ? void 0 : bodyProps.className, "pageshell-body"),
        sx: mergeSxList([
          {
            paddingLeft: 24,
            paddingRight: 24,
            paddingBottom: 16,
            paddingTop: headerVisible ? 0 : 16
          },
          bodyProps == null ? void 0 : bodyProps.sx
        ]),
        children
      }
    )
  ] });
  if (wrapped) {
    return /* @__PURE__ */ jsx(Box, { ...wrapperProps, className: clsx(className, wrapperProps == null ? void 0 : wrapperProps.className, "pageshell-wrapper"), children: page });
  }
  return page;
};
PageShell.Header = PageHeader;
export {
  PageShell
};
