date-picker-np
Version:
Nepali Date Picker for React
884 lines (883 loc) • 35.4 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".date-picker-container,.date-picker-container *{box-sizing:border-box;margin:0}.date-picker-container{position:relative;font-family:sans-serif;font-size:12px;-webkit-user-select:none;user-select:none;color:#0e0e0e;width:fit-content}.date-picker-input-container{position:relative;border-radius:4px;border:1px solid gray}.date-picker-input{border-radius:4px;border:none;outline:none;min-width:140px;width:100%;min-height:28px;padding:0 10px;display:flex;align-items:center}.date-picker-input:focus{outline:none}.date-picker-input-container-disabled{opacity:.5;cursor:not-allowed}.date-picker-input-disabled{cursor:not-allowed}.date-picker-input-right-icon{display:flex;position:absolute;right:8px;top:50%;transform:translateY(-50%);pointer-events:none}:root{--date-picker-np-hover-color: rgb(218, 218, 218)}.date-picker-body-container{display:grid;grid-template-columns:repeat(7,1fr);text-align:center}.date-picker-week-days-container>div{padding:4px 0 8px}.date-picker-dates-container>div{line-height:30px;height:30px;cursor:pointer}.date-picker-dates-container .prev-month-days,.date-picker-dates-container .next-month-days{opacity:.4;cursor:default}.date-picker-dates-container>div:not(.prev-month-days,.next-month-days,.date-picker-date-disabled,.date-picker-selected-date):hover{background:var(--date-picker-np-hover-color)}.date-picker-dates-container .date-picker-selected-date{background:#0085b1;color:#fff}.date-picker-dates-container>.date-picker-date-disabled{background:#fff;opacity:.4;cursor:default}.date-picker-calendar{position:absolute;top:20%;border:1px solid rgb(226,226,226);box-shadow:0 0 20px #0000001a;border-radius:4px;min-width:220px;width:220px;min-height:284px;height:284px;background:#fff;padding:4px 8px}.date-picker-calendar-header{display:flex;justify-content:space-between;align-items:center;margin:2px 0}.date-picker-calendar-header-arrow{display:flex;justify-content:center;align-items:center;cursor:pointer;width:30px;height:30px}.date-picker-calendar-header-arrow.date-picker-calendar-header-arrow-disabled{opacity:.4;cursor:default}.date-picker-calendar-header-dropdown-text{border:1px solid gray;padding:4px 10px;cursor:pointer}.date-picker-selector-container{position:absolute;bottom:0;left:0;z-index:1;display:flex;flex-direction:column;width:100%;height:100%;background:#fff;padding:4px 8px 10px}.date-picker-selector-header{display:flex;align-items:center;justify-content:center;height:34px;flex-shrink:0}.date-picker-selector-block-container{display:grid;grid-template-columns:repeat(3,1fr);overflow:hidden;flex:1}.date-picker-selector-block-container>div{display:grid;place-items:center;cursor:pointer}.date-picker-selector-block-container>div>div{padding:10px}.date-picker-selector-block-container>div>div.date-picker-selector-block-selected{color:#fff;background:#02769c}.date-picker-selector-block-container>div.date-picker-selector-block-disabled{opacity:.4;cursor:default}.date-picker-selector-block-container>div:hover:not(.date-picker-selector-block-disabled)>div:not(.date-picker-selector-block-selected){background:#e2e2e2}.date-picker-year-selector-block-container{display:grid;grid-template-columns:repeat(3,1fr);overflow:auto;margin:4px 0 2px}.date-picker-year-selector-block-container>div{height:38px;line-height:38px;text-align:center;cursor:pointer}.date-picker-year-selector-block-container>div:not(.date-picker-selector-block-disabled,.date-picker-year-selector-block-selected):hover{background:#e2e2e2}.date-picker-year-selector-block-container>div.date-picker-year-selector-block-selected{background:#02769c;color:#fff}.date-picker-year-selector-block-container>div.date-picker-selector-block-disabled{opacity:.4;cursor:default}.date-picker-year-selector-block-container::-webkit-scrollbar{width:4px}.date-picker-year-selector-block-container::-webkit-scrollbar-thumb{background:#888;border-radius:4px}.date-picker-year-selector-block-container::-webkit-scrollbar-thumb:hover{background:#555}.date-picker-calendar-footer{display:flex;justify-content:space-between;padding:10px}.date-picker-calendar-footer>.date-picker-calendar-footer-btn{font-weight:medium;color:#00008b;cursor:pointer}.date-picker-calendar-footer-btn.date-picker-calendar-footer-btn-disabled{cursor:default;opacity:.4}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
import { jsx as h, Fragment as z, jsxs as A } from "react/jsx-runtime";
import { forwardRef as t3, useEffect as M, useRef as V, useState as S, useLayoutEffect as q } from "react";
const J = ({ onClick: e }) => /* @__PURE__ */ h(
"svg",
{
width: "24",
height: "24",
viewBox: "0 0 24 24",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
onClick: e,
children: /* @__PURE__ */ h(
"path",
{
d: "M9 18L15 12L9 6",
stroke: "#262E3C",
strokeWidth: "1.66667",
strokeLinecap: "round",
strokeLinejoin: "round"
}
)
}
), n3 = ({ onClick: e }) => /* @__PURE__ */ h(
"div",
{
style: {
transform: "rotate(180deg)",
display: "flex"
},
children: /* @__PURE__ */ h(J, { onClick: e })
}
), r3 = () => /* @__PURE__ */ h(
"svg",
{
width: "16",
height: "16",
viewBox: "0 0 16 16",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: /* @__PURE__ */ h(
"path",
{
d: "M2.16666 6.16667H13.8333M4.90732 3.16667V1.83333M11.074 3.16667V1.83333M11.5 3.16667H4.49999C3.88115 3.16667 3.28766 3.4125 2.85007 3.85008C2.41249 4.28767 2.16666 4.88116 2.16666 5.5V11.8333C2.16666 12.4522 2.41249 13.0457 2.85007 13.4832C3.28766 13.9208 3.88115 14.1667 4.49999 14.1667H11.5C12.1188 14.1667 12.7123 13.9208 13.1499 13.4832C13.5875 13.0457 13.8333 12.4522 13.8333 11.8333V5.5C13.8333 4.88116 13.5875 4.28767 13.1499 3.85008C12.7123 3.4125 12.1188 3.16667 11.5 3.16667Z",
stroke: "currentColor",
strokeWidth: "1.5",
strokeLinecap: "round",
strokeLinejoin: "round"
}
)
}
), o3 = 4, j = "1921-04-13", P = [
{ year: 1978, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1979, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1980, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1981, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1982, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1983, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1984, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1985, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1986, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1987, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 1988, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 1989, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 1990, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1991, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 1992, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 1993, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1994, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1995, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 1996, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 1997, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1998, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 1999, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2e3, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2001, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2002, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2003, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2004, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2005, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2006, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2007, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2008, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2009, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2010, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2011, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2012, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2013, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2014, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2015, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2016, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2017, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2018, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2019, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2020, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2021, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2022, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2023, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2024, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2025, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2026, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2027, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2028, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2029, months: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2030, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2031, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2032, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2033, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2034, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2035, months: [30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2036, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2037, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2038, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2039, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2040, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2041, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2042, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2043, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2044, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2045, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2046, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2047, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2048, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2049, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2050, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2051, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2052, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2053, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2054, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2055, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2056, months: [31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2057, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2058, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2059, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2060, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2061, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2062, months: [31, 31, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31] },
{ year: 2063, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2064, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2065, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2066, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31] },
{ year: 2067, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2068, months: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2069, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2070, months: [31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30] },
{ year: 2071, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2072, months: [31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2073, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] },
{ year: 2074, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2075, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2076, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2077, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2078, months: [31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2079, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30] },
{ year: 2080, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30] },
{ year: 2081, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31] },
{ year: 2082, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2083, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2084, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2085, months: [31, 32, 31, 32, 30, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2086, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2087, months: [31, 31, 32, 31, 31, 31, 30, 30, 30, 30, 30, 30] },
{ year: 2088, months: [30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2089, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2090, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2091, months: [31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30] },
{ year: 2092, months: [30, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2093, months: [30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2094, months: [31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2095, months: [31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30] },
{ year: 2096, months: [30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30] },
{ year: 2097, months: [31, 32, 31, 31, 31, 30, 30, 30, 29, 30, 30, 30] },
{ year: 2098, months: [31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 29, 31] },
{ year: 2099, months: [31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31] }
], a3 = () => {
let e = o3;
for (let t = 0; t < P.length; t++) {
const n = P[t];
P[t].startWeek = n.months.map((r) => {
const o = e;
return e = (r + o) % 7, e = e === 0 ? 7 : e, o;
});
}
};
a3();
const k = P, G = k[0].year, X = k[k.length - 1].year, s3 = Array.from({ length: k.length }).map(
(e, t) => G + t
), Z = [
{ name_np: "बैशाख", name_en: "Baisakh", month_position: 1 },
{ name_np: "जेठ", name_en: "Jestha", month_position: 2 },
{ name_np: "असार", name_en: "Asar", month_position: 3 },
{ name_np: "साउन", name_en: "Shrawan", month_position: 4 },
{ name_np: "भदौ", name_en: "Bhadra", month_position: 5 },
{ name_np: "असोज", name_en: "Ashoj", month_position: 6 },
{ name_np: "कार्तिक", name_en: "Kartik", month_position: 7 },
{ name_np: "मंसिर", name_en: "Mangsir", month_position: 8 },
{ name_np: "पुष", name_en: "Poush", month_position: 9 },
{ name_np: "माघ", name_en: "Magh", month_position: 10 },
{ name_np: "फागुन", name_en: "Falgun", month_position: 11 },
{ name_np: "चैत", name_en: "Chaitra", month_position: 12 }
], i3 = [
{ name_en: "Sun", name_np: "आइत", week_position: 1 },
{ name_en: "Mon", name_np: "सोम", week_position: 2 },
{ name_en: "Tue", name_np: "मंगल", week_position: 3 },
{ name_en: "Wed", name_np: "बुध", week_position: 4 },
{ name_en: "Thu", name_np: "बिही", week_position: 5 },
{ name_en: "Fri", name_np: "शुक्र", week_position: 6 },
{ name_en: "Sat", name_np: "शनि", week_position: 7 }
], c3 = 32, h3 = "gray", d3 = 220, $ = 284, l3 = t3(
({
value: e,
onChange: t,
inputContainerStyles: n,
setIsCalendarOpen: r,
disabled: o,
placeholder: a,
inputElement: s,
hasCalendarIcon: c = !0,
calendarIcon: i,
calendarColor: m
}, l) => {
const p = () => {
const d = l && "current" in l && l.current;
d == null || d.focus();
};
M(() => {
const d = l && "current" in l && l.current;
if (!d) return;
const f = () => {
r(!0), d.setSelectionRange(10, 10);
}, u = (w) => {
w.key === "Enter" && d.value ? (t(d.value), r(!1), d.blur()) : w.key === "Tab" && (t(d.value), r(!1));
};
return d.addEventListener("focus", f), d.addEventListener("keydown", u), s && d.addEventListener("click", f), () => {
d.removeEventListener("focus", f), d.removeEventListener("keydown", u), s && d.removeEventListener("click", f);
};
}, []);
const { height: y, ..._ } = n;
return /* @__PURE__ */ h(z, { children: s ? /* @__PURE__ */ h(
"div",
{
ref: l,
style: {
width: _.width
},
children: s
}
) : /* @__PURE__ */ A(
"div",
{
className: `date-picker-input-container ${o ? "date-picker-input-container-disabled" : ""}`,
onClick: p,
style: {
paddingRight: c ? "20px" : void 0,
..._
},
children: [
/* @__PURE__ */ h(
"input",
{
ref: l,
type: "text",
placeholder: a ?? "Select Date",
className: `date-picker-input ${o ? "date-picker-input-disabled" : ""}`,
style: {
height: y
},
disabled: o,
...o ? {
value: e,
onChange: () => {
}
} : {}
}
),
c && /* @__PURE__ */ h(
"div",
{
className: "date-picker-input-right-icon",
style: {
color: m || h3,
opacity: o ? 0.5 : 1
},
children: i ?? /* @__PURE__ */ h(r3, {})
}
)
]
}
) });
}
), v = (e) => {
try {
const [t, n, r] = e.split("-");
return {
year: t,
month: n,
day: r
};
} catch {
return {
year: "yyyy",
month: "mm",
day: "dd"
};
}
}, D = (e) => {
if (!e) return !1;
try {
const { year: t, month: n, day: r } = v(e), o = k.find(({ year: a }) => a === +t);
return o ? +r >= 1 && +r <= o.months[+n - 1] || r === "dd" : !1;
} catch {
return !1;
}
}, W = (e) => {
try {
const { year: t, month: n } = v(e), r = k.find(({ year: o }) => o === +t);
return r ? r.months[+n - 1] : 0;
} catch {
return 0;
}
}, m3 = (e) => {
try {
const { year: t, month: n } = v(e);
return +n == 1 ? +t > k[0].year ? W(`${+t - 1}-12-dd`) : 0 : W(`${t}-${+n - 1}-dd`);
} catch {
return 0;
}
}, U = (e) => {
try {
const { year: t, month: n } = v(e);
return +n == 1 && +t > k[0].year ? `${+t - 1}-12-dd` : `${t}-${(+n - 1).toString().padStart(2, "0")}-dd`;
} catch {
return "";
}
}, K = (e) => {
try {
const { year: t, month: n } = v(e);
return +n == 12 && +t < k[k.length - 1].year ? `${+t + 1}-01-dd` : `${t}-${(+n + 1).toString().padStart(2, "0")}-dd`;
} catch {
return "";
}
}, H = () => {
const e = Math.ceil(
((/* @__PURE__ */ new Date()).getTime() - new Date(j).getTime()) / 864e5
);
let t = 0;
for (let n = 0; n < k.length; n++) {
const { year: r, months: o } = k[n];
for (let a = 0; a < o.length; a++) {
const s = t + o[a];
if (s < e)
t = s;
else {
const c = (a + 1).toString().padStart(2, "0"), i = (e - t).toString().padStart(2, "0");
return `${r}-${c}-${i}`;
}
}
}
return "";
}, R = (e, t) => {
const { year: n, month: r, day: o } = v(e), { year: a, month: s, day: c } = v(t), i = isNaN(+o) || isNaN(+c);
return n === a ? r === s ? i ? !0 : +o >= +c : +r >= +s : +n >= +a;
}, B = (e, t) => {
const { year: n, month: r, day: o } = v(e), { year: a, month: s, day: c } = v(t), i = isNaN(+o) || isNaN(+c);
return n === a ? r === s ? i ? !0 : +o <= +c : +r <= +s : +n <= +a;
}, Q = (e) => typeof e != "string" ? "" : e.split("-").map((t) => t.length === 1 ? t.padStart(2, "0") : t).join("-"), y3 = (e) => e ? e.split("-").map((t) => +t) : [0, 0, 0], x = (e, t, n) => {
if (!t && !n) return !0;
let r = !1;
if (t && D(t))
if (R(e, t ?? "")) r = !0;
else return !1;
if (n && D(n))
if (B(e, n ?? "")) r = !0;
else return !1;
return r;
}, u3 = (e, t, n, r) => {
const o = H();
let a = o;
return r && x(e, t, n) ? e : (x(o, t, n) ? a = o : t && D(t) ? a = t : n && D(n) && (a = n), a = Q(a), a = a.slice(0, 8) + "dd", a);
}, S3 = (e) => {
if (!e || typeof e != "string") return "";
try {
const t = Math.ceil(
(new Date(e).getTime() - new Date(j).getTime()) / 864e5
) + 1;
let n = 0;
for (let r = 0; r < k.length; r++) {
const { year: o, months: a } = k[r];
for (let s = 0; s < a.length; s++) {
const c = n + a[s];
if (c < t)
n = c;
else {
const i = (s + 1).toString().padStart(2, "0"), m = (t - n).toString().padStart(2, "0");
return `${o}-${i}-${m}`;
}
}
}
} catch {
return "";
}
return "";
}, b3 = (e) => {
if (!e || typeof e != "string" || !D(e))
return "";
try {
let t = 0;
const { year: n, month: r, day: o } = v(e);
for (let s = 0; s < k.length; s++) {
const c = k[s];
if (c.year === +n) {
for (let i = 0; i < c.months.length; i++) {
const m = c.months[i];
if (i + 1 < +r)
t += m;
else {
t += +o - 1;
break;
}
}
break;
} else
c.months.forEach((i) => {
t += i;
});
}
return new Date(
t * 24 * 60 * 60 * 1e3 + new Date(j).getTime()
).toISOString().split("T")[0];
} catch {
return "";
}
}, p3 = ({
event: e,
container: t,
input: n
}) => {
const r = e.target;
if (r === t || t.contains(r))
return;
const o = n.value;
return D(o) ? o : "";
};
var Y = /* @__PURE__ */ ((e) => (e.AUTO = "auto", e.TOP = "top", e.BOTTOM = "bottom", e))(Y || {});
const f3 = (e) => {
let t = 0, n = 0;
const r = e.getBoundingClientRect(), o = r.left, a = r.top, s = window.document.documentElement.scrollWidth, c = o + d3, i = a + $ + r.height;
return t = c > s ? -c + s : 0, i > innerHeight && innerHeight > $ + r.height && a > $ ? n = -1 : n = 1, { x: t, y: n };
}, k3 = (e, t, n) => e === Y.AUTO ? t > 0 ? n + 2 : -$ : e === Y.TOP ? -$ : n + 2, _3 = [
"०",
"१",
"२",
"३",
"४",
"५",
"६",
"७",
"८",
"९"
], L = (e, t) => !t || e === "en" ? t : t.toString().split("").map((n) => n >= "0" && n <= "9" ? _3[+n] : n).join(""), D3 = ({ lang: e }) => /* @__PURE__ */ h("div", { className: "date-picker-body-container date-picker-week-days-container", children: i3.map(({ name_en: t, name_np: n }) => /* @__PURE__ */ h("div", { children: e === "en" ? t : n }, t)) }), w3 = ({
date: e,
handleChange: t,
min: n,
max: r,
lang: o,
calendarStyles: a
}) => {
var u;
const s = W(e), c = m3(e), { year: i, month: m, day: l } = v(e), p = (u = k.find((w) => w.year === +i)) == null ? void 0 : u.startWeek[+m - 1], y = c - p + 2, _ = (s + p - 1) % 7;
let d = _ > 0 ? 7 - _ : 0;
return (p - 1 + s + (_ > 0 ? 7 - _ : 0)) / 7 === 5 && (d = d + 7), /* @__PURE__ */ A(z, { children: [
/* @__PURE__ */ h(D3, { lang: o }),
/* @__PURE__ */ A("div", { className: "date-picker-body-container date-picker-dates-container", children: [
Array.from({ length: p - 1 }).map((w, g) => /* @__PURE__ */ h("div", { className: "prev-month-days", children: L(
o,
c > 0 ? y + g : void 0
) }, g)),
Array.from({ length: s }).map((w, g) => {
var O, N, T;
const C = g + 1;
let E = !1;
n && D(n) && (E = !R(
e.slice(0, 8) + C,
n
)), !E && r && D(r) && (E = !B(
e.slice(0, 8) + C,
r
));
const b = C === +l;
return /* @__PURE__ */ h(
"div",
{
className: `${b ? "date-picker-selected-date" : ""} ${E ? "date-picker-date-disabled" : ""}`,
onClick: () => !E && t(C),
style: {
...b ? {
color: (O = a == null ? void 0 : a.dates) == null ? void 0 : O.activeTextColor,
backgroundColor: (N = a == null ? void 0 : a.dates) == null ? void 0 : N.activeBackgroundColor
} : {
"--date-picker-np-hover-color": (T = a == null ? void 0 : a.dates) == null ? void 0 : T.hoverBackgroundColor
}
},
children: L(o, C)
},
g
);
}),
Array.from({
length: d
}).map((w, g) => /* @__PURE__ */ h("div", { className: "next-month-days", children: L(o, g + 1) }, g))
] })
] });
}, g3 = ({
hasValidValue: e,
onChange: t,
min: n,
max: r,
lang: o,
calendarStyles: a
}) => {
var m;
let s = !1;
const c = H();
n && D(n) && (s = !R(c, n)), !s && r && D(r) && (s = !B(c, r));
const i = (m = a == null ? void 0 : a.footer) == null ? void 0 : m.textColor;
return /* @__PURE__ */ A("div", { className: "date-picker-calendar-footer", children: [
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-footer-btn ${e ? "" : "date-picker-calendar-footer-btn-disabled"}`,
style: {
color: i
},
onClick: () => e && t(""),
children: o === "en" ? "Clear" : "हटाउनुहोस्"
}
),
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-footer-btn ${s ? "date-picker-calendar-footer-btn-disabled" : ""}`,
style: {
color: i
},
onClick: () => !s && t(H()),
children: o === "en" ? "Today" : "आज"
}
)
] });
}, v3 = ({
selectedYear: e,
setSelectedYear: t,
setActiveSelector: n,
lang: r,
minYear: o,
maxYear: a
}) => {
const s = V(null), c = (i) => {
t(i), n("month");
};
return M(() => {
const m = s.current.children;
for (let l = 0; l < m.length; l++)
if (m[l].textContent === String(L(r, e))) {
m[l].scrollIntoView({
block: "nearest",
inline: "nearest"
});
break;
}
}, [e, r]), /* @__PURE__ */ h(
"div",
{
ref: s,
className: "date-picker-year-selector-block-container",
children: s3.map((i) => {
const m = i === e, l = i < o || i > a;
return /* @__PURE__ */ h(
"div",
{
onClick: () => !l && c(i),
className: `
${m ? "date-picker-year-selector-block-selected" : ""} ${l ? "date-picker-selector-block-disabled" : ""}`,
children: L(r, i)
},
i
);
})
}
);
}, N3 = ({
handleMonthChange: e,
minMonth: t,
maxMonth: n,
lang: r
}) => /* @__PURE__ */ h("div", { className: "date-picker-selector-block-container", children: Z.map(({ name_en: o, name_np: a, month_position: s }) => {
const c = s < t || s > n;
return /* @__PURE__ */ h(
"div",
{
onClick: () => !c && e(s),
className: c ? "date-picker-selector-block-disabled" : void 0,
children: /* @__PURE__ */ h("div", { children: r === "en" ? o : a })
},
o
);
}) }), T3 = ({
year: e,
handleChange: t,
setIsDropdownOpen: n,
min: r,
max: o,
lang: a
}) => {
const [s, c] = S(
"year"
), [i, m] = S(e);
let l = G, p = X, y = 1, _ = 12;
if (r && D(r)) {
const { year: u, month: w } = v(r);
l = +u, i === +u && (y = +w);
}
if (o && D(o)) {
const { year: u, month: w } = v(o);
p = +u, i === +u && (_ = +w);
}
const d = (u) => {
t(`${i}-${u.toString().padStart(2, "0")}-dd`), setTimeout(() => n(!1));
};
return M(() => {
const u = (w) => {
w.key === "Escape" && n(!1);
};
return window.addEventListener("keydown", u), () => window.removeEventListener("keydown", u);
}, []), /* @__PURE__ */ A("div", { className: "date-picker-selector-container", children: [
/* @__PURE__ */ h("div", { className: "date-picker-selector-header", children: /* @__PURE__ */ h("div", { className: "date-picker-calendar-header-dropdown-text", children: L(a, s === "year" ? "Select Year" : "Select Month") }) }),
s === "year" && /* @__PURE__ */ h(
v3,
{
selectedYear: i,
setSelectedYear: m,
setActiveSelector: c,
minYear: l,
maxYear: p,
lang: a
}
),
s === "month" && /* @__PURE__ */ h(
N3,
{
handleMonthChange: d,
minMonth: y,
maxMonth: _,
lang: a
}
)
] });
}, C3 = ({
date: e,
handleChange: t,
min: n,
max: r,
lang: o
}) => {
var d;
const [a, s] = S(!1), c = () => t(K(e)), i = () => t(U(e)), [m, l] = y3(e);
let p = m === G && l === 1, y = m === X && l === 12;
n && D(n) && !p && (p = !R(
U(e),
n
)), r && D(r) && !y && (y = !B(
K(e),
r
));
const _ = `${(d = Z[l - 1]) == null ? void 0 : d[o === "en" ? "name_en" : "name_np"]} ${L(o, m)}`;
return /* @__PURE__ */ A("div", { className: "date-picker-calendar-header", children: [
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-header-arrow ${p ? "date-picker-calendar-header-arrow-disabled" : ""}`,
onClick: () => !p && i(),
children: /* @__PURE__ */ h(n3, {})
}
),
/* @__PURE__ */ A("div", { className: "date-picker-calendar-header-dropdown-container", children: [
/* @__PURE__ */ h(
"p",
{
className: "date-picker-calendar-header-dropdown-text",
onClick: () => s(!a),
children: _
}
),
a && /* @__PURE__ */ h(
T3,
{
year: m,
handleChange: t,
setIsDropdownOpen: s,
min: n,
max: r,
lang: o
}
)
] }),
/* @__PURE__ */ h(
"div",
{
className: `date-picker-calendar-header-arrow ${y ? "date-picker-calendar-header-arrow-disabled" : ""}`,
onClick: () => !y && c(),
children: /* @__PURE__ */ h(J, {})
}
)
] });
}, E3 = ({
value: e = "yyyy-mm-dd",
onChange: t,
calendarPositions: n,
min: r,
max: o,
lang: a,
calendarStyles: s
}) => {
const c = D(e), [i, m] = S(""), l = (y) => {
const { year: _, month: d } = v(i);
t(
`${_}-${d.toString().padStart(2, "0")}-${y.toString().padStart(2, "0")}`
);
};
q(() => {
const y = u3(e, r, o, c);
m(y);
}, [e]);
const p = i.slice(0, 7) === (e == null ? void 0 : e.slice(0, 7)) ? e : i;
return /* @__PURE__ */ A("div", { className: "date-picker-calendar", style: n, children: [
/* @__PURE__ */ h(
C3,
{
date: i,
handleChange: (y) => m(y),
min: r,
max: o,
lang: a,
calendarStyles: s
}
),
/* @__PURE__ */ h(
w3,
{
date: p,
handleChange: l,
min: r,
max: o,
lang: a,
calendarStyles: s
}
),
/* @__PURE__ */ h(
g3,
{
hasValidValue: c,
onChange: t,
min: r,
max: o,
lang: a,
calendarStyles: s
}
)
] });
}, $3 = ({
value: e,
onChange: t,
min: n,
max: r,
disabled: o,
placeholder: a,
inputElement: s,
inputContainerStyles: c = {},
calendarStyles: i = {},
hasCalendarIcon: m,
calendarIcon: l,
calendarColor: p,
lang: y = "en",
menuPosition: _ = "auto"
}) => {
const d = V(null), f = V(null), [u, w] = S({
x: 0,
y: 0
}), [g, C] = S(!1), E = (N) => {
if (o) return;
const T = Q(N);
t(
x(T, n, r) ? T : ""
), C(!1), f.current && (f.current.value = T ?? "");
};
q(() => {
const N = () => {
if (!g) return;
const { x: T, y: I } = f3(
d == null ? void 0 : d.current
);
w({ x: T, y: I });
};
return N(), window.addEventListener("resize", N), window.addEventListener("scroll", N), () => {
window.removeEventListener("resize", N), window.removeEventListener("scroll", N);
};
}, [g]), M(() => {
const N = f == null ? void 0 : f.current, T = d == null ? void 0 : d.current;
if (!N || !g) return;
const I = (e3) => {
const F = p3({
event: e3,
container: T,
input: N
});
F !== void 0 && (F !== e ? E(F) : C(!1));
};
return window.addEventListener("mousedown", I), () => {
window.removeEventListener("mousedown", I);
};
}, [g]), M(() => {
f.current && (f.current.value = D(e) ? e ?? "" : "");
}, [e]);
const b = (c == null ? void 0 : c.height) || c3, O = k3(
_,
u.y,
b
);
return /* @__PURE__ */ A(
"div",
{
className: "date-picker-container",
ref: d,
style: {
width: c.width
},
children: [
/* @__PURE__ */ h(
l3,
{
ref: f,
value: e,
onChange: E,
setIsCalendarOpen: C,
inputContainerStyles: {
...c,
height: b
},
disabled: o,
placeholder: a,
inputElement: s,
hasCalendarIcon: m,
calendarIcon: l,
calendarColor: p
}
),
!o && g && /* @__PURE__ */ h(
E3,
{
calendarPositions: {
top: O,
left: u.x,
zIndex: 1e6
},
value: e,
onChange: E,
min: n,
max: r,
lang: y,
calendarStyles: {
...i
}
}
)
]
}
);
};
export {
S3 as convertADToBS,
b3 as convertBSToAD,
$3 as default
};