import { jsx as r, jsxs as s } from "react/jsx-runtime";
import { useMemo as z, useEffect as b } from "react";
import { useLocation as p, matchPath as D } from "react-router-dom";
import R from "react-helmet";
import { Box as d, useTheme as T, Container as V } from "@mui/material";
import B from "clsx";
import { CloseFullscreen as U, OpenInFull as E } from "@mui/icons-material";
import G from "../dashboard-legacy/index.js";
import "../../Header/header.js";
import O from "../../Header/responsive-header.js";
import q from "../../NavMenu/nav-menu.js";
import "../../NavMenu/products.js";
import A from "../../Footer/index.js";
import f from "./sidebar.js";
import { styled as u } from "../../Theme/index.js";
import { Link as x } from "./external-link.js";
import { FullPageProvider as J, useFullPage as K } from "./full-page.js";
function Q({ closeMenu: e, ...a }) {
  const o = p();
  return b(() => {
    e();
  }, [o]), /* @__PURE__ */ r(q, { ...a });
}
function g(e, a) {
  return e.map((o) => o.children?.length ? {
    ...o,
    label: o.title,
    children: g(o.children, a)
  } : {
    ...o,
    label: /* @__PURE__ */ r(x, { to: o.url, external: o.external, children: o.title }),
    // external = true 时 active 状态由传入 links 的调用方决定 (适用于 blocklet ui dashboard 的情况)
    active: o.external ? o.active : !!D({ path: o.url, end: !1 }, a.pathname)
  });
}
function X({
  title: e = "Home",
  headerProps: a = {},
  links: o = [],
  sidebarWidth: v = 120,
  fullWidth: w = !1,
  dense: l = "auto",
  footerProps: y = {},
  sx: N = {},
  children: P,
  hideHtmlTitle: F = !1,
  ...c
}) {
  const h = T(), { inFullPage: L, showToggleButton: $, headerVisible: C, footerVisible: H, sidebarVisible: W, toggleFullPage: _ } = K(), m = p(), n = z(() => g(o, m), [m, o]), S = n.some((t) => !!t.children?.length), i = l === "auto" ? n.length >= 8 || S : l, j = B("dashboard", { "dashboard-dense": i }, c.className), I = {
    homeLink: (t) => /* @__PURE__ */ r(x, { to: window.blocklet?.prefix || "/", children: t }),
    ...a
  };
  return b(() => {
    const { searchParams: t } = new URL(window.location.href);
    t.get("inviter") && window.localStorage.setItem("inviter", t.get("inviter"));
  }, []), /* @__PURE__ */ s(Y, { sx: N, ...c, className: j, sidebarWidth: v, children: [
    !F && /* @__PURE__ */ r(R, { title: e }, e),
    C && /* @__PURE__ */ r(Z, { ...I, className: "dashboard-header", children: o?.length ? ({ isMobile: t, closeMenu: M }) => t ? /* @__PURE__ */ r(
      Q,
      {
        mode: "inline",
        items: n,
        closeMenu: M,
        bgColor: "transparent",
        activeTextColor: h.palette.primary.main
      }
    ) : null : null }),
    /* @__PURE__ */ s(
      d,
      {
        className: "dashboard-body",
        sx: {
          display: "flex"
        },
        children: [
          !!o?.length && W && /* @__PURE__ */ r(
            d,
            {
              className: "dashboard-sidebar",
              sx: {
                display: {
                  xs: "none",
                  md: "block"
                }
              },
              children: i ? /* @__PURE__ */ r(f, { links: o, dense: i }) : /* @__PURE__ */ r(d, { className: "dashboard-sidebar-container", children: /* @__PURE__ */ r(f, { links: o, dense: i }) })
            }
          ),
          /* @__PURE__ */ s(d, { className: "dashboard-main", id: "arc__dashboard-main", children: [
            $ && /* @__PURE__ */ r(
              d,
              {
                sx: {
                  position: "absolute",
                  top: 4,
                  right: 4,
                  display: "flex",
                  justifyContent: "center",
                  alignItems: "center",
                  width: 24,
                  height: 24,
                  color: "#fff",
                  bgcolor: "rgba(158,158,158, 0.6);",
                  borderRadius: 1,
                  cursor: "pointer"
                },
                onClick: _,
                children: L ? /* @__PURE__ */ r(U, { style: { fontSize: 18 } }) : /* @__PURE__ */ r(E, { style: { fontSize: 18 } })
              }
            ),
            /* @__PURE__ */ r(V, { className: "dashboard-content", id: "arc__dashboard-content", ...w && { maxWidth: !1 }, children: P }),
            H && /* @__PURE__ */ r(A, { dark: h.palette.mode === "dark", ...y })
          ] })
        ]
      }
    )
  ] });
}
const Y = u(d)`
  &.dashboard {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: ${({ theme: e }) => e.palette.background.default};
  }
  .dashboard-body {
    overflow: hidden;
    flex: 1;
  }
  .dashboard-sidebar {
    box-sizing: border-box;
    flex: 0 0 auto;
    width: ${(e) => e.sidebarWidth}px;
    overflow: hidden;
    &:hover {
      overflow-y: auto;
    }
  }
  .dashboard-sidebar-container {
    width: ${(e) => e.sidebarWidth}px;
  }
  .dashboard-main {
    display: flex;
    flex-direction: column;
    overflow: auto;
    flex: 1;
    position: relative;
  }
  .dashboard-content {
    flex: 1;
  }
  &.dashboard-dense {
    .dashboard-header {
      border-bottom: 1px solid;
      border-color: ${({ theme: e }) => e.palette.divider};
    }
    .dashboard-sidebar {
      width: 256px;
      border-right: 1px solid;
      border-color: ${({ theme: e }) => e.palette.divider};
    }
  }
  ${(e) => e.theme.breakpoints.up("md")} {
    .header-logo {
      display: flex;
      justify-content: center;
    }
    &.dashboard-dense {
      .header-logo {
        /* dense = true 时 logo 与 sidenav icons 不需要对齐 */
        width: auto;
      }
    }
  }
`, Z = u(O)`
  .header-container {
    max-width: 100%;
  }
`;
function xe({
  legacy: e = !0,
  ...a
}) {
  return e ? /* @__PURE__ */ r(G, { ...a }) : /* @__PURE__ */ r(J, { children: /* @__PURE__ */ r(X, { ...a }) });
}
export {
  xe as default
};
