import { jsx as e, jsxs as b, Fragment as V } from "react/jsx-runtime";
import k, { createContext as _r, forwardRef as v, useRef as K, useContext as lr, useEffect as wr } from "react";
import { a as hr, T as Y, P as mr, O as fr, C as yr, D as br, b as $r, R as gr } from "./index-CKCTy3ZL.mjs";
import { c as E } from "./bind-CU-R61T-.mjs";
import { c as q, B as R } from "./button-DBX_tvfJ.mjs";
import { a as W, D as X } from "./heading-gqtQNo5n.mjs";
import { l as vr } from "./chevron-left.es-UFhf3v35.mjs";
import { r as Dr } from "./close.es-BPmk2wkU.mjs";
import { V as G } from "./visually-hidden-BYFkJEp1.mjs";
import { R as Nr, V as Pr, S as Sr, T as Or } from "./index-B8Mazo6u.mjs";
const Q = _r(null), Er = "_slideUp_71yig_1", Ar = "_slideDown_71yig_1", Cr = "_slideInRight_71yig_1", xr = "_slideInLeft_71yig_1", Lr = "_slideOutRight_71yig_1", Mr = "_slideOutLeft_71yig_1", jr = "_fadeIn_71yig_1", Ur = "_fadeOut_71yig_1", Yr = {
  "purpur-drawer-content": "_purpur-drawer-content_71yig_1",
  slideUp: Er,
  slideDown: Ar,
  "purpur-drawer-content--left": "_purpur-drawer-content--left_71yig_21",
  "purpur-drawer-content--right": "_purpur-drawer-content--right_71yig_24",
  "purpur-drawer-content--fit-to-content": "_purpur-drawer-content--fit-to-content_71yig_27",
  slideInRight: Cr,
  slideInLeft: xr,
  slideOutRight: Lr,
  slideOutLeft: Mr,
  "purpur-drawer-content__content-container": "_purpur-drawer-content__content-container_71yig_63",
  "purpur-drawer-content__description": "_purpur-drawer-content__description_71yig_68",
  "purpur-drawer-overlay": "_purpur-drawer-overlay_71yig_79",
  fadeIn: jr,
  fadeOut: Ur
}, kr = {
  "purpur-drawer-container--header": "_purpur-drawer-container--header_1bcla_1",
  "purpur-drawer-container--body": "_purpur-drawer-container--body_1bcla_4",
  "purpur-drawer-container--sticky": "_purpur-drawer-container--sticky_1bcla_12",
  "purpur-drawer-container--footer": "_purpur-drawer-container--footer_1bcla_20"
}, Hr = E.bind(kr), I = "purpur-drawer-container", O = v(
  ({
    ["data-testid"]: r = "purpur-drawer-container",
    children: a,
    className: o,
    variant: n = "body",
    stickyFooter: s,
    ...u
  }, d) => {
    const i = Hr([
      I,
      {
        [`${I}--${n}`]: n,
        [`${I}--sticky`]: s
      },
      o
    ]);
    return /* @__PURE__ */ e("div", { className: i, "data-testid": r, ref: d, ...u, children: a });
  }
);
O.displayName = "DrawerContainer";
const Rr = {
  "purpur-drawer-frame": "_purpur-drawer-frame_1didd_1",
  "purpur-drawer-frame--without-back-button": "_purpur-drawer-frame--without-back-button_1didd_11",
  "purpur-drawer-frame__header": "_purpur-drawer-frame__header_1didd_11",
  "purpur-drawer-frame--with-back-button": "_purpur-drawer-frame--with-back-button_1didd_14",
  "purpur-drawer-frame--left": "_purpur-drawer-frame--left_1didd_18",
  "purpur-drawer-frame--right": "_purpur-drawer-frame--right_1didd_22",
  "purpur-drawer-frame--sticky-footer": "_purpur-drawer-frame--sticky-footer_1didd_33",
  "purpur-drawer-frame__body": "_purpur-drawer-frame__body_1didd_39",
  "purpur-drawer-frame--fit-to-content": "_purpur-drawer-frame--fit-to-content_1didd_43",
  "purpur-drawer-frame__footer": "_purpur-drawer-frame__footer_1didd_52",
  "purpur-drawer-frame__content-container": "_purpur-drawer-frame__content-container_1didd_55",
  "purpur-drawer-frame__content-container--no-footer": "_purpur-drawer-frame__content-container--no-footer_1didd_60"
}, Ir = {
  "purpur-drawer-handle": "_purpur-drawer-handle_3n0ew_1"
}, Vr = (r, a, o, n, s, u) => ({
  onPointerDown: (t) => {
    r.current = { y: t.clientY };
  },
  onPointerMove: (t) => {
    if (!r.current)
      return;
    const _ = t.clientY - r.current.y, w = !!a.current, m = Math.max(0, _), p = t.pointerType === "touch" ? 10 : 2, h = { y: m }, A = { originalEvent: t, delta: h };
    w ? (a.current = h, n(A)) : J(h, 0) ? (a.current = h, o(), t.target.setPointerCapture(t.pointerId)) : Math.abs(_) > p && (r.current = null);
  },
  onPointerUp: (t) => {
    const _ = a.current, w = t.target;
    if (w.hasPointerCapture(t.pointerId) && w.releasePointerCapture(t.pointerId), a.current = null, r.current = null, _) {
      const m = t.currentTarget, p = { originalEvent: t, delta: _ };
      J(_, 0) && _.y > 200 ? u(p) : s(), m.addEventListener("click", (h) => h.preventDefault(), {
        once: !0
      });
    }
  }
}), J = (r, a = 0) => Math.abs(r.y) > a, Tr = E.bind(Ir), zr = "purpur-drawer-handle", Z = v(
  ({
    ["data-testid"]: r = "purpur-drawer-handle",
    className: a,
    onSwipeStart: o,
    onSwipeMove: n,
    onSwipeCancel: s,
    onSwipeEnd: u,
    ...d
  }, i) => {
    const c = Tr([zr, a]), t = k.useRef(null), _ = k.useRef(null), { onPointerDown: w, onPointerMove: m, onPointerUp: p } = Vr(
      _,
      t,
      o,
      n,
      s,
      u
    );
    return /* @__PURE__ */ e(
      "div",
      {
        className: c,
        "data-testid": r,
        onPointerDown: w,
        onPointerMove: m,
        onPointerUp: p,
        ref: i,
        ...d
      }
    );
  }
);
Z.displayName = "DrawerHandle";
const Fr = {
  "purpur-drawer-header": "_purpur-drawer-header_1iujy_1",
  "purpur-drawer-header__row": "_purpur-drawer-header__row_1iujy_4",
  "purpur-drawer-header__row--with-back-button": "_purpur-drawer-header__row--with-back-button_1iujy_7",
  "purpur-drawer-header__left": "_purpur-drawer-header__left_1iujy_10",
  "purpur-drawer-header__right": "_purpur-drawer-header__right_1iujy_13",
  "purpur-drawer-header__close-button": "_purpur-drawer-header__close-button_1iujy_16",
  "purpur-drawer-header__back-button--only-icon": "_purpur-drawer-header__back-button--only-icon_1iujy_27"
}, N = E.bind(Fr), $ = "purpur-drawer-header", B = v(
  ({
    ["data-testid"]: r = "purpur-drawer-header",
    backButton: a,
    backButtonText: o,
    backButtonOnlyIcon: n,
    className: s,
    closeButtonAriaLabel: u,
    headerContent: d,
    onBackButtonClick: i,
    onCloseClick: c,
    title: t,
    ..._
  }, w) => {
    const m = N([$, s]), p = !!(a && o && i), h = c ? k.Fragment : hr;
    return /* @__PURE__ */ b("div", { className: m, "data-testid": r, ref: w, ..._, children: [
      /* @__PURE__ */ b(
        "div",
        {
          className: N([
            `${$}__row`,
            {
              [`${$}__row--with-back-button`]: p
            }
          ]),
          "data-testid": `${r}-row`,
          children: [
            /* @__PURE__ */ e("div", { className: N(`${$}__left`), children: p ? /* @__PURE__ */ b(
              q,
              {
                "aria-label": n ? o : "",
                className: N([
                  `${$}__back-button`,
                  {
                    [`${$}__back-button--only-icon`]: n
                  }
                ]),
                "data-testid": `${r}-back-button`,
                iconOnly: n,
                onClick: i,
                size: "sm",
                variant: n ? R.TERTIARY_PURPLE : R.TEXT,
                children: [
                  /* @__PURE__ */ e(vr, { size: "sm" }),
                  !n && o
                ]
              }
            ) : d ? /* @__PURE__ */ b(V, { children: [
              d,
              /* @__PURE__ */ e(G, { asChild: !0, children: /* @__PURE__ */ e(Y, { children: t }) })
            ] }) : /* @__PURE__ */ e(Y, { asChild: !0, children: /* @__PURE__ */ e(
              W,
              {
                "data-testid": `${r}-title`,
                tag: "h2",
                variant: X.DISPLAY10,
                tabIndex: -1,
                children: t
              }
            ) }) }),
            /* @__PURE__ */ e("div", { className: N(`${$}__right`), children: /* @__PURE__ */ e(h, { ...c ? {} : { asChild: !0 }, children: /* @__PURE__ */ e(
              q,
              {
                "aria-label": u,
                className: N(`${$}__close-button`),
                iconOnly: !0,
                onClick: c,
                size: "sm",
                variant: R.TERTIARY_PURPLE,
                children: /* @__PURE__ */ e(Dr, { size: "sm" })
              }
            ) }) })
          ]
        }
      ),
      p && (d ? /* @__PURE__ */ b(V, { children: [
        d,
        /* @__PURE__ */ e(G, { asChild: !0, children: /* @__PURE__ */ e(Y, { children: t }) })
      ] }) : /* @__PURE__ */ e(Y, { asChild: !0, children: /* @__PURE__ */ e(
        W,
        {
          "data-testid": `${r}-title-with-back-button`,
          tag: "h2",
          tabIndex: -1,
          variant: X.DISPLAY10,
          children: t
        }
      ) }))
    ] });
  }
);
B.displayName = "DrawerHeader";
const Kr = {
  "purpur-drawer-scroll-area__root": "_purpur-drawer-scroll-area__root_1hyos_1",
  "purpur-drawer-scroll-area__root--fit-to-content": "_purpur-drawer-scroll-area__root--fit-to-content_1hyos_4",
  "purpur-drawer-scroll-area__viewport": "_purpur-drawer-scroll-area__viewport_1hyos_10",
  "purpur-drawer-scroll-area__scrollbar": "_purpur-drawer-scroll-area__scrollbar_1hyos_14",
  "purpur-drawer-scroll-area__thumb": "_purpur-drawer-scroll-area__thumb_1hyos_25"
}, x = E.bind(Kr), P = "purpur-drawer-scroll-area", T = v(
  ({
    ["data-testid"]: r = "purpur-drawer-scroll-area",
    children: a,
    className: o,
    fitToContent: n = !1,
    ...s
  }, u) => {
    const d = x([P, o]);
    return /* @__PURE__ */ e("div", { className: d, "data-testid": r, ref: u, ...s, children: /* @__PURE__ */ b(
      Nr,
      {
        className: x(`${P}__root`, {
          [`${P}__root--fit-to-content`]: n
        }),
        children: [
          /* @__PURE__ */ e(Pr, { className: x(`${P}__viewport`), children: a }),
          /* @__PURE__ */ e(
            Sr,
            {
              className: x(`${P}__scrollbar`),
              orientation: "vertical",
              children: /* @__PURE__ */ e(Or, { className: x(`${P}__thumb`) })
            }
          )
        ]
      }
    ) });
  }
);
T.displayName = "DrawerScrollArea";
const S = E.bind(Rr), l = "purpur-drawer-frame", rr = v(
  ({
    ["data-testid"]: r = "purpur-drawer-frame",
    backButton: a,
    backButtonText: o,
    backButtonOnlyIcon: n,
    children: s,
    className: u,
    closeButtonAriaLabel: d,
    fitToContent: i = !1,
    footerContent: c,
    headerContent: t,
    onBackButtonClick: _,
    onCloseClick: w,
    onSwipeStart: m,
    onSwipeMove: p,
    onSwipeCancel: h,
    onSwipeEnd: A,
    title: M,
    stickyFooter: y,
    position: j = "right",
    ...D
  }, H) => {
    const C = !!(a && o && _), U = S([
      l,
      {
        [`${l}--fit-to-content`]: i,
        [`${l}--sticky-footer`]: y,
        [`${l}--left`]: j === "left",
        [`${l}--right`]: j === "right",
        [`${l}--without-back-button`]: !C,
        [`${l}--with-back-button`]: C
      },
      u
    ]);
    return /* @__PURE__ */ b("div", { className: U, "data-testid": r, ref: H, ...D, children: [
      /* @__PURE__ */ e(
        Z,
        {
          onSwipeStart: m,
          onSwipeMove: p,
          onSwipeCancel: h,
          onSwipeEnd: A
        }
      ),
      /* @__PURE__ */ e(
        O,
        {
          className: S(`${l}__header`),
          variant: "header",
          stickyFooter: y,
          children: /* @__PURE__ */ e(
            B,
            {
              title: M,
              headerContent: t,
              backButtonOnlyIcon: n,
              backButton: a,
              backButtonText: o,
              closeButtonAriaLabel: d,
              onBackButtonClick: _,
              onCloseClick: w
            }
          )
        }
      ),
      y ? /* @__PURE__ */ b(V, { children: [
        /* @__PURE__ */ e(
          T,
          {
            className: S(`${l}__body`),
            "data-testid": `${r}-sticky-footer-scroll-area`,
            fitToContent: i,
            children: /* @__PURE__ */ e(O, { stickyFooter: !0, children: s })
          }
        ),
        c && /* @__PURE__ */ e(
          O,
          {
            className: S(`${l}__footer`),
            "data-testid": `${r}-sticky-footer`,
            variant: "footer",
            stickyFooter: y,
            children: c
          }
        )
      ] }) : /* @__PURE__ */ e(
        T,
        {
          className: S(`${l}__body`),
          "data-testid": `${r}-scroll-area`,
          fitToContent: i,
          children: /* @__PURE__ */ b(
            "div",
            {
              className: S([
                `${l}__content-container`,
                { [`${l}__content-container--no-footer`]: !c }
              ]),
              children: [
                /* @__PURE__ */ e(O, { stickyFooter: y, children: s }),
                c && /* @__PURE__ */ e(
                  O,
                  {
                    "data-testid": `${r}-footer`,
                    stickyFooter: y,
                    variant: "footer",
                    children: c
                  }
                )
              ]
            }
          )
        }
      )
    ] });
  }
);
rr.displayName = "DrawerFrame";
const qr = (r, a) => ({
  onSwipeStart: () => {
    r.current && r.current.setAttribute("data-swipe", "start");
  },
  onSwipeMove: (d) => {
    if (!r.current)
      return;
    const { y: i } = d.delta;
    r.current.setAttribute("data-swipe", "move"), r.current.style.setProperty("--purpur-drawer-swipe-move-y", `${i}px`);
  },
  onSwipeCancel: () => {
    r.current && (r.current.setAttribute("data-swipe", "cancel"), r.current.style.removeProperty("--purpur-drawer-swipe-move-y"), r.current.style.removeProperty("--purpur-drawer-swipe-end-y"));
  },
  onSwipeEnd: (d) => {
    if (!r.current)
      return;
    const { y: i } = d.delta;
    r.current.setAttribute("data-swipe", "end"), r.current.style.removeProperty("--purpur-drawer-swipe-move-y"), r.current.style.setProperty("--purpur-drawer-swipe-end-y", `${i}px`), a?.(!1);
  }
}), L = E.bind(Yr), g = "purpur-drawer-content", er = v(
  ({
    ["data-testid"]: r = "purpur-drawer-content",
    backButton: a = !1,
    backButtonText: o,
    backButtonOnlyIcon: n = !1,
    bodyText: s,
    children: u,
    className: d,
    closeButtonAriaLabel: i,
    disableCloseOnClickOutside: c = !1,
    fitToContent: t = !1,
    footerContent: _,
    headerContent: w,
    onBackButtonClick: m,
    onCloseClick: p,
    stickyFooter: h = !1,
    title: A,
    zIndex: M,
    position: y = "right",
    ...j
  }, D) => {
    const H = L([
      g,
      {
        [`${g}--fit-to-content`]: t,
        [`${g}--left`]: y === "left",
        [`${g}--right`]: y === "right"
      },
      d
    ]), C = K(null), U = K(null), ar = (f) => {
      U.current = f, typeof D == "function" ? D(f) : D && (D.current = f);
    }, nr = lr(Q), { onSwipeStart: or, onSwipeMove: sr, onSwipeCancel: dr, onSwipeEnd: ir } = qr(
      U,
      nr
    ), ur = (f) => {
      if (c) {
        f.preventDefault();
        return;
      }
      p && (f.preventDefault(), p());
    }, cr = (f) => {
      p && (f.preventDefault(), p());
    }, pr = () => {
      const f = C.current;
      if (f) {
        const F = f.querySelector("h2");
        F && setTimeout(() => {
          F.focus();
        });
      }
    };
    return /* @__PURE__ */ e(mr, { children: /* @__PURE__ */ e(
      fr,
      {
        className: L("purpur-drawer-overlay"),
        style: M ? { zIndex: M } : void 0,
        "data-testid": `${r}-overlay`,
        children: /* @__PURE__ */ e(
          yr,
          {
            onPointerDownOutside: ur,
            onEscapeKeyDown: cr,
            onOpenAutoFocus: pr,
            className: H,
            "data-testid": r,
            ref: ar,
            ...!s && { "aria-describedby": void 0 },
            ...j,
            children: /* @__PURE__ */ e(
              rr,
              {
                backButton: a,
                backButtonText: o,
                backButtonOnlyIcon: n,
                closeButtonAriaLabel: i,
                className: L(`${g}__drawer-frame`),
                fitToContent: t,
                footerContent: _,
                headerContent: w,
                ref: C,
                onBackButtonClick: m,
                onCloseClick: p,
                onSwipeStart: or,
                onSwipeMove: sr,
                onSwipeCancel: dr,
                onSwipeEnd: ir,
                stickyFooter: h,
                title: A,
                position: y,
                children: s ? /* @__PURE__ */ b("div", { className: L(`${g}__content-container`), children: [
                  /* @__PURE__ */ e(
                    br,
                    {
                      className: L(`${g}__description`),
                      "data-testid": `${r}-description`,
                      children: s
                    }
                  ),
                  /* @__PURE__ */ e("div", { children: u })
                ] }) : u
              }
            )
          }
        )
      }
    ) });
  }
);
er.displayName = "DrawerContent";
const tr = v(
  ({ ["data-testid"]: r = "purpur-drawer-trigger", children: a, ...o }, n) => /* @__PURE__ */ e($r, { asChild: !0, "data-testid": r, ref: n, ...o, children: a })
);
tr.displayName = "DrawerTrigger";
const z = ({
  ["data-testid"]: r = "purpur-drawer",
  children: a,
  className: o,
  onOpenChange: n,
  open: s = !1,
  ...u
}) => {
  const [d, i] = k.useState(s), c = (t) => {
    i(t), n?.(t);
  };
  return wr(() => {
    i(s);
  }, [s]), /* @__PURE__ */ e(Q.Provider, { value: c, children: /* @__PURE__ */ e("div", { className: o, "data-testid": r, ...u, children: /* @__PURE__ */ e(gr, { open: d, onOpenChange: c, children: a }) }) });
};
z.Trigger = tr;
z.Content = er;
z.displayName = "Drawer";
export {
  z as D
};
//# sourceMappingURL=drawer-Boqmgh-i.mjs.map
