import { WithElement as S, OnDispose as z, prop as R, computedOf as w, Fragment as M, attr as g, WithBrowserCtx as J, Value as U, render as Q, html as k, dataAttr as B, aria as V, on as X, When as q, Use as H, coalesce as I } from "@tempots/dom";
import { g as $, T as _ } from "./timer-DzWb416P.js";
import { s as Y, C as Z } from "./notice-CTONCH2t.js";
import { a as K, B as P } from "./translations-BUTBIDsS.js";
const ee = [
  "a[href]",
  "button:not([disabled])",
  "input:not([disabled])",
  "select:not([disabled])",
  "textarea:not([disabled])",
  '[tabindex]:not([tabindex="-1"])',
  '[contenteditable="true"]',
  "audio[controls]",
  "video[controls]",
  "details > summary:first-of-type",
  "details[open]"
].join(", ");
function te(o) {
  return Array.from(o.querySelectorAll(ee)).filter(
    (t) => {
      const s = t;
      return s.offsetWidth > 0 && s.offsetHeight > 0 && !s.hasAttribute("inert") && window.getComputedStyle(s).visibility !== "hidden";
    }
  );
}
function F(o = {}) {
  const {
    active: t = !0,
    escapeDeactivates: s = !0,
    onEscape: e,
    initialFocus: n,
    returnFocus: r,
    clickOutsideDeactivates: a = !1,
    onClickOutside: u
  } = o;
  return S((m) => {
    let f = t, p = null, c = [];
    typeof document < "u" && (p = document.activeElement);
    const v = () => {
      c = te(m);
    }, b = (l) => {
      if (f) {
        if (s && l.key === "Escape") {
          l.preventDefault(), e?.();
          return;
        }
        if (l.key === "Tab") {
          if (v(), c.length === 0) {
            l.preventDefault();
            return;
          }
          const i = c.indexOf(
            document.activeElement
          );
          l.shiftKey ? i <= 0 && (l.preventDefault(), c[c.length - 1]?.focus()) : i >= c.length - 1 && (l.preventDefault(), c[0]?.focus());
        }
      }
    }, h = (l) => {
      if (!f || !a) return;
      const i = l.target;
      m.contains(i) || u?.();
    }, y = () => {
      if (!f) return;
      v();
      let l = null;
      typeof n == "function" ? l = n() : n ? l = n : c.length > 0 && (l = c[0]), l && setTimeout(() => {
        l?.focus();
      }, 50), document.addEventListener("keydown", b, !0), a && document.addEventListener("click", h, !0);
    }, x = () => {
      f = !1, document.removeEventListener("keydown", b, !0), document.removeEventListener("click", h, !0);
      let l = null;
      typeof r == "function" ? l = r() : r ? l = r : p && (l = p), l && document.body.contains(l) && setTimeout(() => {
        l?.focus();
      }, 0);
    };
    return setTimeout(() => y(), 0), z(() => {
      x();
    });
  });
}
function pe(o = {}) {
  return {
    activate: () => F({ ...o, active: !0 }),
    deactivate: () => F({ ...o, active: !1 })
  };
}
function N({
  initialStatus: o = "closed",
  openedAfter: t,
  closedAfter: s
}) {
  const e = R(o), n = () => {
    e.set("start-opening");
  }, r = () => {
    e.set("start-closing");
  }, a = e.map(
    (i) => i !== "closed" && i !== "start-closing" && i !== "closing"
  ), u = (i) => {
    i ? n() : r();
  }, m = () => {
    u(!a.value);
  }, f = [], p = (i) => {
    f.push(
      e.on((T) => {
        T === "closed" && i();
      })
    );
  };
  let c = () => {
  };
  e.on((i) => {
    switch (c(), i) {
      case "start-opening":
        c = $(() => e.set("opening"));
        break;
      case "opening":
        c = t(() => e.set("opened"));
        break;
      case "start-closing":
        c = $(() => e.set("closing"));
        break;
      case "closing":
        c = s(() => e.set("closed"));
        break;
      case "closed":
        c = () => {
        };
        break;
    }
  }), e.onDispose(() => {
    f.forEach((i) => i()), c();
  });
  const v = e.map((i) => i === "closed"), b = e.map((i) => i === "start-opening"), h = e.map((i) => i === "opening"), y = e.map((i) => i === "opened"), x = e.map((i) => i === "closing"), l = e.map((i) => i === "start-closing");
  return {
    status: e,
    open: n,
    close: r,
    toggle: m,
    setOpen: u,
    display: a,
    isClosed: v,
    isStartOpening: b,
    isOpening: h,
    isOpened: y,
    isClosing: x,
    isStartClosing: l,
    dispose: () => e.dispose(),
    listenOnClosed: p
  };
}
function he({
  initialStatus: o = "closed",
  duration: t,
  openDuration: s = t ?? 500,
  closeDuration: e = t ?? 500
} = {}) {
  return N({
    initialStatus: o,
    openedAfter: (n) => _(n, s),
    closedAfter: (n) => _(n, e)
  });
}
function W(o, t) {
  let s = !1, e = null;
  function n() {
    s || (s = !0, o.removeEventListener("transitionend", r), o.removeEventListener("animationend", a), e && (clearTimeout(e), e = null), t());
  }
  function r(f) {
    f.target === o && n();
  }
  function a(f) {
    f.target === o && n();
  }
  const m = $(() => {
    if (typeof o.getAnimations > "u") {
      e = setTimeout(n, 16);
      return;
    }
    o.addEventListener("transitionend", r), o.addEventListener("animationend", a), o.getAnimations().length === 0 && (e = setTimeout(n, 1e3));
  });
  return () => {
    s = !0, m(), e && (clearTimeout(e), e = null), o.removeEventListener("transitionend", r), o.removeEventListener("animationend", a);
  };
}
function G({
  initialStatus: o = "closed",
  element: t
} = {}) {
  let s = t;
  return {
    setElement: (e) => {
      s = e;
    },
    ...N({
      initialStatus: o,
      openedAfter: (e) => s == null ? (e(), () => {
      }) : W(s, e),
      closedAfter: (e) => s == null ? (e(), () => {
      }) : W(s, e)
    })
  };
}
function se(o) {
  if (o == null) return "";
  const t = [];
  return o.fade && t.push("fade"), o.slide && t.push(`slide-${o.slide}`), o.scale != null && t.push("scale"), t.length > 0 ? t.join(" ") : "none";
}
function ne(o) {
  if (o == null) return "";
  const t = [];
  return o.scale != null && typeof o.scale == "number" && t.push(`--scale-factor: ${o.scale}`), o.transformOrigin != null && t.push(`--transform-origin: ${o.transformOrigin}`), o.duration != null && t.push(`--animation-duration: ${o.duration}ms`), o.easing != null && t.push(`--animation-easing: ${o.easing}`), t.join("; ");
}
function oe({
  animation: o,
  status: t
}) {
  const s = w(
    o,
    t
  )((n, r) => {
    if (n == null)
      return `bc-animated-toggle bc-animated-toggle--${r}`;
    const a = r === "start-opening" || r === "opening" || r === "opened";
    let u;
    return "enter" in n || "exit" in n ? u = a ? n.enter : n.exit : u = n, `bc-animated-toggle bc-animated-toggle--${se(u)} bc-animated-toggle--${r}`;
  }), e = w(
    o,
    t
  )((n, r) => {
    if (n == null) return "";
    const a = r === "start-opening" || r === "opening" || r === "opened";
    let u;
    return "enter" in n || "exit" in n ? u = a ? n.enter : n.exit : u = n, ne(u);
  });
  return M(g.class(s), g.style(e));
}
function ge({
  initialStatus: o = "closed",
  animation: t
}, s) {
  return S((e) => {
    const { setElement: n, dispose: r, ...a } = G({
      initialStatus: o,
      element: e
    });
    return n(e), M(
      oe({ status: a.status, animation: t }),
      z(r),
      s(a)
    );
  });
}
function re(o) {
  return {
    "~standard": {
      version: 1,
      vendor: "beatui-custom",
      validate: (s) => {
        const e = o.validate(s);
        return e.success ? { value: e.data } : {
          issues: e.errors.map((n) => ({
            message: n.message,
            path: n.path
          }))
        };
      },
      types: void 0
    },
    safeParse: (s) => {
      const e = o.validate(s);
      return e.success ? { success: !0, data: e.data } : {
        success: !1,
        error: {
          errors: e.errors.map((n) => ({
            message: n.message,
            path: n.path?.map(
              (r) => typeof r == "object" && "key" in r ? r.key.toString() : r.toString()
            ) || []
          }))
        }
      };
    }
  };
}
class A {
  optional() {
    return new ae(this);
  }
  default(t) {
    return new ie(this, t);
  }
  schema() {
    return re(this);
  }
}
class C extends A {
  minLength;
  maxLength;
  pattern;
  customValidations = [];
  validate(t) {
    if (typeof t != "string")
      return { success: !1, errors: [{ message: "Expected string" }] };
    const s = [];
    this.minLength !== void 0 && t.length < this.minLength && s.push({ message: `Must be at least ${this.minLength} characters` }), this.maxLength !== void 0 && t.length > this.maxLength && s.push({ message: `Must be at most ${this.maxLength} characters` }), this.pattern && !this.pattern.test(t) && s.push({ message: "Invalid format" });
    for (const e of this.customValidations) {
      const n = e(t);
      n && s.push({ message: n });
    }
    return s.length > 0 ? { success: !1, errors: s } : { success: !0, data: t };
  }
  min(t, s) {
    const e = new C();
    return e.minLength = t, e.maxLength = this.maxLength, e.pattern = this.pattern, e.customValidations = [...this.customValidations], s && e.customValidations.push(
      (n) => n.length < t ? s : null
    ), e;
  }
  max(t, s) {
    const e = new C();
    return e.minLength = this.minLength, e.maxLength = t, e.pattern = this.pattern, e.customValidations = [...this.customValidations], s && e.customValidations.push(
      (n) => n.length > t ? s : null
    ), e;
  }
  regex(t, s) {
    const e = new C();
    return e.minLength = this.minLength, e.maxLength = this.maxLength, e.pattern = t, e.customValidations = [...this.customValidations], s && e.customValidations.push(
      (n) => t.test(n) ? null : s
    ), e;
  }
  email(t = "Please enter a valid email address") {
    const s = /^[^\s@]+@[^\s@]+\.[^\s@]+$/, e = new C();
    return e.minLength = this.minLength, e.maxLength = this.maxLength, e.pattern = this.pattern, e.customValidations = [
      ...this.customValidations,
      (n) => s.test(n) ? null : t
    ], e;
  }
  refine(t) {
    const s = new C();
    return s.minLength = this.minLength, s.maxLength = this.maxLength, s.pattern = this.pattern, s.customValidations = [...this.customValidations, t], s;
  }
}
class O extends A {
  mustBeTrue = !1;
  trueMessage;
  validate(t) {
    return typeof t != "boolean" ? { success: !1, errors: [{ message: "Expected boolean" }] } : this.mustBeTrue && t !== !0 ? {
      success: !1,
      errors: [{ message: this.trueMessage || "Must be true" }]
    } : { success: !0, data: t };
  }
  refine(t, s) {
    const e = new O();
    e.mustBeTrue = this.mustBeTrue, e.trueMessage = this.trueMessage;
    const n = e.validate.bind(e);
    return e.validate = (r) => {
      const a = n(r);
      return a.success ? t(a.data) ? a : { success: !1, errors: [{ message: s }] } : a;
    }, e;
  }
  literal(t, s) {
    const e = new O();
    return e.mustBeTrue = !0, e.trueMessage = s, e;
  }
}
class ae extends A {
  constructor(t) {
    super(), this.inner = t;
  }
  validate(t) {
    if (t === void 0)
      return { success: !0, data: void 0 };
    const s = this.inner.validate(t);
    return s.success ? { success: !0, data: s.data } : { success: !1, errors: s.errors };
  }
}
class ie extends A {
  constructor(t, s) {
    super(), this.inner = t, this.defaultValue = s;
  }
  validate(t) {
    return t === void 0 ? { success: !0, data: this.defaultValue } : this.inner.validate(t);
  }
}
class D extends A {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  constructor(t) {
    super(), this.shape = t;
  }
  validate(t) {
    if (typeof t != "object" || t === null || Array.isArray(t))
      return { success: !1, errors: [{ message: "Expected object" }] };
    const s = t, e = {}, n = [];
    for (const [r, a] of Object.entries(this.shape)) {
      const u = a.validate(s[r]);
      if (u.success)
        e[r] = u.data;
      else
        for (const m of u.errors)
          n.push({
            message: m.message,
            path: [r, ...m.path || []]
          });
    }
    return n.length > 0 ? { success: !1, errors: n } : { success: !0, data: e };
  }
  refine(t, s) {
    const e = new D(this.shape), n = e.validate.bind(e);
    return e.validate = (r) => {
      const a = n(r);
      if (!a.success) return a;
      const u = t(a.data);
      return u ? {
        success: !1,
        errors: [
          {
            message: u,
            path: s?.path
          }
        ]
      } : { success: !0, data: a.data };
    }, e;
  }
}
const be = () => new C(), ve = () => new O(), ye = (o) => new D(o);
function ce(o) {
  return J((t) => {
    const s = [], e = () => s.forEach((r) => r());
    return o(({
      effect: r = "opaque",
      mode: a = "capturing",
      onClickOutside: u,
      onEscape: m,
      content: f,
      container: p = "body"
    }) => {
      p === "body" && (t = t.makePortal("body"));
      const c = G();
      c.listenOnClosed(e);
      let v = () => {
      }, b = () => {
      };
      const h = (E) => {
        E.key === "Escape" && (m?.(), c.close());
      }, y = () => {
        u?.(), c.close();
      }, x = (E) => {
        v(), b(), E === "capturing" ? (document.addEventListener("keydown", h), v = () => document.removeEventListener("keydown", h), t.element.addEventListener("mousedown", y), b = () => t.element.removeEventListener("mousedown", y)) : (v = () => {
        }, b = () => {
        });
      }, l = U.on(a, x);
      s.push(l), s.push(() => {
        c.dispose(), v(), b();
      });
      const T = Q((() => {
        const E = /* @__PURE__ */ new Set();
        for (const d of t.element.querySelectorAll(
          ":scope > :not([data-overlay])"
        ))
          d.hasAttribute("inert") ? E.add(d) : d.setAttribute("inert", "");
        return s.push(() => {
          for (const d of t.element.querySelectorAll(
            ":scope > :not([data-overlay])"
          ))
            E.has(d) || d.removeAttribute("inert");
          E.clear();
        }), document.activeElement?.blur?.(), k.div(
          S((d) => c.setElement(d)),
          B.status(c.status.map(String)),
          B.overlay("true"),
          g.class(
            w(
              r ?? "opaque",
              a
            )(
              (d, L) => `bc-overlay bc-overlay--effect-${d} bc-overlay--mode-${L}`
            )
          ),
          f
        );
      })(), t.element, {
        disposeWithParent: !0,
        clear: !1,
        providers: t.providers
      });
      s.push(T), $(() => c.open());
    }, e);
  });
}
function le(o, t) {
  const {
    size: s = "md",
    dismissable: e = !0,
    showCloseButton: n = !0,
    onClose: r,
    overlayEffect: a = "opaque",
    container: u = "body",
    position: m = "center"
  } = o;
  return ce((f, p) => {
    let c = () => {
    };
    return t((h) => {
      c = p;
      const y = R("capturing");
      U.on(e, (d) => {
        y.set(d ? "capturing" : "non-capturing");
      });
      const x = w(
        h.header != null,
        n
      )((d, L) => d || L), l = Y("modal"), i = `${l}-header`, T = `${l}-body`, E = k.div(
        g.class(
          w(
            s,
            m
          )(
            (d, L) => `bc-modal bc-modal--size-${d} bc-modal--container-${u} bc-modal--position-${L}`
          )
        ),
        // Essential ARIA attributes for modal dialog
        g.role("dialog"),
        V.modal(!0),
        ...h.header ? [V.labelledby(i)] : [],
        V.describedby(T),
        g.tabindex(-1),
        // Make modal focusable for initial focus
        g.id(l),
        B.focusTrap("true"),
        // Mark as focus trap container
        X.mousedown((d) => d.stopPropagation()),
        // Prevent overlay click-outside when clicking modal content
        // Focus trap implementation
        F({
          escapeDeactivates: !1,
          // Let Overlay handle escape key
          initialFocus: () => {
            const d = document.getElementById(l);
            if (!d) return null;
            const L = d.querySelector(
              '[aria-label="Close modal"]'
            );
            if (L) return L;
            const j = d.querySelector(
              'button, input, select, textarea, [tabindex]:not([tabindex="-1"])'
            );
            return j || d;
          }
        }),
        // Modal content container
        k.div(
          g.class("bc-modal__content"),
          // Header section
          q(
            x,
            () => k.div(
              g.class("bc-modal__header"),
              k.div(
                g.class("bc-modal__title"),
                ...h.header ? [g.id(i)] : [],
                h.header
              ),
              q(
                n,
                () => H(
                  K,
                  (d) => Z({
                    size: "sm",
                    label: d.$.closeModal,
                    onClick: () => {
                      c(), p();
                    }
                  })
                )
              )
            )
          ),
          // Body section
          k.div(g.class("bc-modal__body"), g.id(T), h.body),
          // Footer section
          h.footer && k.div(g.class("bc-modal__footer"), h.footer)
        )
      );
      f({
        mode: y,
        effect: a ?? "opaque",
        container: u,
        content: E,
        onClickOutside: () => {
          r?.(), p();
        },
        onEscape: () => {
          r?.(), p();
        }
      });
    }, () => {
      c(), p();
    });
  });
}
function Ee(o, t) {
  const { confirmText: s, cancelText: e, onConfirm: n, onCancel: r, ...a } = o;
  return H(
    K,
    (u) => le({ showCloseButton: !1, ...a }, (m, f) => {
      const p = () => {
        n?.(), f();
      }, c = () => {
        r?.(), f();
      };
      return t((b) => {
        m({
          body: b,
          footer: M(
            g.class("bc-modal__actions"),
            P(
              {
                variant: "outline",
                onClick: c
              },
              I(e, u.$.cancel)
            ),
            P(
              {
                color: "primary",
                variant: "filled",
                onClick: p
              },
              I(s, u.$.confirm)
            )
          )
        });
      }, f);
    })
  );
}
export {
  oe as A,
  O as B,
  Ee as C,
  F,
  le as M,
  ce as O,
  C as S,
  ge as a,
  ve as b,
  D as c,
  re as d,
  pe as e,
  N as f,
  he as g,
  ye as o,
  be as s,
  G as u
};
