import { jsxs as m, Fragment as N, jsx as n } from "react/jsx-runtime";
import { useState as i, useRef as J, useMemo as Q, useCallback as S, useEffect as T } from "react";
import { c as U, s as W, a as X } from "../tools/tools.js";
import { O as H } from "./offcanvas-backdrop.js";
import { O as L } from "./offcanvas-body.js";
import { O as P } from "./offcanvas-header.js";
import { O as j } from "./offcanvas-title.js";
const t = function(K) {
  const {
    as: R = "div",
    backdrop: p = !0,
    body: v,
    bodyProps: V,
    className: u,
    dropOldClass: h,
    fade: $ = !0,
    header: b,
    headerProps: F,
    onChange: e,
    placement: l,
    responsive: c,
    scroll: M,
    style: O,
    title: y,
    titleProps: _,
    variables: g,
    visible: f = !1,
    ...q
  } = K, [o, d] = i(f), k = J(null), [w, C] = i(!1), [x, B] = i(!1), [r, E] = i(!1), z = Q(() => {
    const s = U(
      !h && (c ? `offcanvas-${c}` : "offcanvas"),
      l && `offcanvas-${l}`,
      w && "showing",
      x && "hiding",
      r && "show",
      u
    ), a = W((Z, I) => ({ tKey: X(I) }), g, O);
    return {
      className: s,
      style: a
    };
  }, [u, h, x, l, c, r, w, O, g]), A = S(
    (s) => {
      d(!1), e == null || e(!1, s);
    },
    [e]
  ), G = S(
    (s, a) => {
      d(s), e == null || e(s, a);
    },
    [e]
  );
  return T(() => {
    const s = k.current;
    if (!s)
      return;
    const a = () => {
      o ? C(!1) : B(!1);
    };
    return s.addEventListener("transitionend", a), o ? (E(!0), C(!0)) : r && (E(!1), B(!0)), () => s.removeEventListener("transitionend", a);
  }, [r, o]), T(() => {
    d(f);
  }, [f]), /* @__PURE__ */ m(N, { children: [
    /* @__PURE__ */ m(R, { ...q, ...z, ref: k, children: [
      b || (y ? /* @__PURE__ */ m(P, { ...F, children: [
        /* @__PURE__ */ n(j, { ..._, children: y }),
        /* @__PURE__ */ n(
          "button",
          {
            "aria-label": "Close",
            className: "btn-close",
            "data-bs-dismiss": "offcanvas",
            onClick: A,
            type: "button"
          }
        )
      ] }) : /* @__PURE__ */ n(N, {})),
      v && /* @__PURE__ */ n(L, { ...V, children: v })
    ] }),
    p && /* @__PURE__ */ n(
      H,
      {
        backdrop: p,
        fade: $,
        onChange: G,
        scroll: M,
        visible: o
      }
    )
  ] });
};
t.Header = P;
t.Title = j;
t.Body = L;
t.Backdrop = H;
t.displayName = "BRL.Offcanvas";
export {
  t as O
};
//# sourceMappingURL=offcanvas.js.map
