import { m as ae, u as ce, b as le, w as ue, a as pe } from "./28e77e61.js";
import { useCallback as z, forwardRef as de, useMemo as K, useState as ge, useEffect as me } from "react";
import { u as fe, b as ye, P as we, r as ke } from "./5933aeef.js";
import { bQ as m, la as Z, lb as L, lc as ee, V as B } from "./684d2f28.js";
import "./b7901950.js";
import "./55f8e851.js";
import "./d44efa59.js";
import "react-dom";
import "./72df4a4a.js";
import "./717d41b5.js";
import "./af88f495.js";
const F = "TILL_NOW";
m.extend(Z);
m.extend(L);
m.extend(ee);
const C = {
  year: 0,
  month: 1,
  day: 2,
  hour: 3,
  minute: 4,
  second: 5
};
function he(n, t, e, s, o, a, r) {
  const i = [], h = t.getFullYear(), w = t.getMonth() + 1, k = t.getDate(), S = t.getHours(), c = t.getMinutes(), u = t.getSeconds(), f = e.getFullYear(), P = e.getMonth() + 1, b = e.getDate(), R = e.getHours(), N = e.getMinutes(), H = e.getSeconds(), I = C[s], O = parseInt(n[0]), j = m(Q([n[0], n[1], "1"])), W = parseInt(n[1]), D = parseInt(n[2]), x = parseInt(n[3]), y = parseInt(n[4]), p = O === h, V = O === f, Y = p && W === w, v = V && W === P, $ = Y && D === k, q = v && D === b, G = $ && x === S, J = q && x === R, oe = G && y === c, re = J && y === N, _ = (g, M, d) => {
    let l = [];
    for (let T = g; T <= M; T++)
      l.push(T);
    const se = n.slice(0, C[d]), E = a == null ? void 0 : a[d];
    return E && typeof E == "function" && (l = l.filter((T) => E(T, {
      get date() {
        const ie = [...se, T.toString()];
        return Q(ie);
      }
    }))), l;
  };
  if (I >= C.year) {
    const d = _(h, f, "year");
    i.push(d.map((l) => ({
      label: o("year", l),
      value: l.toString()
    })));
  }
  if (I >= C.month) {
    const d = _(p ? w : 1, V ? P : 12, "month");
    i.push(d.map((l) => ({
      label: o("month", l),
      value: l.toString()
    })));
  }
  if (I >= C.day) {
    const g = Y ? k : 1, M = v ? b : j.daysInMonth(), d = _(g, M, "day");
    i.push(d.map((l) => ({
      label: o("day", l),
      value: l.toString()
    })));
  }
  if (I >= C.hour) {
    const d = _($ ? S : 0, q ? R : 23, "hour");
    i.push(d.map((l) => ({
      label: o("hour", l),
      value: l.toString()
    })));
  }
  if (I >= C.minute) {
    const d = _(G ? c : 0, J ? N : 59, "minute");
    i.push(d.map((l) => ({
      label: o("minute", l),
      value: l.toString()
    })));
  }
  if (I >= C.second) {
    const d = _(oe ? u : 0, re ? H : 59, "second");
    i.push(d.map((l) => ({
      label: o("second", l),
      value: l.toString()
    })));
  }
  if (r && (i[0].push({
    label: o("now", null),
    value: F
  }), F === (n == null ? void 0 : n[0])))
    for (let g = 1; g < i.length; g += 1)
      i[g] = [];
  return i;
}
function Se(n) {
  return n ? [n.getFullYear().toString(), (n.getMonth() + 1).toString(), n.getDate().toString(), n.getHours().toString(), n.getMinutes().toString(), n.getSeconds().toString()] : [];
}
function Q(n) {
  var t, e, s, o, a, r;
  const i = (t = n[0]) !== null && t !== void 0 ? t : "1900", h = (e = n[1]) !== null && e !== void 0 ? e : "1", w = (s = n[2]) !== null && s !== void 0 ? s : "1", k = (o = n[3]) !== null && o !== void 0 ? o : "0", S = (a = n[4]) !== null && a !== void 0 ? a : "0", c = (r = n[5]) !== null && r !== void 0 ? r : "0";
  return new Date(parseInt(i), parseInt(h) - 1, parseInt(w), parseInt(k), parseInt(S), parseInt(c));
}
m.extend(Z);
m.extend(L);
m.extend(ee);
const A = {
  year: 0,
  week: 1,
  "week-day": 2
};
function ve(n, t, e, s, o, a) {
  const r = [], i = t.getFullYear(), h = e.getFullYear(), w = A[s], k = parseInt(n[0]), S = k === i, c = k === h, u = m(t), f = m(e), P = u.isoWeek(), b = f.isoWeek(), R = u.isoWeekday(), N = f.isoWeekday(), H = parseInt(n[1]), I = S && H === P, O = c && H === b, j = m(`${k}-01-01`).isoWeeksInYear(), W = (D, x, y) => {
    let p = [];
    for (let v = D; v <= x; v++)
      p.push(v);
    const V = n.slice(0, A[y]), Y = a == null ? void 0 : a[y];
    return Y && typeof Y == "function" && (p = p.filter((v) => Y(v, {
      get date() {
        const $ = [...V, v.toString()];
        return ne($);
      }
    }))), p;
  };
  if (w >= A.year) {
    const y = W(i, h, "year");
    r.push(y.map((p) => ({
      label: o("year", p),
      value: p.toString()
    })));
  }
  if (w >= A.week) {
    const y = W(S ? P : 1, c ? b : j, "week");
    r.push(y.map((p) => ({
      label: o("week", p),
      value: p.toString()
    })));
  }
  if (w >= A["week-day"]) {
    const y = W(I ? R : 1, O ? N : 7, "week-day");
    r.push(y.map((p) => ({
      label: o("week-day", p),
      value: p.toString()
    })));
  }
  return r;
}
function Ie(n) {
  if (!n)
    return [];
  const t = m(n);
  return [t.isoWeekYear().toString(), t.isoWeek().toString(), t.isoWeekday().toString()];
}
function ne(n) {
  var t, e, s;
  const o = (t = n[0]) !== null && t !== void 0 ? t : "1900", a = (e = n[1]) !== null && e !== void 0 ? e : "1", r = (s = n[2]) !== null && s !== void 0 ? s : "1";
  return m().year(parseInt(o)).isoWeek(parseInt(a)).isoWeekday(parseInt(r)).hour(0).minute(0).second(0).toDate();
}
const Me = {
  year: 1,
  month: 2,
  day: 3,
  hour: 4,
  minute: 5,
  second: 6
}, Ce = (n, t) => {
  if (t.includes("week"))
    return Ie(n);
  {
    const e = t;
    return Se(n).slice(0, Me[e]);
  }
}, U = (n, t) => {
  if ((n == null ? void 0 : n[0]) === F) {
    const e = /* @__PURE__ */ new Date();
    return e.tillNow = !0, e;
  }
  return t.includes("week") ? ne(n) : Q(n);
}, De = (n, t, e, s, o, a, r) => s.startsWith("week") ? ve(n, t, e, s, o, a) : he(n, t, e, s, o, a, r);
function xe(n) {
  const {
    locale: t
  } = fe();
  return z((e, s) => {
    if (n)
      return n(e, s);
    switch (e) {
      case "minute":
      case "second":
      case "hour":
        return ("0" + s.toString()).slice(-2);
      case "now":
        return t.DatePicker.tillNow;
      default:
        return s.toString();
    }
  }, [n]);
}
const X = (/* @__PURE__ */ new Date()).getFullYear(), We = {
  min: new Date((/* @__PURE__ */ new Date()).setFullYear(X - 10)),
  max: new Date((/* @__PURE__ */ new Date()).setFullYear(X + 10)),
  precision: "day",
  defaultValue: null
}, te = de((n, t) => {
  const e = ae(We, n), {
    renderLabel: s
  } = e, [o, a] = ce({
    value: e.value,
    defaultValue: e.defaultValue,
    onChange: (c) => {
      var u;
      c !== null && ((u = e.onConfirm) === null || u === void 0 || u.call(e, c));
    }
  }), r = K(() => /* @__PURE__ */ new Date(), []), i = xe(s), h = K(() => {
    let c = o ?? r;
    return c.tillNow ? [F] : (c = new Date(ye(c.getTime(), e.min.getTime(), e.max.getTime())), Ce(c, e.precision));
  }, [o, e.precision, e.min, e.max]), w = z((c) => {
    const u = U(c, e.precision);
    a(u, !0);
  }, [a, e.precision]), k = le((c) => {
    var u;
    const f = U(c, e.precision);
    (u = e.onSelect) === null || u === void 0 || u.call(e, f);
  }), S = z((c) => De(c, e.min, e.max, e.precision, i, e.filter, e.tillNow), [e.min, e.max, e.precision, i, e.tillNow]);
  return ue(e, /* @__PURE__ */ B(we, {
    ref: t,
    columns: S,
    value: h,
    onCancel: e.onCancel,
    onClose: e.onClose,
    closeOnMaskClick: e.closeOnMaskClick,
    visible: e.visible,
    confirmText: e.confirmText,
    cancelText: e.cancelText,
    onConfirm: w,
    onSelect: k,
    getContainer: e.getContainer,
    loading: e.loading,
    loadingContent: e.loadingContent,
    afterShow: e.afterShow,
    afterClose: e.afterClose,
    onClick: e.onClick,
    title: e.title,
    stopPropagation: e.stopPropagation,
    mouseWheel: e.mouseWheel,
    destroyOnClose: e.destroyOnClose,
    forceRender: e.forceRender,
    children: (c, u) => {
      var f;
      return (f = e.children) === null || f === void 0 ? void 0 : f.call(e, o, u);
    }
  }));
});
function Ye(n) {
  return new Promise((t) => {
    const s = ke(/* @__PURE__ */ B(() => {
      const [o, a] = ge(!1);
      return me(() => {
        a(!0);
      }, []), /* @__PURE__ */ B(te, {
        ...Object.assign({}, n, {
          visible: o,
          onConfirm: (r) => {
            var i;
            (i = n.onConfirm) === null || i === void 0 || i.call(n, r), t(r);
          },
          onClose: () => {
            var r;
            (r = n.onClose) === null || r === void 0 || r.call(n), a(!1), t(null);
          },
          afterClose: () => {
            var r;
            (r = n.afterClose) === null || r === void 0 || r.call(n), s();
          }
        })
      });
    }, {}));
  });
}
const $e = pe(te, {
  prompt: Ye,
  DATE_NOW: F
});
export {
  $e as default
};
