import { jsxs as Z, jsx as n } from "react/jsx-runtime";
import { forwardRef as ee, useState as h, useRef as se, useEffect as te } from "react";
import { AnimatePresence as ae, motion as ne } from "motion/react";
import { noop as E } from "es-toolkit/compat";
import f from "../../utils/classNames.js";
import re from "../../hooks/useAfterMount.js";
import oe from "../../hooks/useElementSize.js";
import le from "../../hooks/usePrevious.js";
import { hasRoundedClass as ie, hasBorderClass as ce, hasBgClass as me, hasOverflowClass as de, hasAlignItemsClass as k, hasDisplayClass as y, hasAlignSelfClass as pe, hasTextSizeClass as ue, hasTextColorClass as he, hasCursorClass as fe, hasPaddingClass as Ce, hasHoverTextColorClass as ge, hasHoverScaleClass as De, hasUserSelectClass as F, hasSpaceClass as M, hasFlexClass as Ne } from "../../utils/hasUtilityClass.js";
const ye = 200, ve = 1, xe = 7, Ae = 0.2, _ = "page", we = "pageBack", B = "ColumnItem", Se = {
  pageEnter: (t) => ({
    x: t === _ ? "60%" : "-60%",
    opacity: 0
  }),
  pageCenter: () => ({ x: 0, opacity: 1 })
}, l = (t) => t.toISOString().split("T").at(0), O = (t) => [...t.classList].includes(B) ? t : O(t.children[0]), be = ee((t, b) => {
  const {
    minDayWith: v = ye,
    minDays: P = ve,
    maxDays: R = xe,
    renderDay: x,
    skipWeekends: L = !1,
    startDate: i = /* @__PURE__ */ new Date(),
    onNextClick: U = E,
    onPreviousClick: z = E,
    buttonClassName: s = "",
    className: o = "",
    daysWrapperClassName: m = "",
    dayWrapperClassName: d = ""
  } = t, [r, C] = h(i), [a, A] = h(1), [H, j] = h(!1), c = se(null), [w] = oe(c), V = le(l(r)), S = l(r) > V ? _ : we, [X, Y] = h(i);
  l(i) !== l(X) && (C(i), Y(i)), re(() => {
    j(!0);
  }, []), te(() => {
    if (!c.current)
      return;
    const e = O(c.current.children[0]);
    if (!e)
      return;
    const g = e.getBoundingClientRect().width, D = a - 1 >= P, u = a + 1 <= R, Q = D && g <= v;
    if (u && (a + 1) * v <= w) {
      const N = a + 1;
      A(N);
      return;
    }
    if (Q) {
      const N = a - 1;
      A(N);
      return;
    }
  }, [w, c.current, a, r]);
  const K = () => {
    const e = new Date(r);
    e.setDate(e.getDate() + a), C(e), U(e);
  }, $ = () => {
    const e = new Date(r);
    e.setDate(e.getDate() - a), C(e), z(e);
  }, p = [];
  let I = !0, T = 1;
  for (; I; ) {
    const e = new Date(r);
    e.setDate(r.getDate() + T);
    const g = e.getDay() === 6, D = e.getDay() === 0, u = g || D;
    u && !L ? p.push(e) : u || p.push(e), T++, p.length === a && (I = !1);
  }
  const q = f(
    "CalenderStripe",
    !y(o) && "display-flex",
    !k(o) && "align-items-center",
    !de(o) && "overflow-hidden",
    !me(o) && "bg-white",
    !ce(o) && "border",
    !ie(o) && "rounded",
    o
  ), W = f(
    !k(s) && "align-items-center",
    !y(s) && "display-flex",
    !De(s) && "hover-scale-105",
    !ge(s) && "hover-text-color-darkest",
    !Ce(s) && "padding-10",
    !fe(s) && "cursor-pointer",
    !he(s) && "text-color-darker",
    !ue(s) && "text-size-12",
    !pe(s) && "align-self-stretch",
    s
  ), G = f(
    !y(m) && "display-flex",
    !M(m) && "space-x--1",
    !F(m) && "user-select-none",
    m
  ), J = f(
    B,
    !Ne(d) && "flex-1-1-0",
    !M(d) && "space-x--1",
    !F(d) && "user-select-none",
    d
  );
  return /* @__PURE__ */ Z("div", { ref: b, className: q, children: [
    /* @__PURE__ */ n("div", { className: W, onClick: $, children: /* @__PURE__ */ n("span", { className: "rioglyph rioglyph-chevron-left" }) }),
    /* @__PURE__ */ n("div", { className: "flex-1-1 overflow-hidden", ref: c, children: /* @__PURE__ */ n(ae, { mode: "wait", custom: S, children: /* @__PURE__ */ n(
      ne.div,
      {
        variants: Se,
        initial: H ? "pageEnter" : !1,
        animate: "pageCenter",
        custom: S,
        transition: { duration: Ae },
        children: /* @__PURE__ */ n("div", { className: G, children: p.map((e) => /* @__PURE__ */ n("div", { className: J, children: x ? x(e) : null }, `${l(e)}`)) })
      },
      l(r)
    ) }) }),
    /* @__PURE__ */ n("div", { className: W, onClick: K, children: /* @__PURE__ */ n("span", { className: "rioglyph rioglyph-chevron-right" }) })
  ] });
});
export {
  be as default
};
//# sourceMappingURL=CalendarStripe.js.map
