import { jsxs as c, jsx as l } from "@emotion/react/jsx-runtime";
import { usePopupsStore as S } from "../../../../../../../../../popups/components/PopupsProvider/hooks/usePopupsStore.js";
import { PanelLayoutStyled as z, PanelMiddleRowStyled as H, PanelCenterColumnStyled as M, MainLayoutFlowStyled as $ } from "../../../../../../slots/AreasViewerSlots.js";
import { usePanelsByArea as b } from "../../hooks/usePanelsByArea.js";
import { usePinnedPanelResize as A } from "../../hooks/usePinnedPanelResize.js";
import { PanelResizeInteractionLayer as W } from "./subcomponents/PanelResizeInteractionLayer.js";
import { PanelWindow as m } from "./subcomponents/PanelWindow.js";
const y = (e, o) => {
  const i = {
    position: "relative",
    display: "flex",
    flexDirection: e.side === "left" || e.side === "right" ? "row" : "column",
    flexShrink: 0,
    minWidth: 0,
    minHeight: 0,
    overflow: o ? "visible" : "hidden"
  };
  if (e.side === "left" || e.side === "right") {
    const n = o ? 0 : e.width;
    return {
      ...i,
      width: `${n}px`,
      minWidth: `${n}px`,
      maxWidth: `${n}px`,
      height: "100%"
    };
  }
  const t = o ? 0 : e.height;
  return {
    ...i,
    width: "100%",
    height: `${t}px`,
    minHeight: `${t}px`,
    maxHeight: `${t}px`
  };
}, u = (e, o, i) => {
  const t = e[e.length - 1];
  if (t)
    return {
      overlay: !0,
      panel: t
    };
  const n = o[o.length - 1];
  return n ? {
    overlay: !1,
    panel: i(n)
  } : null;
}, F = ({ areaId: e, children: o, selected: i }) => {
  const t = S((g) => g.currentZindex), n = b(e), {
    centerColumnRef: P,
    handlePinnedResizeMove: f,
    handlePinnedResizeStart: p,
    isPinnedResizeActive: w,
    middleRowRef: R,
    pinnedResizeSession: v,
    resolvePinnedPanelRuntime: h,
    stopPinnedResize: x
  } = A(e), r = u(
    n.overlay.left,
    n.pinned.left,
    h
  ), a = u(
    n.overlay.top,
    n.pinned.top,
    h
  ), s = u(
    n.overlay.right,
    n.pinned.right,
    h
  ), d = u(
    n.overlay.bottom,
    n.pinned.bottom,
    h
  );
  return /* @__PURE__ */ c(z, { children: [
    /* @__PURE__ */ c(H, { ref: R, children: [
      r ? /* @__PURE__ */ l("div", { style: y(r.panel, r.overlay), children: /* @__PURE__ */ l(
        m,
        {
          areaId: e,
          panel: r.panel,
          panelZIndexBase: t,
          selected: i,
          overlay: r.overlay,
          onPinnedResizeStart: p
        },
        r.panel.windowId
      ) }) : null,
      /* @__PURE__ */ c(
        M,
        {
          "data-testid": "areas-panel-center-column",
          ref: P,
          children: [
            a ? /* @__PURE__ */ l("div", { style: y(a.panel, a.overlay), children: /* @__PURE__ */ l(
              m,
              {
                areaId: e,
                panel: a.panel,
                panelZIndexBase: t,
                selected: i,
                overlay: a.overlay,
                onPinnedResizeStart: p
              },
              a.panel.windowId
            ) }) : null,
            /* @__PURE__ */ l(
              $,
              {
                "data-testid": "areas-main-layout-flow",
                ownerState: { isResizingPanel: w },
                children: o
              },
              "areas-main-layout-flow"
            ),
            d ? /* @__PURE__ */ l("div", { style: y(d.panel, d.overlay), children: /* @__PURE__ */ l(
              m,
              {
                areaId: e,
                panel: d.panel,
                panelZIndexBase: t,
                selected: i,
                overlay: d.overlay,
                onPinnedResizeStart: p
              },
              d.panel.windowId
            ) }) : null
          ]
        },
        "areas-panel-center-column"
      ),
      s ? /* @__PURE__ */ l("div", { style: y(s.panel, s.overlay), children: /* @__PURE__ */ l(
        m,
        {
          areaId: e,
          panel: s.panel,
          panelZIndexBase: t,
          selected: i,
          overlay: s.overlay,
          onPinnedResizeStart: p
        },
        s.panel.windowId
      ) }) : null
    ] }, "areas-panel-middle-row"),
    v ? /* @__PURE__ */ l(
      W,
      {
        side: v.panel.side,
        panelZIndexBase: t,
        onMouseMove: f,
        onMouseUp: x
      }
    ) : null
  ] });
};
export {
  F as AreaPanels
};
