rhf-hero-ui
Version:
React Components with React Hook Form and HeroUI
970 lines (969 loc) • 34.6 kB
JavaScript
import o, { useCallback as x, useState as B, useEffect as Ee, useMemo as F } from "react";
import { DatePicker as at, Input as we, InputOtp as lt, Select as ot, SelectItem as ct, TimeInput as st, Textarea as it, Autocomplete as dt, AutocompleteItem as ut, RadioGroup as ht, Radio as ft, Checkbox as Me, CheckboxGroup as mt, Card as $t, CardHeader as yt, Divider as gt, CardBody as pt, Table as ve, TableHeader as Ce, TableColumn as xe, TableBody as De, TableRow as Ie, TableCell as ke, Skeleton as bt, Pagination as Et, Button as H, Modal as wt, ModalContent as Mt, ModalHeader as vt, ModalBody as Ct, ModalFooter as xt } from "@heroui/react";
import { Controller as w } from "react-hook-form";
function ee(e, t) {
return e - t * Math.floor(e / t);
}
const Se = 1721426;
function J(e, t, n, r) {
t = ae(e, t);
let a = t - 1, l = -2;
return n <= 2 ? l = 0 : G(t) && (l = -1), Se - 1 + 365 * a + Math.floor(a / 4) - Math.floor(a / 100) + Math.floor(a / 400) + Math.floor((367 * n - 362) / 12 + l + r);
}
function G(e) {
return e % 4 === 0 && (e % 100 !== 0 || e % 400 === 0);
}
function ae(e, t) {
return e === "BC" ? 1 - t : t;
}
function Dt(e) {
let t = "AD";
return e <= 0 && (t = "BC", e = 1 - e), [
t,
e
];
}
const It = {
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 K {
fromJulianDay(t) {
let n = t, r = n - Se, a = Math.floor(r / 146097), l = ee(r, 146097), c = Math.floor(l / 36524), s = ee(l, 36524), i = Math.floor(s / 1461), m = ee(s, 1461), M = Math.floor(m / 365), q = a * 400 + c * 100 + i * 4 + M + (c !== 4 && M !== 4 ? 1 : 0), [N, f] = Dt(q), p = n - J(N, f, 1, 1), v = 2;
n < J(N, f, 3, 1) ? v = 0 : G(f) && (v = 1);
let $ = Math.floor(((p + v) * 12 + 373) / 367), Y = n - J(N, f, $, 1) + 1;
return new O(N, f, $, Y);
}
toJulianDay(t) {
return J(t.era, t.year, t.month, t.day);
}
getDaysInMonth(t) {
return It[G(t.year) ? "leapyear" : "standard"][t.month - 1];
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getMonthsInYear(t) {
return 12;
}
getDaysInYear(t) {
return G(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 kt(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 Be(e, t) {
return e.calendar.toJulianDay(e) - t.calendar.toJulianDay(t);
}
function Ne(e, t) {
return $e(e) - $e(t);
}
function $e(e) {
return e.hour * 36e5 + e.minute * 6e4 + e.second * 1e3 + e.millisecond;
}
let te = null;
function Te() {
return te == null && (te = new Intl.DateTimeFormat().resolvedOptions().timeZone), te;
}
function ye(e) {
e = le(e, new K());
let t = ae(e.era, e.year);
return Fe(t, e.month, e.day, e.hour, e.minute, e.second, e.millisecond);
}
function Fe(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 ge(e, t) {
if (t === "UTC") return 0;
if (e > 0 && t === Te()) return new Date(e).getTimezoneOffset() * -6e4;
let { year: n, month: r, day: a, hour: l, minute: c, second: s } = Pe(e, t);
return Fe(n, r, a, l, c, s, 0) - Math.floor(e / 1e3) * 1e3;
}
const pe = /* @__PURE__ */ new Map();
function Pe(e, t) {
let n = pe.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"
}), pe.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 be = 864e5;
function St(e, t, n, r) {
return (n === r ? [
n
] : [
n,
r
]).filter((l) => Bt(e, t, l));
}
function Bt(e, t, n) {
let r = Pe(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 Nt(e, t, n = "compatible") {
let r = Ae(e);
if (t === "UTC") return ye(r);
if (t === Te() && n === "compatible") {
r = le(r, new K());
let i = /* @__PURE__ */ new Date(), m = ae(r.era, r.year);
return i.setFullYear(m, r.month - 1, r.day), i.setHours(r.hour, r.minute, r.second, r.millisecond), i.getTime();
}
let a = ye(r), l = ge(a - be, t), c = ge(a + be, t), s = St(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 Ye(e, t, n = "compatible") {
return new Date(Nt(e, t, n));
}
function Ae(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 L(e.calendar, e.era, e.year, e.month, e.day, n, r, a, l);
}
function le(e, t) {
if (kt(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 oe(e, t) {
let n = e.copy(), r = "hour" in n ? qe(n, t) : 0;
ne(n, t.years || 0), n.calendar.balanceYearMonth && n.calendar.balanceYearMonth(n, e), n.month += t.months || 0, re(n), Re(n), n.day += (t.weeks || 0) * 7, n.day += t.days || 0, n.day += r, Tt(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 ne(e, t) {
var n, r;
!((n = (r = e.calendar).isInverseEra) === null || n === void 0) && n.call(r, e) && (t = -t), e.year += t;
}
function re(e) {
for (; e.month < 1; )
ne(e, -1), e.month += e.calendar.getMonthsInYear(e);
let t = 0;
for (; e.month > (t = e.calendar.getMonthsInYear(e)); )
e.month -= t, ne(e, 1);
}
function Tt(e) {
for (; e.day < 1; )
e.month--, re(e), e.day += e.calendar.getDaysInMonth(e);
for (; e.day > e.calendar.getDaysInMonth(e); )
e.day -= e.calendar.getDaysInMonth(e), e.month++, re(e);
}
function Re(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)), Re(e);
}
function je(e) {
let t = {};
for (let n in e) typeof e[n] == "number" && (t[n] = -e[n]);
return t;
}
function He(e, t) {
return oe(e, je(t));
}
function Ve(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 Oe(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), Le(n), n;
}
function Ft(e) {
e.second += Math.floor(e.millisecond / 1e3), e.millisecond = _(e.millisecond, 1e3), e.minute += Math.floor(e.second / 60), e.second = _(e.second, 60), e.hour += Math.floor(e.minute / 60), e.minute = _(e.minute, 60);
let t = Math.floor(e.hour / 24);
return e.hour = _(e.hour, 24), t;
}
function Le(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 _(e, t) {
let n = e % t;
return n < 0 && (n += t), n;
}
function qe(e, t) {
return e.hour += t.hours || 0, e.minute += t.minutes || 0, e.second += t.seconds || 0, e.millisecond += t.milliseconds || 0, Ft(e);
}
function Ue(e, t) {
let n = e.copy();
return qe(n, t), n;
}
function Pt(e, t) {
return Ue(e, je(t));
}
function We(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 Je(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 Yt = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})$/, At = /^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}))?(?::(\d{2}))?(?::(\d{2}))?(\.\d+)?$/;
function Rt(e) {
let t = e.match(Yt);
if (!t) throw new Error("Invalid ISO 8601 date string: " + e);
let n = new O(E(t[1], 0, 9999), E(t[2], 1, 12), 1);
return n.day = E(t[3], 1, n.calendar.getDaysInMonth(n)), n;
}
function jt(e) {
let t = e.match(At);
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 L(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 _e(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 Ge(e) {
let t = le(e, new K()), 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 Ht(e) {
return `${Ge(e)}T${_e(e)}`;
}
function Vt(e, t) {
if (t.has(e))
throw new TypeError("Cannot initialize the same private elements twice on an object");
}
function ce(e, t, n) {
Vt(e, t), t.set(e, n);
}
function Ke(e) {
let t = typeof e[0] == "object" ? e.shift() : new K(), 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 Ot = /* @__PURE__ */ new WeakMap();
class O {
/** Returns a copy of this date. */
copy() {
return this.era ? new O(this.calendar, this.era, this.year, this.month, this.day) : new O(this.calendar, this.year, this.month, this.day);
}
/** Returns a new `CalendarDate` with the given duration added to it. */
add(t) {
return oe(this, t);
}
/** Returns a new `CalendarDate` with the given duration subtracted from it. */
subtract(t) {
return He(this, t);
}
/** Returns a new `CalendarDate` with the given fields set to the provided values. Other fields will be constrained accordingly. */
set(t) {
return Ve(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 We(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 Ye(this, t);
}
/** Converts the date to an ISO 8601 formatted string. */
toString() {
return Ge(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 Be(this, t);
}
constructor(...t) {
ce(this, Ot, {
writable: !0,
value: void 0
});
let [n, r, a, l, c] = Ke(t);
this.calendar = n, this.era = r, this.year = a, this.month = l, this.day = c, P(this);
}
}
var Lt = /* @__PURE__ */ new WeakMap();
class V {
/** Returns a copy of this time. */
copy() {
return new V(this.hour, this.minute, this.second, this.millisecond);
}
/** Returns a new `Time` with the given duration added to it. */
add(t) {
return Ue(this, t);
}
/** Returns a new `Time` with the given duration subtracted from it. */
subtract(t) {
return Pt(this, t);
}
/** Returns a new `Time` with the given fields set to the provided values. Other fields will be constrained accordingly. */
set(t) {
return Oe(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 Je(this, t, n, r);
}
/** Converts the time to an ISO 8601 formatted string. */
toString() {
return _e(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 Ne(this, t);
}
constructor(t = 0, n = 0, r = 0, a = 0) {
ce(this, Lt, {
writable: !0,
value: void 0
}), this.hour = t, this.minute = n, this.second = r, this.millisecond = a, Le(this);
}
}
var qt = /* @__PURE__ */ new WeakMap();
class L {
/** Returns a copy of this date. */
copy() {
return this.era ? new L(this.calendar, this.era, this.year, this.month, this.day, this.hour, this.minute, this.second, this.millisecond) : new L(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 oe(this, t);
}
/** Returns a new `CalendarDateTime` with the given duration subtracted from it. */
subtract(t) {
return He(this, t);
}
/** Returns a new `CalendarDateTime` with the given fields set to the provided values. Other fields will be constrained accordingly. */
set(t) {
return Ve(Oe(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 We(this, t, n, r);
default:
return Je(this, t, n, r);
}
}
/** Converts the date to a native JavaScript Date object in the given time zone. */
toDate(t, n) {
return Ye(this, t, n);
}
/** Converts the date to an ISO 8601 formatted string. */
toString() {
return Ht(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 = Be(this, t);
return n === 0 ? Ne(this, Ae(t)) : n;
}
constructor(...t) {
ce(this, qt, {
writable: !0,
value: void 0
});
let [n, r, a, l, c] = Ke(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 en = ({ name: e, granularity: t, rules: n, ...r }) => {
const a = x((l) => t === "day" || !t ? Rt(l) : jt(l), [t]);
return /* @__PURE__ */ o.createElement(
w,
{
defaultValue: "",
name: e,
rules: n,
render: ({ field: l, formState: { errors: c } }) => /* @__PURE__ */ o.createElement(
at,
{
...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
}
)
}
);
}, tn = ({ 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(
we,
{
...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" : ""}`
}
}
)
}
), nn = ({ 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(
lt,
{
...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" : ""}`
}
}
)
}
), rn = ({ 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(
ot,
{
...c,
...s,
onChange: (m) => {
const M = m.target.value;
e === "multiple" ? s.onChange(M ? M.split(",") : []) : s.onChange(M ?? ""), l?.(m);
},
items: r,
selectedKeys: e === "multiple" ? s.value : [s.value],
errorMessage: i[t]?.message || "",
isInvalid: !!i[t],
disabledKeys: a,
selectionMode: e
},
(m) => /* @__PURE__ */ o.createElement(ct, { ...m, key: m.key })
)
}
), an = ({ name: e, shouldUnregister: t, granularity: n, rules: r, ...a }) => {
const l = x((c) => {
if (n === "second") {
const [s, i, m] = c.split(":").map(Number);
return new V(s, i, m);
} else if (n === "minute" || !n) {
const [s, i] = c.split(":").map(Number);
return new V(s, i);
} else {
const [s] = c.split(":").map(Number);
return new V(s);
}
}, [n]);
return /* @__PURE__ */ o.createElement(
w,
{
name: e,
rules: r,
shouldUnregister: t,
defaultValue: "",
render: ({ field: c, formState: { errors: s } }) => /* @__PURE__ */ o.createElement(
st,
{
...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 : ""
}
)
}
);
}, ln = ({ 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(
it,
{
...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" : ""}`
}
}
)
}
), on = ({ 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(
dt,
{
...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(ut, { ...i, key: i.key }))
)
}
), cn = ({ 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(
ht,
{
...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(ft, { ...c, key: s }))
)
}
), sn = ({ rules: e, name: t, ...n }) => /* @__PURE__ */ o.createElement(
w,
{
rules: e,
name: t,
render: ({ field: r, formState: { errors: a } }) => /* @__PURE__ */ o.createElement(
Me,
{
...n,
...r,
isSelected: !!r.value,
isInvalid: !!a[t]
},
n.children
)
}
), dn = ({ 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(
mt,
{
...a,
...l,
isInvalid: !!c[n],
onChange: (s) => {
l.onChange(s), e?.(s);
}
},
r.map((s) => /* @__PURE__ */ o.createElement(Me, { ...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 ?? "")
)
}
), Ut = () => /* @__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" })), 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-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" })), un = ({ title: e, color: t = "default", children: n, collapse: r = !1 }) => {
const [a, l] = B(!0);
return /* @__PURE__ */ o.createElement($t, { className: "mb-5" }, /* @__PURE__ */ o.createElement(yt, { 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(Ut, null) : /* @__PURE__ */ o.createElement(Wt, null))), /* @__PURE__ */ o.createElement(gt, null), /* @__PURE__ */ o.createElement(pt, { className: `p-5 ${a ? "" : "hidden"}` }, n));
}, Jt = ({ size: e, columns: t }) => /* @__PURE__ */ o.createElement(ve, { "aria-label": "cargando" }, /* @__PURE__ */ o.createElement(Ce, null, t.map(
(n) => /* @__PURE__ */ o.createElement(xe, { ...t, key: n.key }, n.title)
)), /* @__PURE__ */ o.createElement(De, null, Array.from(
{ length: e },
(n, r) => /* @__PURE__ */ o.createElement(Ie, { key: r }, () => /* @__PURE__ */ o.createElement(ke, null, /* @__PURE__ */ o.createElement(bt, { className: "h-5 w-4/5 rounded-lg" })))
))), _t = () => /* @__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" })), Gt = (e, t) => {
const [n, r] = B(e);
return Ee(() => {
const a = setTimeout(() => {
r(e);
}, t);
return () => {
clearTimeout(a);
};
}, [e, t]), n;
}, hn = ({
hideFilterSearch: e,
loading: t,
isVirtualized: n,
onSelect: r,
onSelectionChange: a,
isHeaderSticky: l,
classNames: c,
exportButton: s,
selectionMode: i,
inputSearch: m,
hideRowsPerPageOptions: M,
extraTopContent: q,
cellClass: N,
rows: f,
columns: p,
keyRow: v = "id",
localText: $ = { emptyContent: "No hay datos.", rowsPerPage: "Filas por pagina" },
onExport: Y,
rowsPerPageOptions: z = { default: 10, options: [5, 10, 15] },
...A
}) => {
const [R, Q] = B(""), [k, ze] = B(z.default), [y, S] = B(1), [X, Z] = B(/* @__PURE__ */ new Set()), [C, Qe] = B(A.sortDescriptor), se = !!Gt(R, 500), U = F(() => [...X].length, [X]);
Ee(() => {
f && (S(1), Z(/* @__PURE__ */ new Set()));
}, [f]);
const Xe = x((d) => {
Z(d);
let u = [];
i === "single" ? u = f.find((h) => h[v] == [...d][0]) : d === "all" ? (u = f, Z(new Set(f.map((h) => h[v].toString())))) : u = f.filter((h) => [...d].includes(h[v].toString())), r && r(u), a && a(d);
}, [r, f, i, v, a]), W = F(() => {
let d = [...f];
return se && (d = d.filter(
(u) => Object.values(u).some(
(h, b) => {
const D = Object.keys(u)[b], g = p.find((rt) => rt.key == D);
return !g || h == null || !h ? !1 : (g.onFilter ? g.onFilter(h) : h).toString().toLowerCase().includes(R.toLowerCase());
}
)
)), d;
}, [R, se, f, p]), j = Math.ceil(W.length / k) || 1, T = F(() => C === void 0 ? W : [...W].sort((d, u) => {
const h = p.find((me) => me.key === C.column), b = h?.onOrder ? h.onOrder(d[C.column]) : d[C.column], D = h?.onOrder ? h.onOrder(u[C.column]) : u[C.column];
let g = 0;
return !b && !D && (g = 0), b || (g = -1), D || (g = 1), typeof b == "number" && typeof D == "number" && (g = b - D), typeof b == "string" && typeof D == "string" && (g = (b ?? "").localeCompare(D ?? "")), C.direction === "descending" ? -g : g;
}), [C, W, p]), Ze = F(() => {
if (n) return T;
const d = (y - 1) * k, u = d + k;
return T.slice(d, u);
}, [T, y, k, n]), ie = x(() => {
Q(""), S(1);
}, []), de = x(() => {
y < j && S(y + 1);
}, [y, j]), ue = x(() => {
y > 1 && S(y - 1);
}, [y]), he = x((d) => {
ze(Number(d.target.value)), S(1);
}, []), fe = x((d) => {
d ? (Q(d), S(1)) : Q("");
}, []), et = x((d, u) => {
const h = p.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]);
}, [p]), tt = 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" }, U > 0 && /* @__PURE__ */ o.createElement(o.Fragment, null, U, " ", U === 1 ? $?.items?.[0] ?? "fila seleccionada" : $?.items?.[1] ?? "filas seleccionadas")), !n && /* @__PURE__ */ o.createElement(o.Fragment, null, /* @__PURE__ */ o.createElement(
Et,
{
isCompact: !0,
showControls: !0,
showShadow: !0,
page: y,
total: j,
onChange: S,
color: A.color
}
), /* @__PURE__ */ o.createElement("div", { className: "hidden sm:flex w-[30%] justify-end gap-2" }, /* @__PURE__ */ o.createElement(H, { isDisabled: y === 1, size: "sm", variant: "flat", onPress: ue }, $.paginateButtons?.[0] ?? "Atrás"), /* @__PURE__ */ o.createElement(H, { isDisabled: y === j, size: "sm", variant: "flat", onPress: de }, $.paginateButtons?.[1] ?? "Siguiente")))),
[
y,
j,
de,
ue,
U,
A.color,
n,
$.paginateButtons,
$.items
]
), nt = 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(
we,
{
...m,
className: m?.className ?? "w-full sm:max-w-[44%]",
placeholder: m?.placeholder ?? "Buscar...",
startContent: /* @__PURE__ */ o.createElement(_t, null),
value: R,
onClear: () => ie(),
onValueChange: fe,
isClearable: !0
}
), /* @__PURE__ */ o.createElement("div", { className: "flex flex-wrap gap-2" }, q, Y && /* @__PURE__ */ o.createElement(H, { ...s, onPress: () => T.length > 0 && Y(T) }))), /* @__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 ? $?.items?.[0] ?? "dato" : $?.items?.[1] ?? "datos"), !M && !n && /* @__PURE__ */ o.createElement("label", { className: "flex items-center text-default-400 text-small" }, $.rowsPerPage, ":", /* @__PURE__ */ o.createElement(
"select",
{
className: "bg-transparent outline-none text-default-400 text-small cursor-pointer",
onChange: he,
defaultValue: k
},
z.options.map(
(d) => /* @__PURE__ */ o.createElement("option", { key: d, value: d }, d)
)
)))), [
R,
f.length,
ie,
he,
$.rowsPerPage,
s,
m,
q,
fe,
k,
n,
T,
e,
M,
z,
$.items,
Y
]);
return /* @__PURE__ */ o.createElement(o.Fragment, null, t ? /* @__PURE__ */ o.createElement(Jt, { columns: p, size: k }) : /* @__PURE__ */ o.createElement(o.Fragment, null, nt, /* @__PURE__ */ o.createElement(
ve,
{
...A,
"aria-label": A["aria-label"] ?? "Tabla de resultados",
isVirtualized: n,
isHeaderSticky: l,
sortDescriptor: C,
onSortChange: Qe,
selectedKeys: X,
onSelectionChange: Xe,
selectionMode: i,
classNames: {
...c,
wrapper: n && l ? "p-0" : c?.wrapper
}
},
/* @__PURE__ */ o.createElement(Ce, { columns: p }, (d) => /* @__PURE__ */ o.createElement(xe, { ...d, children: void 0, key: d.key })),
/* @__PURE__ */ o.createElement(De, { emptyContent: $.emptyContent, items: Ze }, (d) => /* @__PURE__ */ o.createElement(Ie, { key: d[v] }, (u) => /* @__PURE__ */ o.createElement(ke, { className: N }, et(d, u))))
), tt));
};
function fn({ display: e, onClose: t, children: n, title: r, cancelButton: a, acceptButton: l, ...c }) {
return /* @__PURE__ */ o.createElement(wt, { isOpen: e, onOpenChange: t, ...c }, /* @__PURE__ */ o.createElement(Mt, null, /* @__PURE__ */ o.createElement(vt, { className: "flex flex-col gap-1" }, r), /* @__PURE__ */ o.createElement(Ct, null, n), /* @__PURE__ */ o.createElement(xt, null, a && /* @__PURE__ */ o.createElement(H, { ...a, onPress: t }), l && /* @__PURE__ */ o.createElement(H, { ...l }))));
}
export {
hn as DataTable,
fn as Modal,
un as Panel,
on as RHFAutocomplete,
sn as RHFCheckbox,
dn as RHFCheckboxGroup,
en as RHFDate,
tn as RHFInput,
nn as RHFInputOtp,
cn as RHFRadioGroup,
rn as RHFSelect,
ln as RHFTextArea,
an as RHFTime
};