react-nepali-datetime
Version:
[](https://www.npmjs.com/package/react-nepali-datetime) [](https://github.com/opensource-nepal/react
950 lines (947 loc) • 32.1 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode('._calendarContainer_13lxa_1{margin-top:16px;color:#666;font-family:sans-serif;font-size:14px;font-weight:300;font-style:normal}._calendarGrid_13lxa_10{display:grid;grid-template-columns:repeat(7,1fr)}._calendarCell_13lxa_15{display:inline-flex;align-items:center;justify-content:center;width:45px;height:40px;user-select:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none}._calendarCellInactive_13lxa_28{opacity:.5}._calendarCell_13lxa_15:not(._calendarCellInactive_13lxa_28){cursor:pointer}._calendarCellCurrent_13lxa_36{color:#2096f5;font-weight:700}._calendarCellSelected_13lxa_41{position:relative;color:#fff;z-index:1}._calendarCellSelected_13lxa_41:after{content:"";background-color:#2096f5;border-radius:50%;width:40px;height:40px;position:absolute;z-index:-1}._prevNext_13lxa_56{width:22px;height:22px}._prevNext_13lxa_56 span{cursor:pointer}._calendarControls_13lxa_64{display:flex;justify-content:space-between}._popoverContent_qysd3_1{position:absolute;left:0;padding:16px;background-color:#fff;color:#444;box-shadow:0 4px 6px #0000001a;z-index:101}._pickerInput_1txhx_1{width:100%;box-sizing:border-box;-webkit-box-sizing:border-box;-moz-box-sizing:border-box}')),document.head.appendChild(e)}}catch(n){console.error("vite-plugin-css-injected-by-js",n)}})();
import $e, { useState as H, useRef as We, useCallback as Me, useLayoutEffect as Sr, useEffect as jr, cloneElement as wr } from "react";
import F from "nepali-datetime";
var z = { exports: {} }, B = {};
/**
* @license React
* react-jsx-runtime.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ie;
function Tr() {
if (Ie) return B;
Ie = 1;
var t = $e, a = Symbol.for("react.element"), v = Symbol.for("react.fragment"), i = Object.prototype.hasOwnProperty, E = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, _ = { key: !0, ref: !0, __self: !0, __source: !0 };
function y(p, d, R) {
var g, x = {}, C = null, O = null;
R !== void 0 && (C = "" + R), d.key !== void 0 && (C = "" + d.key), d.ref !== void 0 && (O = d.ref);
for (g in d) i.call(d, g) && !_.hasOwnProperty(g) && (x[g] = d[g]);
if (p && p.defaultProps) for (g in d = p.defaultProps, d) x[g] === void 0 && (x[g] = d[g]);
return { $$typeof: a, type: p, key: C, ref: O, props: x, _owner: E.current };
}
return B.Fragment = v, B.jsx = y, B.jsxs = y, B;
}
var G = {};
/**
* @license React
* react-jsx-runtime.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var Ye;
function Or() {
return Ye || (Ye = 1, process.env.NODE_ENV !== "production" && function() {
var t = $e, a = Symbol.for("react.element"), v = Symbol.for("react.portal"), i = Symbol.for("react.fragment"), E = Symbol.for("react.strict_mode"), _ = Symbol.for("react.profiler"), y = Symbol.for("react.provider"), p = Symbol.for("react.context"), d = Symbol.for("react.forward_ref"), R = Symbol.for("react.suspense"), g = Symbol.for("react.suspense_list"), x = Symbol.for("react.memo"), C = Symbol.for("react.lazy"), O = Symbol.for("react.offscreen"), S = Symbol.iterator, s = "@@iterator";
function A(e) {
if (e === null || typeof e != "object")
return null;
var r = S && e[S] || e[s];
return typeof r == "function" ? r : null;
}
var L = t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
function j(e) {
{
for (var r = arguments.length, n = new Array(r > 1 ? r - 1 : 0), o = 1; o < r; o++)
n[o - 1] = arguments[o];
Be("error", e, n);
}
}
function Be(e, r, n) {
{
var o = L.ReactDebugCurrentFrame, u = o.getStackAddendum();
u !== "" && (r += "%s", n = n.concat([u]));
var h = n.map(function(c) {
return String(c);
});
h.unshift("Warning: " + r), Function.prototype.apply.call(console[e], console, h);
}
}
var Ge = !1, He = !1, Je = !1, Ke = !1, qe = !1, ce;
ce = Symbol.for("react.module.reference");
function Xe(e) {
return !!(typeof e == "string" || typeof e == "function" || e === i || e === _ || qe || e === E || e === R || e === g || Ke || e === O || Ge || He || Je || typeof e == "object" && e !== null && (e.$$typeof === C || e.$$typeof === x || e.$$typeof === y || e.$$typeof === p || e.$$typeof === d || // This needs to include all possible module reference object
// types supported by any Flight configuration anywhere since
// we don't know which Flight build this will end up being used
// with.
e.$$typeof === ce || e.getModuleId !== void 0));
}
function ze(e, r, n) {
var o = e.displayName;
if (o)
return o;
var u = r.displayName || r.name || "";
return u !== "" ? n + "(" + u + ")" : n;
}
function ue(e) {
return e.displayName || "Context";
}
function N(e) {
if (e == null)
return null;
if (typeof e.tag == "number" && j("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."), typeof e == "function")
return e.displayName || e.name || null;
if (typeof e == "string")
return e;
switch (e) {
case i:
return "Fragment";
case v:
return "Portal";
case _:
return "Profiler";
case E:
return "StrictMode";
case R:
return "Suspense";
case g:
return "SuspenseList";
}
if (typeof e == "object")
switch (e.$$typeof) {
case p:
var r = e;
return ue(r) + ".Consumer";
case y:
var n = e;
return ue(n._context) + ".Provider";
case d:
return ze(e, e.render, "ForwardRef");
case x:
var o = e.displayName || null;
return o !== null ? o : N(e.type) || "Memo";
case C: {
var u = e, h = u._payload, c = u._init;
try {
return N(c(h));
} catch {
return null;
}
}
}
return null;
}
var M = Object.assign, V = 0, fe, de, ve, pe, he, _e, ge;
function me() {
}
me.__reactDisabledLog = !0;
function Ze() {
{
if (V === 0) {
fe = console.log, de = console.info, ve = console.warn, pe = console.error, he = console.group, _e = console.groupCollapsed, ge = console.groupEnd;
var e = {
configurable: !0,
enumerable: !0,
value: me,
writable: !0
};
Object.defineProperties(console, {
info: e,
log: e,
warn: e,
error: e,
group: e,
groupCollapsed: e,
groupEnd: e
});
}
V++;
}
}
function Qe() {
{
if (V--, V === 0) {
var e = {
configurable: !0,
enumerable: !0,
writable: !0
};
Object.defineProperties(console, {
log: M({}, e, {
value: fe
}),
info: M({}, e, {
value: de
}),
warn: M({}, e, {
value: ve
}),
error: M({}, e, {
value: pe
}),
group: M({}, e, {
value: he
}),
groupCollapsed: M({}, e, {
value: _e
}),
groupEnd: M({}, e, {
value: ge
})
});
}
V < 0 && j("disabledDepth fell below zero. This is a bug in React. Please file an issue.");
}
}
var Q = L.ReactCurrentDispatcher, ee;
function J(e, r, n) {
{
if (ee === void 0)
try {
throw Error();
} catch (u) {
var o = u.stack.trim().match(/\n( *(at )?)/);
ee = o && o[1] || "";
}
return `
` + ee + e;
}
}
var re = !1, K;
{
var er = typeof WeakMap == "function" ? WeakMap : Map;
K = new er();
}
function Ee(e, r) {
if (!e || re)
return "";
{
var n = K.get(e);
if (n !== void 0)
return n;
}
var o;
re = !0;
var u = Error.prepareStackTrace;
Error.prepareStackTrace = void 0;
var h;
h = Q.current, Q.current = null, Ze();
try {
if (r) {
var c = function() {
throw Error();
};
if (Object.defineProperty(c.prototype, "props", {
set: function() {
throw Error();
}
}), typeof Reflect == "object" && Reflect.construct) {
try {
Reflect.construct(c, []);
} catch (T) {
o = T;
}
Reflect.construct(e, [], c);
} else {
try {
c.call();
} catch (T) {
o = T;
}
e.call(c.prototype);
}
} else {
try {
throw Error();
} catch (T) {
o = T;
}
e();
}
} catch (T) {
if (T && o && typeof T.stack == "string") {
for (var l = T.stack.split(`
`), w = o.stack.split(`
`), m = l.length - 1, b = w.length - 1; m >= 1 && b >= 0 && l[m] !== w[b]; )
b--;
for (; m >= 1 && b >= 0; m--, b--)
if (l[m] !== w[b]) {
if (m !== 1 || b !== 1)
do
if (m--, b--, b < 0 || l[m] !== w[b]) {
var P = `
` + l[m].replace(" at new ", " at ");
return e.displayName && P.includes("<anonymous>") && (P = P.replace("<anonymous>", e.displayName)), typeof e == "function" && K.set(e, P), P;
}
while (m >= 1 && b >= 0);
break;
}
}
} finally {
re = !1, Q.current = h, Qe(), Error.prepareStackTrace = u;
}
var $ = e ? e.displayName || e.name : "", I = $ ? J($) : "";
return typeof e == "function" && K.set(e, I), I;
}
function rr(e, r, n) {
return Ee(e, !1);
}
function nr(e) {
var r = e.prototype;
return !!(r && r.isReactComponent);
}
function q(e, r, n) {
if (e == null)
return "";
if (typeof e == "function")
return Ee(e, nr(e));
if (typeof e == "string")
return J(e);
switch (e) {
case R:
return J("Suspense");
case g:
return J("SuspenseList");
}
if (typeof e == "object")
switch (e.$$typeof) {
case d:
return rr(e.render);
case x:
return q(e.type, r, n);
case C: {
var o = e, u = o._payload, h = o._init;
try {
return q(h(u), r, n);
} catch {
}
}
}
return "";
}
var U = Object.prototype.hasOwnProperty, ye = {}, be = L.ReactDebugCurrentFrame;
function X(e) {
if (e) {
var r = e._owner, n = q(e.type, e._source, r ? r.type : null);
be.setExtraStackFrame(n);
} else
be.setExtraStackFrame(null);
}
function tr(e, r, n, o, u) {
{
var h = Function.call.bind(U);
for (var c in e)
if (h(e, c)) {
var l = void 0;
try {
if (typeof e[c] != "function") {
var w = Error((o || "React class") + ": " + n + " type `" + c + "` is invalid; it must be a function, usually from the `prop-types` package, but received `" + typeof e[c] + "`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");
throw w.name = "Invariant Violation", w;
}
l = e[c](r, c, o, n, null, "SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");
} catch (m) {
l = m;
}
l && !(l instanceof Error) && (X(u), j("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).", o || "React class", n, c, typeof l), X(null)), l instanceof Error && !(l.message in ye) && (ye[l.message] = !0, X(u), j("Failed %s type: %s", n, l.message), X(null));
}
}
}
var ar = Array.isArray;
function ne(e) {
return ar(e);
}
function or(e) {
{
var r = typeof Symbol == "function" && Symbol.toStringTag, n = r && e[Symbol.toStringTag] || e.constructor.name || "Object";
return n;
}
}
function ir(e) {
try {
return xe(e), !1;
} catch {
return !0;
}
}
function xe(e) {
return "" + e;
}
function Re(e) {
if (ir(e))
return j("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.", or(e)), xe(e);
}
var Ce = L.ReactCurrentOwner, sr = {
key: !0,
ref: !0,
__self: !0,
__source: !0
}, Se, je;
function lr(e) {
if (U.call(e, "ref")) {
var r = Object.getOwnPropertyDescriptor(e, "ref").get;
if (r && r.isReactWarning)
return !1;
}
return e.ref !== void 0;
}
function cr(e) {
if (U.call(e, "key")) {
var r = Object.getOwnPropertyDescriptor(e, "key").get;
if (r && r.isReactWarning)
return !1;
}
return e.key !== void 0;
}
function ur(e, r) {
typeof e.ref == "string" && Ce.current;
}
function fr(e, r) {
{
var n = function() {
Se || (Se = !0, j("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
n.isReactWarning = !0, Object.defineProperty(e, "key", {
get: n,
configurable: !0
});
}
}
function dr(e, r) {
{
var n = function() {
je || (je = !0, j("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)", r));
};
n.isReactWarning = !0, Object.defineProperty(e, "ref", {
get: n,
configurable: !0
});
}
}
var vr = function(e, r, n, o, u, h, c) {
var l = {
// This tag allows us to uniquely identify this as a React Element
$$typeof: a,
// Built-in properties that belong on the element
type: e,
key: r,
ref: n,
props: c,
// Record the component responsible for creating this element.
_owner: h
};
return l._store = {}, Object.defineProperty(l._store, "validated", {
configurable: !1,
enumerable: !1,
writable: !0,
value: !1
}), Object.defineProperty(l, "_self", {
configurable: !1,
enumerable: !1,
writable: !1,
value: o
}), Object.defineProperty(l, "_source", {
configurable: !1,
enumerable: !1,
writable: !1,
value: u
}), Object.freeze && (Object.freeze(l.props), Object.freeze(l)), l;
};
function pr(e, r, n, o, u) {
{
var h, c = {}, l = null, w = null;
n !== void 0 && (Re(n), l = "" + n), cr(r) && (Re(r.key), l = "" + r.key), lr(r) && (w = r.ref, ur(r, u));
for (h in r)
U.call(r, h) && !sr.hasOwnProperty(h) && (c[h] = r[h]);
if (e && e.defaultProps) {
var m = e.defaultProps;
for (h in m)
c[h] === void 0 && (c[h] = m[h]);
}
if (l || w) {
var b = typeof e == "function" ? e.displayName || e.name || "Unknown" : e;
l && fr(c, b), w && dr(c, b);
}
return vr(e, l, w, u, o, Ce.current, c);
}
}
var te = L.ReactCurrentOwner, we = L.ReactDebugCurrentFrame;
function D(e) {
if (e) {
var r = e._owner, n = q(e.type, e._source, r ? r.type : null);
we.setExtraStackFrame(n);
} else
we.setExtraStackFrame(null);
}
var ae;
ae = !1;
function oe(e) {
return typeof e == "object" && e !== null && e.$$typeof === a;
}
function Te() {
{
if (te.current) {
var e = N(te.current.type);
if (e)
return `
Check the render method of \`` + e + "`.";
}
return "";
}
}
function hr(e) {
return "";
}
var Oe = {};
function _r(e) {
{
var r = Te();
if (!r) {
var n = typeof e == "string" ? e : e.displayName || e.name;
n && (r = `
Check the top-level render call using <` + n + ">.");
}
return r;
}
}
function Pe(e, r) {
{
if (!e._store || e._store.validated || e.key != null)
return;
e._store.validated = !0;
var n = _r(r);
if (Oe[n])
return;
Oe[n] = !0;
var o = "";
e && e._owner && e._owner !== te.current && (o = " It was passed a child from " + N(e._owner.type) + "."), D(e), j('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.', n, o), D(null);
}
}
function ke(e, r) {
{
if (typeof e != "object")
return;
if (ne(e))
for (var n = 0; n < e.length; n++) {
var o = e[n];
oe(o) && Pe(o, r);
}
else if (oe(e))
e._store && (e._store.validated = !0);
else if (e) {
var u = A(e);
if (typeof u == "function" && u !== e.entries)
for (var h = u.call(e), c; !(c = h.next()).done; )
oe(c.value) && Pe(c.value, r);
}
}
}
function gr(e) {
{
var r = e.type;
if (r == null || typeof r == "string")
return;
var n;
if (typeof r == "function")
n = r.propTypes;
else if (typeof r == "object" && (r.$$typeof === d || // Note: Memo only checks outer props here.
// Inner props are checked in the reconciler.
r.$$typeof === x))
n = r.propTypes;
else
return;
if (n) {
var o = N(r);
tr(n, e.props, "prop", o, e);
} else if (r.PropTypes !== void 0 && !ae) {
ae = !0;
var u = N(r);
j("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?", u || "Unknown");
}
typeof r.getDefaultProps == "function" && !r.getDefaultProps.isReactClassApproved && j("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.");
}
}
function mr(e) {
{
for (var r = Object.keys(e.props), n = 0; n < r.length; n++) {
var o = r[n];
if (o !== "children" && o !== "key") {
D(e), j("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.", o), D(null);
break;
}
}
e.ref !== null && (D(e), j("Invalid attribute `ref` supplied to `React.Fragment`."), D(null));
}
}
var Ae = {};
function Ne(e, r, n, o, u, h) {
{
var c = Xe(e);
if (!c) {
var l = "";
(e === void 0 || typeof e == "object" && e !== null && Object.keys(e).length === 0) && (l += " You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");
var w = hr();
w ? l += w : l += Te();
var m;
e === null ? m = "null" : ne(e) ? m = "array" : e !== void 0 && e.$$typeof === a ? (m = "<" + (N(e.type) || "Unknown") + " />", l = " Did you accidentally export a JSX literal instead of a component?") : m = typeof e, j("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", m, l);
}
var b = pr(e, r, n, u, h);
if (b == null)
return b;
if (c) {
var P = r.children;
if (P !== void 0)
if (o)
if (ne(P)) {
for (var $ = 0; $ < P.length; $++)
ke(P[$], e);
Object.freeze && Object.freeze(P);
} else
j("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");
else
ke(P, e);
}
if (U.call(r, "key")) {
var I = N(e), T = Object.keys(r).filter(function(Cr) {
return Cr !== "key";
}), ie = T.length > 0 ? "{key: someKey, " + T.join(": ..., ") + ": ...}" : "{key: someKey}";
if (!Ae[I + ie]) {
var Rr = T.length > 0 ? "{" + T.join(": ..., ") + ": ...}" : "{}";
j(`A props object containing a "key" prop is being spread into JSX:
let props = %s;
<%s {...props} />
React keys must be passed directly to JSX without using spread:
let props = %s;
<%s key={someKey} {...props} />`, ie, I, Rr, I), Ae[I + ie] = !0;
}
}
return e === i ? mr(b) : gr(b), b;
}
}
function Er(e, r, n) {
return Ne(e, r, n, !0);
}
function yr(e, r, n) {
return Ne(e, r, n, !1);
}
var br = yr, xr = Er;
G.Fragment = i, G.jsx = br, G.jsxs = xr;
}()), G;
}
var Fe;
function Pr() {
return Fe || (Fe = 1, process.env.NODE_ENV === "production" ? z.exports = Tr() : z.exports = Or()), z.exports;
}
var f = Pr();
const se = ["०", "१", "२", "३", "४", "५", "६", "७", "८", "९"], kr = "en", W = "ne", Z = kr, le = F.minSupportedNepaliDate().getYear(), Ve = F.maxSupportedNepaliDate().getYear(), Ar = [
"Baisakh",
"Jestha",
"Asar",
"Shrawan",
"Bhadra",
"Aswin",
"Kartik",
"Mangsir",
"Poush",
"Magh",
"Falgun",
"Chaitra"
], Nr = [
"बैशाख",
"जेठ",
"असार",
"श्रावण",
"भाद्र",
"आश्विन",
"कार्तिक",
"मंसिर",
"पौष",
"माघ",
"फाल्गुण",
"चैत्र"
], Mr = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], Ir = ["आइत", "सोम", "मंगल", "बुध", "बिहि", "शुक्र", "शनि"], Ue = (t) => t.toString().split("").map((a) => isNaN(Number(a)) ? a : se[Number(a)]).join(""), Yr = (t) => t.toString().split("").map((a) => se.includes(a) ? se.indexOf(a) : a).join(""), Fr = Array.from(
{ length: Ve - le + 1 },
(t, a) => a + le
), Lr = ({
selectedYear: t,
onChange: a,
locale: v = Z
}) => /* @__PURE__ */ f.jsx(
"select",
{
value: t,
onChange: (i) => a && a(Number(i.target.value)),
children: Fr.map((i) => /* @__PURE__ */ f.jsx("option", { value: i, children: v === W ? Ue(i) : i }, i))
}
), Dr = (t) => t === W ? Nr : Ar, $r = ({
selectedMonth: t,
onChange: a,
locale: v = Z
}) => /* @__PURE__ */ f.jsx(
"select",
{
value: t,
onChange: (i) => a && a(Number(i.target.value)),
children: Dr(v).map((i, E) => /* @__PURE__ */ f.jsx("option", { value: E, children: i }, i))
}
), Le = 7, De = (t, a) => {
try {
return F.getDaysOfMonth(t, a);
} catch {
return null;
}
}, Wr = (t, a) => {
const v = De(t, a);
if (!v)
return [];
const i = new F(t, a, 1).getDay(), [E, _] = a === 0 ? [t - 1, 11] : [t, a - 1], y = De(E, _), [p, d] = a === 11 ? [t + 1, 0] : [t, a + 1], R = Math.ceil((i + v) / Le) * Le;
return Array(R).fill(null).map((x, C) => {
let O, S, s, A;
return C < i ? (O = y ? y - (i - C - 1) : null, S = _, s = E, A = !1) : C < i + v ? (O = C - i + 1, S = a, s = t, A = !0) : (O = C - (i + v) + 1, S = d, s = p, A = !1), {
index: C,
active: A,
year: s,
month: S,
date: O
};
});
}, Y = (...t) => t.filter(Boolean).join(" "), Vr = "_calendarContainer_13lxa_1", Ur = "_calendarGrid_13lxa_10", Br = "_calendarCell_13lxa_15", Gr = "_calendarCellInactive_13lxa_28", Hr = "_calendarCellCurrent_13lxa_36", Jr = "_calendarCellSelected_13lxa_41", Kr = "_prevNext_13lxa_56", qr = "_calendarControls_13lxa_64", k = {
calendarContainer: Vr,
calendarGrid: Ur,
calendarCell: Br,
calendarCellInactive: Gr,
calendarCellCurrent: Hr,
calendarCellSelected: Jr,
prevNext: Kr,
calendarControls: qr
}, Xr = ({
selectedNepaliDate: t,
onDateSelect: a = null,
locale: v = Z
}) => {
const i = new F(), E = v === W ? Ir : Mr, [_, y] = H(
(t == null ? void 0 : t.getYear()) ?? i.getYear()
), [p, d] = H(
(t == null ? void 0 : t.getMonth()) ?? i.getMonth()
), R = (s) => s.year === i.getYear() && s.month === i.getMonth() && s.date === i.getDate(), g = (s) => t && s.year === t.getYear() && s.month === t.getMonth() && s.date === t.getDate(), x = (s) => {
!s.active || !s.date || !a || a(new F(_, p, s.date));
}, C = () => {
if (_ === le && p === 0)
return;
const [s, A] = p === 0 ? [_ - 1, 11] : [_, p - 1];
y(s), d(A);
}, O = () => {
if (_ === Ve && p === 11)
return;
const [s, A] = p === 11 ? [_ + 1, 0] : [_, p + 1];
y(s), d(A);
}, S = Wr(_, p);
return /* @__PURE__ */ f.jsxs("div", { className: "ndt-calendar", children: [
/* @__PURE__ */ f.jsxs("div", { className: `ndt-calendar-controls ${k.calendarControls}`, children: [
/* @__PURE__ */ f.jsx("div", { className: `ndt-prev ${k.prevNext}`, children: /* @__PURE__ */ f.jsx("span", { onClick: C, children: /* @__PURE__ */ f.jsx(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 24 24",
children: /* @__PURE__ */ f.jsx(
"path",
{
fill: "none",
fillRule: "evenodd",
stroke: "currentcolor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: "2.4",
d: "M16.283 18.907L9.6 12l6.683-5.438"
}
)
}
) }) }),
/* @__PURE__ */ f.jsxs("div", { children: [
/* @__PURE__ */ f.jsx(
Lr,
{
selectedYear: _,
onChange: (s) => y(s),
locale: v
}
),
/* @__PURE__ */ f.jsx(
$r,
{
selectedMonth: p,
onChange: (s) => d(s),
locale: v
}
)
] }),
/* @__PURE__ */ f.jsx("div", { className: `ndt-next ${k.prevNext}`, children: /* @__PURE__ */ f.jsx("span", { onClick: O, children: /* @__PURE__ */ f.jsx(
"svg",
{
xmlns: "http://www.w3.org/2000/svg",
xmlnsXlink: "http://www.w3.org/1999/xlink",
viewBox: "0 0 24 24",
children: /* @__PURE__ */ f.jsx(
"path",
{
transform: "rotate(180 12 12)",
fill: "none",
fillRule: "evenodd",
stroke: "currentcolor",
strokeLinecap: "round",
strokeLinejoin: "round",
strokeWidth: "2.4",
d: "M16.283 18.907L9.6 12l6.683-5.438"
}
)
}
) }) })
] }),
/* @__PURE__ */ f.jsxs("div", { className: `ndt-calendar-container ${k.calendarContainer}`, children: [
/* @__PURE__ */ f.jsx("div", { className: `ndt-calendar-grid ${k.calendarGrid}`, children: E.map((s) => /* @__PURE__ */ f.jsx(
"div",
{
className: Y("ndt-calendar-header", k.calendarCell),
children: s
},
s
)) }),
/* @__PURE__ */ f.jsx("div", { className: `ndt-calendar-grid ${k.calendarGrid}`, children: S.map((s) => /* @__PURE__ */ f.jsx(
"div",
{
onClick: () => x(s),
className: Y(
"ndt-calendar-cell",
k.calendarCell,
g(s) && Y("ndt-calendar-cell-selected", k.calendarCellSelected),
R(s) && Y("ndt-calendar-cell-current", k.calendarCellCurrent),
!s.active && k.calendarCellInactive
),
children: s.date && v === W ? Ue(s.date) : s.date
},
s.index
)) })
] })
] });
}, zr = "_popoverContent_qysd3_1", Zr = {
popoverContent: zr
}, Qr = 150, en = ({
popoverChildRef: t,
children: a,
onOutsideClick: v
}) => {
const i = We(null), [E, _] = H(), y = Me(() => {
const d = t == null ? void 0 : t.current;
if (!d) {
_({});
return;
}
const { bottom: R, height: g } = d.getBoundingClientRect(), x = R + Qr > window.innerHeight;
_(x ? { bottom: g } : { top: g });
}, [t]), p = Me(
(d) => {
var g, x;
if (!v)
return;
const R = d.target;
!((g = t == null ? void 0 : t.current) != null && g.contains(R)) && !((x = i.current) != null && x.contains(R)) && v();
},
[t, v]
);
return Sr(() => (y(), document.addEventListener("mousedown", p), () => document.removeEventListener("mousedown", p)), [p, y]), E ? /* @__PURE__ */ f.jsx(
"div",
{
className: Y("ndt-popover-content", Zr.popoverContent),
ref: i,
style: E,
children: a
}
) : null;
}, rn = ({
children: t,
content: a,
open: v = !1,
onOpenChange: i,
className: E
}) => {
const _ = We(null), y = (p) => {
i && i(p);
};
return /* @__PURE__ */ f.jsxs(
"div",
{
className: Y("ndt-popover", E),
style: { position: "relative" },
children: [
/* @__PURE__ */ f.jsx(
"div",
{
className: "ndt-popover-child",
ref: _,
onClick: () => y(!0),
children: t
}
),
v && /* @__PURE__ */ f.jsx(
en,
{
onOutsideClick: () => y(!1),
popoverChildRef: _,
children: a
}
)
]
}
);
}, nn = "_pickerInput_1txhx_1", tn = {
pickerInput: nn
}, an = ({ className: t, ...a }) => /* @__PURE__ */ f.jsx(
"input",
{
className: Y("ndt-picker-input", tn.pickerInput, t),
type: "text",
...a
}
), on = (t, a, v) => {
const i = v === W ? Yr(t) : t;
try {
return new F(i, a);
} catch {
return null;
}
}, cn = ({
value: t = "",
format: a = "YYYY-MM-DD",
inputElement: v = null,
onDateSelect: i = null,
locale: E = Z,
..._
}) => {
const [y, p] = H(!1), [d, R] = H(t), g = { value: d, readOnly: !0 };
jr(() => {
R(t);
}, [t]);
const x = (S) => {
R(S), i && i(S);
}, C = (S) => {
const s = E === W ? S.formatNepali(a) : S.format(a);
x(s), p(!1);
}, O = v && wr(v, { ..._, ...g });
return /* @__PURE__ */ f.jsx(
rn,
{
className: "ndt-date-picker",
open: y,
onOpenChange: (S) => p(S),
content: /* @__PURE__ */ f.jsx(
Xr,
{
locale: E,
selectedNepaliDate: on(d, a, E),
onDateSelect: C
}
),
children: O || /* @__PURE__ */ f.jsx(an, { ..._, ...g })
}
);
};
export {
Xr as NepaliCalendar,
cn as NepaliDatePicker
};