import { jsxs as s, jsx as t } from "react/jsx-runtime";
import { P as k, O as q, C as G, T as J, D as O, a as Q, b as X, R as Y } from "./index-CKCTy3ZL.mjs";
import { forwardRef as M, useState as P, useRef as b, useCallback as Z, useEffect as g } from "react";
import { c as tt } from "./button-DBX_tvfJ.mjs";
import { a as et } from "./heading-gqtQNo5n.mjs";
import { r as rt } from "./close.es-BPmk2wkU.mjs";
import { a as ot } from "./paragraph-DNtj7OLr.mjs";
import { V as nt } from "./visually-hidden-BYFkJEp1.mjs";
import { c as at } from "./bind-CU-R61T-.mjs";
const lt = "_fadeIn_slvdi_1", st = "_fadeOut_slvdi_1", dt = "_slideUp_slvdi_1", it = "_slideDown_slvdi_1", _t = {
  "purpur-modal-content": "_purpur-modal-content_slvdi_1",
  fadeIn: lt,
  fadeOut: st,
  slideUp: dt,
  slideDown: it,
  "purpur-modal-content__overlay": "_purpur-modal-content__overlay_slvdi_49",
  "purpur-modal-content__close-button": "_purpur-modal-content__close-button_slvdi_65",
  "purpur-modal-content__wrapper": "_purpur-modal-content__wrapper_slvdi_75",
  "purpur-modal-content__wrapper-inner": "_purpur-modal-content__wrapper-inner_slvdi_85",
  "purpur-modal-content__image-wrapper": "_purpur-modal-content__image-wrapper_slvdi_89",
  "purpur-modal-content__header": "_purpur-modal-content__header_slvdi_112",
  "purpur-modal-content__title": "_purpur-modal-content__title_slvdi_125",
  "purpur-modal-content__description": "_purpur-modal-content__description_slvdi_128",
  "purpur-modal-content__body": "_purpur-modal-content__body_slvdi_131",
  "purpur-modal-content__body-inner": "_purpur-modal-content__body-inner_slvdi_139",
  "purpur-modal-content__actions-buttons": "_purpur-modal-content__actions-buttons_slvdi_151",
  "purpur-modal-content__notification": "_purpur-modal-content__notification_slvdi_169",
  "purpur-modal-content--with-image": "_purpur-modal-content--with-image_slvdi_172",
  "purpur-modal-content--overflow": "_purpur-modal-content--overflow_slvdi_172",
  "purpur-modal-content__actions": "_purpur-modal-content__actions_slvdi_151",
  "purpur-modal-content__actions-separator": "_purpur-modal-content__actions-separator_slvdi_203",
  "purpur-modal-content--sticky-footer": "_purpur-modal-content--sticky-footer_slvdi_213"
}, R = (o) => o.showCloseButton === !0, r = at.bind(_t), e = "purpur-modal-content", ct = M(
  ({
    ["data-testid"]: o,
    actions: n,
    children: a,
    className: _,
    description: c,
    disableCloseOnClickOutside: C,
    hideDescription: N,
    image: u,
    stickyButtons: f = !0,
    title: E,
    notification: w = void 0,
    zIndex: D,
    onCloseAutoFocus: H,
    ...y
  }, S) => {
    const { closeButtonAriaLabel: m, showCloseButton: T, ...B } = y, [V, W] = P(!1), [z, A] = P(0), p = b(null), v = b(null), F = r(
      e,
      { [`${e}--with-image`]: !!u },
      { [`${e}--overflow`]: V },
      { [`${e}--sticky-footer`]: f },
      _
    ), d = (l) => o ? `${o} ${l}` : void 0, L = (l) => {
      C && l.preventDefault();
    }, i = Z(() => {
      if (!p.current || !v.current)
        return;
      const l = window.getComputedStyle(p.current, null), h = parseFloat(l.getPropertyValue("height")), K = v.current.offsetHeight;
      W(h < K), A(
        (p.current.offsetWidth ?? 0) - (p.current.clientWidth ?? 0)
      );
    }, []), U = () => {
      const l = v.current;
      if (l) {
        const h = l.querySelector("h2");
        h && setTimeout(() => {
          h.focus();
        });
      }
    }, j = (l) => {
      C && !T && l.preventDefault();
    };
    return g(() => (window.addEventListener("resize", i), () => {
      window.removeEventListener("resize", i);
    }), [i]), g(() => {
      i();
    }, [w, a, i]), /* @__PURE__ */ s(k, { children: [
      /* @__PURE__ */ t(q, { className: r(`${e}__overlay`), style: { zIndex: D } }),
      /* @__PURE__ */ s(
        G,
        {
          ...B,
          className: F,
          "data-testid": o,
          ref: S,
          ...!c && { "aria-describedby": void 0 },
          onPointerDownOutside: L,
          onOpenAutoFocus: () => {
            i(), U();
          },
          onEscapeKeyDown: j,
          onCloseAutoFocus: H,
          style: { zIndex: `calc(${D} + 1)` },
          children: [
            /* @__PURE__ */ s("div", { ref: p, className: r(`${e}__wrapper`), children: [
              R(y) && m && u && /* @__PURE__ */ t(
                x,
                {
                  "aria-label": m,
                  hasImage: !0,
                  scrollbarWidth: z,
                  "data-testid": d("close-button")
                }
              ),
              /* @__PURE__ */ s("div", { ref: v, className: r(`${e}__wrapper-inner`), children: [
                /* @__PURE__ */ s("div", { className: r(`${e}__header`), children: [
                  R(y) && m && !u && /* @__PURE__ */ t(
                    x,
                    {
                      "aria-label": m,
                      "data-testid": d("close-button")
                    }
                  ),
                  /* @__PURE__ */ t(
                    J,
                    {
                      asChild: !0,
                      className: r(`${e}__title`),
                      "data-testid": d("title"),
                      children: /* @__PURE__ */ t(et, { tag: "h2", variant: "title-200", tabIndex: -1, children: E })
                    }
                  )
                ] }),
                u && /* @__PURE__ */ t(
                  "div",
                  {
                    className: r(`${e}__image-wrapper`),
                    "data-testid": d("image"),
                    children: u
                  }
                ),
                /* @__PURE__ */ t("div", { className: r(`${e}__body`), children: /* @__PURE__ */ s("div", { className: r(`${e}__body-inner`), children: [
                  c && N && /* @__PURE__ */ t(nt, { asChild: !0, children: /* @__PURE__ */ t(O, { "data-testid": d("description"), children: c }) }),
                  c && !N && /* @__PURE__ */ t(
                    O,
                    {
                      asChild: !0,
                      className: r(`${e}__description`),
                      "data-testid": d("description"),
                      children: /* @__PURE__ */ t(ot, { variant: "paragraph-100", children: c })
                    }
                  ),
                  /* @__PURE__ */ t("div", { children: a }),
                  !f && /* @__PURE__ */ t(I, { actions: n, notification: w })
                ] }) })
              ] })
            ] }),
            f && /* @__PURE__ */ t(I, { actions: n, notification: w })
          ]
        }
      )
    ] });
  }
), x = ({
  ["aria-label"]: o,
  hasImage: n,
  scrollbarWidth: a,
  ["data-testid"]: _
}) => /* @__PURE__ */ t(Q, { asChild: !0, children: /* @__PURE__ */ t(
  tt,
  {
    variant: n ? "primary" : "tertiary-purple",
    negative: n,
    size: "sm",
    iconOnly: !0,
    "aria-label": o,
    className: r(`${e}__close-button`),
    style: { right: `calc(var(--purpur-spacing-100) + ${a || 0}px)` },
    "data-testid": _,
    children: /* @__PURE__ */ t(rt, {})
  }
) }), I = ({
  actions: o,
  notification: n
}) => {
  const a = b(null);
  return g(() => {
    n && a?.current?.scrollIntoView?.(!1);
  }, [n]), o ? /* @__PURE__ */ s("div", { className: r(`${e}__actions`), children: [
    /* @__PURE__ */ t("div", { className: r(`${e}__actions-buttons`), "data-testid": "modal actions", children: o }),
    n && /* @__PURE__ */ t("div", { className: r(`${e}__notification`), ref: a, children: n }),
    /* @__PURE__ */ t("span", { className: r(`${e}__actions-separator`) })
  ] }) : null;
}, ut = M(
  ({ children: o, ...n }, a) => /* @__PURE__ */ t(X, { asChild: !0, ref: a, ...n, children: o })
), $ = ({
  ["data-testid"]: o,
  children: n,
  open: a,
  onOpenChange: _
}) => /* @__PURE__ */ t(Y, { open: a, onOpenChange: _, "data-testid": o, children: n });
$.Trigger = ut;
$.Content = ct;
$.displayName = "Modal";
export {
  $ as M
};
//# sourceMappingURL=modal-C2UQsW-g.mjs.map
