UNPKG

rhf-hero-ui

Version:

React Components with React Hook Form and HeroUI

968 lines (967 loc) 34.4 kB
import o, { useCallback as C, useState as B, useEffect as pe, useMemo as F } from "react"; import { DatePicker as nt, Input as be, InputOtp as rt, Select as at, SelectItem as lt, TimeInput as ot, Textarea as ct, Autocomplete as st, AutocompleteItem as it, RadioGroup as dt, Radio as ut, Checkbox as Ee, CheckboxGroup as ht, Card as ft, CardHeader as mt, Divider as $t, CardBody as yt, Table as we, TableHeader as Me, TableColumn as ve, TableBody as Ce, TableRow as xe, TableCell as Ie, Skeleton as gt, Pagination as pt, Button as W, Modal as bt, ModalContent as Et, ModalHeader as wt, ModalBody as Mt, ModalFooter as vt } from "@heroui/react"; import { Controller as w } from "react-hook-form"; function X(e, t) { return e - t * Math.floor(e / t); } const De = 1721426; function L(e, t, n, r) { t = ne(e, t); let a = t - 1, l = -2; return n <= 2 ? l = 0 : U(t) && (l = -1), De - 1 + 365 * a + Math.floor(a / 4) - Math.floor(a / 100) + Math.floor(a / 400) + Math.floor((367 * n - 362) / 12 + l + r); } function U(e) { return e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0); } function ne(e, t) { return e === "BC" ? 1 - t : t; } function Ct(e) { let t = "AD"; return e <= 0 && (t = "BC", e = 1 - e), [ t, e ]; } const xt = { standard: [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ], leapyear: [ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ] }; class J { fromJulianDay(t) { let n = t, r = n - De, a = Math.floor(r / 146097), l = X(r, 146097), c = Math.floor(l / 36524), s = X(l, 36524), i = Math.floor(s / 1461), $ = X(s, 1461), M = Math.floor($ / 365), _ = a * 400 + c * 100 + i * 4 + M + (c !== 4 && M !== 4 ? 1 : 0), [f, y] = Ct(_), D = n - L(f, y, 1, 1), m = 2; n < L(f, y, 3, 1) ? m = 0 : U(y) && (m = 1); let N = Math.floor(((D + m) * 12 + 373) / 367), T = n - L(f, y, N, 1) + 1; return new j(f, y, N, T); } toJulianDay(t) { return L(t.era, t.year, t.month, t.day); } getDaysInMonth(t) { return xt[U(t.year) ? "leapyear" : "standard"][t.month - 1]; } // eslint-disable-next-line @typescript-eslint/no-unused-vars getMonthsInYear(t) { return 12; } getDaysInYear(t) { return U(t.year) ? 366 : 365; } // eslint-disable-next-line @typescript-eslint/no-unused-vars getYearsInEra(t) { return 9999; } getEras() { return [ "BC", "AD" ]; } isInverseEra(t) { return t.era === "BC"; } balanceDate(t) { t.year <= 0 && (t.era = t.era === "BC" ? "AD" : "BC", t.year = 1 - t.year); } constructor() { this.identifier = "gregory"; } } function It(e, t) { var n, r, a, l; return (l = (a = (n = e.isEqual) === null || n === void 0 ? void 0 : n.call(e, t)) !== null && a !== void 0 ? a : (r = t.isEqual) === null || r === void 0 ? void 0 : r.call(t, e)) !== null && l !== void 0 ? l : e.identifier === t.identifier; } function ke(e, t) { return e.calendar.toJulianDay(e) - t.calendar.toJulianDay(t); } function Se(e, t) { return fe(e) - fe(t); } function fe(e) { return e.hour * 36e5 + e.minute * 6e4 + e.second * 1e3 + e.millisecond; } let Z = null; function Be() { return Z == null && (Z = new Intl.DateTimeFormat().resolvedOptions().timeZone), Z; } function me(e) { e = re(e, new J()); let t = ne(e.era, e.year); return Ne(t, e.month, e.day, e.hour, e.minute, e.second, e.millisecond); } function Ne(e, t, n, r, a, l, c) { let s = /* @__PURE__ */ new Date(); return s.setUTCHours(r, a, l, c), s.setUTCFullYear(e, t - 1, n), s.getTime(); } function $e(e, t) { if (t === "UTC") return 0; if (e > 0 && t === Be()) return new Date(e).getTimezoneOffset() * -6e4; let { year: n, month: r, day: a, hour: l, minute: c, second: s } = Te(e, t); return Ne(n, r, a, l, c, s, 0) - Math.floor(e / 1e3) * 1e3; } const ye = /* @__PURE__ */ new Map(); function Te(e, t) { let n = ye.get(t); n || (n = new Intl.DateTimeFormat("en-US", { timeZone: t, hour12: !1, era: "short", year: "numeric", month: "numeric", day: "numeric", hour: "numeric", minute: "numeric", second: "numeric" }), ye.set(t, n)); let r = n.formatToParts(new Date(e)), a = {}; for (let l of r) l.type !== "literal" && (a[l.type] = l.value); return { // Firefox returns B instead of BC... https://bugzilla.mozilla.org/show_bug.cgi?id=1752253 year: a.era === "BC" || a.era === "B" ? -a.year + 1 : +a.year, month: +a.month, day: +a.day, hour: a.hour === "24" ? 0 : +a.hour, minute: +a.minute, second: +a.second }; } const ge = 864e5; function Dt(e, t, n, r) { return (n === r ? [ n ] : [ n, r ]).filter((l) => kt(e, t, l)); } function kt(e, t, n) { let r = Te(n, t); return e.year === r.year && e.month === r.month && e.day === r.day && e.hour === r.hour && e.minute === r.minute && e.second === r.second; } function St(e, t, n = "compatible") { let r = Pe(e); if (t === "UTC") return me(r); if (t === Be() && n === "compatible") { r = re(r, new J()); let i = /* @__PURE__ */ new Date(), $ = ne(r.era, r.year); return i.setFullYear($, r.month - 1, r.day), i.setHours(r.hour, r.minute, r.second, r.millisecond), i.getTime(); } let a = me(r), l = $e(a - ge, t), c = $e(a + ge, t), s = Dt(r, t, a - l, a - c); if (s.length === 1) return s[0]; if (s.length > 1) switch (n) { // 'compatible' means 'earlier' for "fall back" transitions case "compatible": case "earlier": return s[0]; case "later": return s[s.length - 1]; case "reject": throw new RangeError("Multiple possible absolute times found"); } switch (n) { case "earlier": return Math.min(a - l, a - c); // 'compatible' means 'later' for "spring forward" transitions case "compatible": case "later": return Math.max(a - l, a - c); case "reject": throw new RangeError("No such absolute time found"); } } function Fe(e, t, n = "compatible") { return new Date(St(e, t, n)); } function Pe(e, t) { let n = 0, r = 0, a = 0, l = 0; if ("timeZone" in e) ({ hour: n, minute: r, second: a, millisecond: l } = e); else if ("hour" in e && !t) return e; return t && ({ hour: n, minute: r, second: a, millisecond: l } = t), new H(e.calendar, e.era, e.year, e.month, e.day, n, r, a, l); } function re(e, t) { if (It(e.calendar, t)) return e; let n = t.fromJulianDay(e.calendar.toJulianDay(e)), r = e.copy(); return r.calendar = t, r.era = n.era, r.year = n.year, r.month = n.month, r.day = n.day, P(r), r; } function ae(e, t) { let n = e.copy(), r = "hour" in n ? Oe(n, t) : 0; ee(n, t.years || 0), n.calendar.balanceYearMonth && n.calendar.balanceYearMonth(n, e), n.month += t.months || 0, te(n), Ye(n), n.day += (t.weeks || 0) * 7, n.day += t.days || 0, n.day += r, Bt(n), n.calendar.balanceDate && n.calendar.balanceDate(n), n.year < 1 && (n.year = 1, n.month = 1, n.day = 1); let a = n.calendar.getYearsInEra(n); if (n.year > a) { var l, c; let i = (l = (c = n.calendar).isInverseEra) === null || l === void 0 ? void 0 : l.call(c, n); n.year = a, n.month = i ? 1 : n.calendar.getMonthsInYear(n), n.day = i ? 1 : n.calendar.getDaysInMonth(n); } n.month < 1 && (n.month = 1, n.day = 1); let s = n.calendar.getMonthsInYear(n); return n.month > s && (n.month = s, n.day = n.calendar.getDaysInMonth(n)), n.day = Math.max(1, Math.min(n.calendar.getDaysInMonth(n), n.day)), n; } function ee(e, t) { var n, r; !((n = (r = e.calendar).isInverseEra) === null || n === void 0) && n.call(r, e) && (t = -t), e.year += t; } function te(e) { for (; e.month < 1; ) ee(e, -1), e.month += e.calendar.getMonthsInYear(e); let t = 0; for (; e.month > (t = e.calendar.getMonthsInYear(e)); ) e.month -= t, ee(e, 1); } function Bt(e) { for (; e.day < 1; ) e.month--, te(e), e.day += e.calendar.getDaysInMonth(e); for (; e.day > e.calendar.getDaysInMonth(e); ) e.day -= e.calendar.getDaysInMonth(e), e.month++, te(e); } function Ye(e) { e.month = Math.max(1, Math.min(e.calendar.getMonthsInYear(e), e.month)), e.day = Math.max(1, Math.min(e.calendar.getDaysInMonth(e), e.day)); } function P(e) { e.calendar.constrainDate && e.calendar.constrainDate(e), e.year = Math.max(1, Math.min(e.calendar.getYearsInEra(e), e.year)), Ye(e); } function Ae(e) { let t = {}; for (let n in e) typeof e[n] == "number" && (t[n] = -e[n]); return t; } function Re(e, t) { return ae(e, Ae(t)); } function je(e, t) { let n = e.copy(); return t.era != null && (n.era = t.era), t.year != null && (n.year = t.year), t.month != null && (n.month = t.month), t.day != null && (n.day = t.day), P(n), n; } function He(e, t) { let n = e.copy(); return t.hour != null && (n.hour = t.hour), t.minute != null && (n.minute = t.minute), t.second != null && (n.second = t.second), t.millisecond != null && (n.millisecond = t.millisecond), Ve(n), n; } function Nt(e) { e.second += Math.floor(e.millisecond / 1e3), e.millisecond = q(e.millisecond, 1e3), e.minute += Math.floor(e.second / 60), e.second = q(e.second, 60), e.hour += Math.floor(e.minute / 60), e.minute = q(e.minute, 60); let t = Math.floor(e.hour / 24); return e.hour = q(e.hour, 24), t; } function Ve(e) { e.millisecond = Math.max(0, Math.min(e.millisecond, 1e3)), e.second = Math.max(0, Math.min(e.second, 59)), e.minute = Math.max(0, Math.min(e.minute, 59)), e.hour = Math.max(0, Math.min(e.hour, 23)); } function q(e, t) { let n = e % t; return n < 0 && (n += t), n; } function Oe(e, t) { return e.hour += t.hours || 0, e.minute += t.minutes || 0, e.second += t.seconds || 0, e.millisecond += t.milliseconds || 0, Nt(e); } function Le(e, t) { let n = e.copy(); return Oe(n, t), n; } function Tt(e, t) { return Le(e, Ae(t)); } function qe(e, t, n, r) { let a = e.copy(); switch (t) { case "era": { let s = e.calendar.getEras(), i = s.indexOf(e.era); if (i < 0) throw new Error("Invalid era: " + e.era); i = I(i, n, 0, s.length - 1, r?.round), a.era = s[i], P(a); break; } case "year": var l, c; !((l = (c = a.calendar).isInverseEra) === null || l === void 0) && l.call(c, a) && (n = -n), a.year = I(e.year, n, -1 / 0, 9999, r?.round), a.year === -1 / 0 && (a.year = 1), a.calendar.balanceYearMonth && a.calendar.balanceYearMonth(a, e); break; case "month": a.month = I(e.month, n, 1, e.calendar.getMonthsInYear(e), r?.round); break; case "day": a.day = I(e.day, n, 1, e.calendar.getDaysInMonth(e), r?.round); break; default: throw new Error("Unsupported field " + t); } return e.calendar.balanceDate && e.calendar.balanceDate(a), P(a), a; } function Ue(e, t, n, r) { let a = e.copy(); switch (t) { case "hour": { let l = e.hour, c = 0, s = 23; if (r?.hourCycle === 12) { let i = l >= 12; c = i ? 12 : 0, s = i ? 23 : 11; } a.hour = I(l, n, c, s, r?.round); break; } case "minute": a.minute = I(e.minute, n, 0, 59, r?.round); break; case "second": a.second = I(e.second, n, 0, 59, r?.round); break; case "millisecond": a.millisecond = I(e.millisecond, n, 0, 999, r?.round); break; default: throw new Error("Unsupported field " + t); } return a; } function I(e, t, n, r, a = !1) { if (a) { e += Math.sign(t), e < n && (e = r); let l = Math.abs(t); t > 0 ? e = Math.ceil(e / l) * l : e = Math.floor(e / l) * l, e > r && (e = n); } else e += t, e < n ? e = r - (n - e - 1) : e > r && (e = n + (e - r - 1)); return e; } const Ft = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})$/, Pt = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/; function Yt(e) { let t = e.match(Ft); if (!t) throw new Error("Invalid ISO 8601 date string: " + e); let n = new j(E(t[1], 0, 9999), E(t[2], 1, 12), 1); return n.day = E(t[3], 1, n.calendar.getDaysInMonth(n)), n; } function At(e) { let t = e.match(Pt); if (!t) throw new Error("Invalid ISO 8601 date time string: " + e); let n = E(t[1], -9999, 9999), r = n < 1 ? "BC" : "AD", a = new H(r, n < 1 ? -n + 1 : n, E(t[2], 1, 12), 1, t[4] ? E(t[4], 0, 23) : 0, t[5] ? E(t[5], 0, 59) : 0, t[6] ? E(t[6], 0, 59) : 0, t[7] ? E(t[7], 0, 1 / 0) * 1e3 : 0); return a.day = E(t[3], 0, a.calendar.getDaysInMonth(a)), a; } function E(e, t, n) { let r = Number(e); if (r < t || r > n) throw new RangeError(`Value out of range: ${t} <= ${r} <= ${n}`); return r; } function We(e) { return `${String(e.hour).padStart(2, "0")}:${String(e.minute).padStart(2, "0")}:${String(e.second).padStart(2, "0")}${e.millisecond ? String(e.millisecond / 1e3).slice(1) : ""}`; } function Je(e) { let t = re(e, new J()), n; return t.era === "BC" ? n = t.year === 1 ? "0000" : "-" + String(Math.abs(1 - t.year)).padStart(6, "00") : n = String(t.year).padStart(4, "0"), `${n}-${String(t.month).padStart(2, "0")}-${String(t.day).padStart(2, "0")}`; } function Rt(e) { return `${Je(e)}T${We(e)}`; } function jt(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); } function le(e, t, n) { jt(e, t), t.set(e, n); } function _e(e) { let t = typeof e[0] == "object" ? e.shift() : new J(), n; if (typeof e[0] == "string") n = e.shift(); else { let c = t.getEras(); n = c[c.length - 1]; } let r = e.shift(), a = e.shift(), l = e.shift(); return [ t, n, r, a, l ]; } var Ht = /* @__PURE__ */ new WeakMap(); class j { /** Returns a copy of this date. */ copy() { return this.era ? new j(this.calendar, this.era, this.year, this.month, this.day) : new j(this.calendar, this.year, this.month, this.day); } /** Returns a new `CalendarDate` with the given duration added to it. */ add(t) { return ae(this, t); } /** Returns a new `CalendarDate` with the given duration subtracted from it. */ subtract(t) { return Re(this, t); } /** Returns a new `CalendarDate` with the given fields set to the provided values. Other fields will be constrained accordingly. */ set(t) { return je(this, t); } /** * Returns a new `CalendarDate` with the given field adjusted by a specified amount. * When the resulting value reaches the limits of the field, it wraps around. */ cycle(t, n, r) { return qe(this, t, n, r); } /** Converts the date to a native JavaScript Date object, with the time set to midnight in the given time zone. */ toDate(t) { return Fe(this, t); } /** Converts the date to an ISO 8601 formatted string. */ toString() { return Je(this); } /** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */ compare(t) { return ke(this, t); } constructor(...t) { le(this, Ht, { writable: !0, value: void 0 }); let [n, r, a, l, c] = _e(t); this.calendar = n, this.era = r, this.year = a, this.month = l, this.day = c, P(this); } } var Vt = /* @__PURE__ */ new WeakMap(); class R { /** Returns a copy of this time. */ copy() { return new R(this.hour, this.minute, this.second, this.millisecond); } /** Returns a new `Time` with the given duration added to it. */ add(t) { return Le(this, t); } /** Returns a new `Time` with the given duration subtracted from it. */ subtract(t) { return Tt(this, t); } /** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */ set(t) { return He(this, t); } /** * Returns a new `Time` with the given field adjusted by a specified amount. * When the resulting value reaches the limits of the field, it wraps around. */ cycle(t, n, r) { return Ue(this, t, n, r); } /** Converts the time to an ISO 8601 formatted string. */ toString() { return We(this); } /** Compares this time with another. A negative result indicates that this time is before the given one, and a positive time indicates that it is after. */ compare(t) { return Se(this, t); } constructor(t = 0, n = 0, r = 0, a = 0) { le(this, Vt, { writable: !0, value: void 0 }), this.hour = t, this.minute = n, this.second = r, this.millisecond = a, Ve(this); } } var Ot = /* @__PURE__ */ new WeakMap(); class H { /** Returns a copy of this date. */ copy() { return this.era ? new H(this.calendar, this.era, this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond) : new H(this.calendar, this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond); } /** Returns a new `CalendarDateTime` with the given duration added to it. */ add(t) { return ae(this, t); } /** Returns a new `CalendarDateTime` with the given duration subtracted from it. */ subtract(t) { return Re(this, t); } /** Returns a new `CalendarDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */ set(t) { return je(He(this, t), t); } /** * Returns a new `CalendarDateTime` with the given field adjusted by a specified amount. * When the resulting value reaches the limits of the field, it wraps around. */ cycle(t, n, r) { switch (t) { case "era": case "year": case "month": case "day": return qe(this, t, n, r); default: return Ue(this, t, n, r); } } /** Converts the date to a native JavaScript Date object in the given time zone. */ toDate(t, n) { return Fe(this, t, n); } /** Converts the date to an ISO 8601 formatted string. */ toString() { return Rt(this); } /** Compares this date with another. A negative result indicates that this date is before the given one, and a positive date indicates that it is after. */ compare(t) { let n = ke(this, t); return n === 0 ? Se(this, Pe(t)) : n; } constructor(...t) { le(this, Ot, { writable: !0, value: void 0 }); let [n, r, a, l, c] = _e(t); this.calendar = n, this.era = r, this.year = a, this.month = l, this.day = c, this.hour = t.shift() || 0, this.minute = t.shift() || 0, this.second = t.shift() || 0, this.millisecond = t.shift() || 0, P(this); } } const Xt = ({ name: e, granularity: t, rules: n, ...r }) => { const a = C((l) => t === "day" || !t ? Yt(l) : At(l), [t]); return /* @__PURE__ */ o.createElement( w, { defaultValue: "", name: e, rules: n, render: ({ field: l, formState: { errors: c } }) => /* @__PURE__ */ o.createElement( nt, { ...r, ...l, value: l.value ? a(l.value) : null, onChange: (s) => { l.onChange(s ? s.toString() : null), r.onChange?.(s); }, onBlur: (s) => { l.onBlur(), r.onBlur?.(s); }, errorMessage: c[e] ? c[e]?.message : "", isInvalid: !!c[e], granularity: t } ) } ); }, Zt = ({ rules: e, name: t, classNames: n, ...r }) => /* @__PURE__ */ o.createElement( w, { name: t, rules: e, defaultValue: "", render: ({ field: a, formState: { errors: l } }) => /* @__PURE__ */ o.createElement( be, { ...r, ...a, onChange: (c) => { a.onChange(c), r.onChange?.(c); }, isInvalid: !!l[t], errorMessage: l[t] ? l[t]?.message : "", classNames: { ...n, input: `${n?.input || ""} ${l[t] ? "placeholder:text-danger" : ""}` } } ) } ), en = ({ rules: e, name: t, classNames: n, ...r }) => /* @__PURE__ */ o.createElement( w, { defaultValue: "", name: t, rules: e, render: ({ field: a, formState: { errors: l } }) => /* @__PURE__ */ o.createElement( rt, { ...r, ...a, onChange: (c) => { a.onChange(c), r.onChange?.(c); }, isInvalid: !!l[t], errorMessage: l[t] ? l[t]?.message : "", classNames: { ...n, input: `${n?.input || ""} ${l[t] ? "placeholder:text-danger" : ""}` } } ) } ), tn = ({ selectionMode: e, name: t, rules: n, data: r, disabledKeys: a, onChange: l, ...c }) => /* @__PURE__ */ o.createElement( w, { rules: n, name: t, defaultValue: e === "multiple" ? [] : "", render: ({ field: s, formState: { errors: i } }) => /* @__PURE__ */ o.createElement( at, { ...c, ...s, onChange: ($) => { const M = $.target.value; e === "multiple" ? s.onChange(M ? M.split(",") : []) : s.onChange(M ?? ""), l?.($); }, items: r, selectedKeys: e === "multiple" ? s.value : [s.value], errorMessage: i[t]?.message || "", isInvalid: !!i[t], disabledKeys: a, selectionMode: e }, ($) => /* @__PURE__ */ o.createElement(lt, { ...$, key: $.key }) ) } ), nn = ({ name: e, shouldUnregister: t, granularity: n, rules: r, ...a }) => { const l = C((c) => { if (n === "second") { const [s, i, $] = c.split(":").map(Number); return new R(s, i, $); } else if (n === "minute" || !n) { const [s, i] = c.split(":").map(Number); return new R(s, i); } else { const [s] = c.split(":").map(Number); return new R(s); } }, [n]); return /* @__PURE__ */ o.createElement( w, { name: e, rules: r, shouldUnregister: t, defaultValue: "", render: ({ field: c, formState: { errors: s } }) => /* @__PURE__ */ o.createElement( ot, { ...a, ...c, granularity: n, value: c.value ? l(c.value) : null, onChange: (i) => { c.onChange(i ? i.toString() : null), a.onChange?.(i); }, onBlur: (i) => { c.onBlur(), a.onBlur?.(i); }, isInvalid: !!s[e], errorMessage: s[e] ? s[e]?.message : "" } ) } ); }, rn = ({ rules: e, name: t, classNames: n, ...r }) => /* @__PURE__ */ o.createElement( w, { defaultValue: "", name: t, rules: e, render: ({ field: a, formState: { errors: l } }) => /* @__PURE__ */ o.createElement( ct, { ...r, ...a, onChange: (c) => { a.onChange(c), r.onChange?.(c); }, isInvalid: !!l[t], errorMessage: l[t] ? l[t]?.message : "", classNames: { ...n, input: `${n?.input || ""} ${l[t] ? "placeholder:text-danger" : ""}` } } ) } ), an = ({ onSelectionChange: e, name: t, data: n, rules: r, inputProps: a, ...l }) => /* @__PURE__ */ o.createElement( w, { defaultValue: "", name: t, rules: r, render: ({ field: c, formState: { errors: s } }) => /* @__PURE__ */ o.createElement( st, { ...c, ...l, selectedKey: c.value, defaultItems: n, onSelectionChange: (i) => { c.onChange(i ?? ""), e?.(i ?? ""); }, onBlur: (i) => { c.onBlur(), l.onBlur?.(i); }, isInvalid: !!s[t], errorMessage: s[t] ? s[t]?.message : "", inputProps: { ...a, classNames: { input: s[t] ? "placeholder:text-danger" : "" } } }, n.map((i) => /* @__PURE__ */ o.createElement(it, { ...i, key: i.key })) ) } ), ln = ({ data: e, rules: t, name: n, ...r }) => /* @__PURE__ */ o.createElement( w, { rules: t, name: n, defaultValue: "", render: ({ field: a, formState: { errors: l } }) => /* @__PURE__ */ o.createElement( dt, { ...a, ...r, onChange: (c) => { a.onChange(c), r.onChange?.(c); }, isInvalid: !!l[n], errorMessage: l[n] ? l[n]?.message : "" }, e.map((c, s) => /* @__PURE__ */ o.createElement(ut, { ...c, key: s })) ) } ), on = ({ rules: e, name: t, ...n }) => /* @__PURE__ */ o.createElement( w, { rules: e, name: t, render: ({ field: r, formState: { errors: a } }) => /* @__PURE__ */ o.createElement( Ee, { ...n, ...r, isSelected: !!r.value, isInvalid: !!a[t] }, n.children ) } ), cn = ({ onChange: e, rules: t, name: n, data: r, ...a }) => /* @__PURE__ */ o.createElement( w, { rules: t, name: n, defaultValue: [], render: ({ field: l, formState: { errors: c } }) => /* @__PURE__ */ o.createElement( ht, { ...a, ...l, isInvalid: !!c[n], onChange: (s) => { l.onChange(s), e?.(s); } }, r.map((s) => /* @__PURE__ */ o.createElement(Ee, { ...s, key: s.value }, s.children)), !!c[n] && /* @__PURE__ */ o.createElement("div", { "data-slot": "error-message", className: "text-tiny text-danger w-full" }, c[n]?.message ?? "") ) } ), Lt = () => /* @__PURE__ */ o.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "size-6" }, /* @__PURE__ */ o.createElement("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m4.5 18.75 7.5-7.5 7.5 7.5" }), /* @__PURE__ */ o.createElement("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m4.5 12.75 7.5-7.5 7.5 7.5" })), qt = () => /* @__PURE__ */ o.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "size-6" }, /* @__PURE__ */ o.createElement("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m4.5 5.25 7.5 7.5 7.5-7.5m-15 6 7.5 7.5 7.5-7.5" })), sn = ({ title: e, color: t = "default", children: n, collapse: r = !1 }) => { const [a, l] = B(!0); return /* @__PURE__ */ o.createElement(ft, { className: "mb-5" }, /* @__PURE__ */ o.createElement(mt, { className: `bg-${t} px-5 text-white flex justify-between` }, e, r && /* @__PURE__ */ o.createElement("div", { onClick: () => l(!a), className: "cursor-pointer" }, a ? /* @__PURE__ */ o.createElement(Lt, null) : /* @__PURE__ */ o.createElement(qt, null))), /* @__PURE__ */ o.createElement($t, null), /* @__PURE__ */ o.createElement(yt, { className: `p-5 ${a ? "" : "hidden"}` }, n)); }, Ut = ({ size: e, columns: t }) => /* @__PURE__ */ o.createElement(we, { "aria-label": "cargando" }, /* @__PURE__ */ o.createElement(Me, null, t.map( (n) => /* @__PURE__ */ o.createElement(ve, { ...t, key: n.key }, n.title) )), /* @__PURE__ */ o.createElement(Ce, null, Array.from( { length: e }, (n, r) => /* @__PURE__ */ o.createElement(xe, { key: r }, () => /* @__PURE__ */ o.createElement(Ie, null, /* @__PURE__ */ o.createElement(gt, { className: "h-5 w-4/5 rounded-lg" }))) ))), Wt = () => /* @__PURE__ */ o.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: "size-5" }, /* @__PURE__ */ o.createElement("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m21 21-5.197-5.197m0 0A7.5 7.5 0 1 0 5.196 5.196a7.5 7.5 0 0 0 10.607 10.607Z" })), Jt = (e, t) => { const [n, r] = B(e); return pe(() => { const a = setTimeout(() => { r(e); }, t); return () => { clearTimeout(a); }; }, [e, t]), n; }, dn = ({ hideFilterSearch: e, loading: t, isVirtualized: n, onSelect: r, onSelectionChange: a, isHeaderSticky: l, classNames: c, selectionMode: s, inputSearch: i, hideRowsPerPageOptions: $, extraTopContent: M, cellClass: _, rows: f = [], columns: y = [], keyRow: D = "id", localText: m = { emptyContent: "No hay datos.", rowsPerPage: "Filas por pagina" }, rowsPerPageOptions: N = { default: 10, options: [5, 10, 15] }, ...T }) => { const [Y, G] = B(""), [k, Ge] = B(N.default), [g, S] = B(1), [K, z] = B(/* @__PURE__ */ new Set()), [v, Ke] = B(), oe = !!Jt(Y, 500), V = F(() => [...K].length, [K]); pe(() => { f && (S(1), z(/* @__PURE__ */ new Set())); }, [f]); const ze = C((d) => { z(d); let u = []; s === "single" ? u = f.find((h) => h[D] == [...d][0]) : d === "all" ? (u = f, z(new Set(f.map((h) => h[D].toString())))) : u = f.filter((h) => [...d].includes(h[D].toString())), r && r(u), a && a(d); }, [r, f, s, D, a]), O = F(() => { let d = [...f]; return oe && (d = d.filter( (u) => Object.values(u).some( (h, b) => { const x = Object.keys(u)[b], p = y.find((tt) => tt.key == x); return !p || h == null || !h ? !1 : (p.onFilter ? p.onFilter(h) : h).toString().toLowerCase().includes(Y.toLowerCase()); } ) )), d; }, [Y, oe, f, y]), A = Math.ceil(O.length / k) || 1, Q = F(() => v === void 0 ? O : [...O].sort((d, u) => { const h = y.find((he) => he.key === v.column), b = h?.onOrder ? h.onOrder(d[v.column]) : d[v.column], x = h?.onOrder ? h.onOrder(u[v.column]) : u[v.column]; let p = 0; return !b && !x && (p = 0), b || (p = -1), x || (p = 1), typeof b == "number" && typeof x == "number" && (p = b - x), typeof b == "string" && typeof x == "string" && (p = (b ?? "").localeCompare(x ?? "")), v.direction === "descending" ? -p : p; }), [v, O, y]), Qe = F(() => { if (n) return Q; const d = (g - 1) * k, u = d + k; return Q.slice(d, u); }, [Q, g, k, n]), ce = C(() => { G(""), S(1); }, []), se = C(() => { g < A && S(g + 1); }, [g, A]), ie = C(() => { g > 1 && S(g - 1); }, [g]), de = C((d) => { Ge(Number(d.target.value)), S(1); }, []), ue = C((d) => { d ? (G(d), S(1)) : G(""); }, []), Xe = C((d, u) => { const h = y.find((b) => b.key === u); return h.format ? /* @__PURE__ */ o.createElement("div", null, h.format({ value: d[u], row: d })) : /* @__PURE__ */ o.createElement("p", { title: d[u] }, d[u]); }, [y]), Ze = F( () => /* @__PURE__ */ o.createElement("div", { className: "py-2 px-2 mt-2 flex justify-between items-center" }, /* @__PURE__ */ o.createElement("span", { className: "w-[30%] text-small text-default-400" }, V > 0 && /* @__PURE__ */ o.createElement(o.Fragment, null, V, " ", V === 1 ? m?.items?.[0] ?? "fila seleccionada" : m?.items?.[1] ?? "filas seleccionadas")), !n && /* @__PURE__ */ o.createElement(o.Fragment, null, /* @__PURE__ */ o.createElement( pt, { isCompact: !0, showControls: !0, showShadow: !0, page: g, total: A, onChange: S, color: T.color } ), /* @__PURE__ */ o.createElement("div", { className: "hidden sm:flex w-[30%] justify-end gap-2" }, /* @__PURE__ */ o.createElement(W, { isDisabled: g === 1, size: "sm", variant: "flat", onPress: ie }, m.paginateButtons?.[0] ?? "Atrás"), /* @__PURE__ */ o.createElement(W, { isDisabled: g === A, size: "sm", variant: "flat", onPress: se }, m.paginateButtons?.[1] ?? "Siguiente")))), [ g, A, se, ie, V, T.color, n, m.paginateButtons, m.items ] ), et = F(() => /* @__PURE__ */ o.createElement("div", { className: "flex flex-col gap-4 relative pb-2" }, /* @__PURE__ */ o.createElement("div", { className: "flex justify-between gap-3 items-end" }, !e && /* @__PURE__ */ o.createElement( be, { ...i, className: i?.className ?? "w-full sm:max-w-[44%]", placeholder: i?.placeholder ?? "Buscar...", startContent: /* @__PURE__ */ o.createElement(Wt, null), value: Y, onClear: () => ce(), onValueChange: ue, isClearable: !0 } ), M), /* @__PURE__ */ o.createElement("div", { className: "flex flex-wrap justify-between items-center" }, /* @__PURE__ */ o.createElement("span", { className: "text-default-400 text-small" }, "Total ", f.length, " ", f.length == 1 ? m?.items?.[0] ?? "dato" : m?.items?.[1] ?? "datos"), !$ && !n && /* @__PURE__ */ o.createElement("label", { className: "flex items-center text-default-400 text-small" }, m.rowsPerPage, ":", /* @__PURE__ */ o.createElement( "select", { className: "bg-transparent outline-none text-default-400 text-small cursor-pointer", onChange: de, defaultValue: k }, N.options.map( (d) => /* @__PURE__ */ o.createElement("option", { key: d, value: d }, d) ) )))), [ Y, f.length, ce, de, m.rowsPerPage, i, M, ue, k, n, e, $, N, m.items ]); return /* @__PURE__ */ o.createElement(o.Fragment, null, t ? /* @__PURE__ */ o.createElement(Ut, { columns: y, size: k }) : /* @__PURE__ */ o.createElement(o.Fragment, null, et, /* @__PURE__ */ o.createElement( we, { ...T, "aria-label": T["aria-label"] ?? "Tabla de resultados", isVirtualized: n, isHeaderSticky: l, sortDescriptor: v, onSortChange: Ke, selectedKeys: K, onSelectionChange: ze, selectionMode: s, classNames: { ...c, wrapper: n && l ? "p-0" : c?.wrapper } }, /* @__PURE__ */ o.createElement(Me, { columns: y }, (d) => /* @__PURE__ */ o.createElement(ve, { ...d, children: void 0, key: d.key })), /* @__PURE__ */ o.createElement(Ce, { emptyContent: m.emptyContent, items: Qe }, (d) => /* @__PURE__ */ o.createElement(xe, { key: d[D] }, (u) => /* @__PURE__ */ o.createElement(Ie, { className: _ }, Xe(d, u)))) ), Ze)); }; function un({ display: e, onClose: t, children: n, title: r, cancelButton: a, acceptButton: l, ...c }) { return /* @__PURE__ */ o.createElement(bt, { isOpen: e, onOpenChange: t, ...c }, /* @__PURE__ */ o.createElement(Et, null, /* @__PURE__ */ o.createElement(wt, { className: "flex flex-col gap-1" }, r), /* @__PURE__ */ o.createElement(Mt, null, n), /* @__PURE__ */ o.createElement(vt, null, a && /* @__PURE__ */ o.createElement(W, { ...a, onPress: t }), l && /* @__PURE__ */ o.createElement(W, { ...l })))); } export { dn as DataTable, un as Modal, sn as Panel, an as RHFAutocomplete, on as RHFCheckbox, cn as RHFCheckboxGroup, Xt as RHFDate, Zt as RHFInput, en as RHFInputOtp, ln as RHFRadioGroup, tn as RHFSelect, rn as RHFTextArea, nn as RHFTime };