custom-date-selector
Version:
A custom date picker component
32 lines (29 loc) • 23.6 kB
JavaScript
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".outer-container{position:relative;height:100%}.date-input-field{height:36px;width:100%;padding:0 10px;font-size:16px;border-radius:5px}.calendar-icon{fill:#8e8e8e;cursor:pointer;height:30px;width:30px;position:absolute;top:3px;right:5px}.calendar-icon:hover{fill:#494949}.calendar-container{background-color:#fff;z-index:10;box-shadow:#32325d40 0 6px 12px -2px,#0000004d 0 3px 7px -3px;border-radius:8px;display:grid;grid-template-rows:0fr;grid-template-columns:0fr;position:fixed;transition:grid-template-rows .2s,grid-template-columns .2s,min-width .2s}.calendar-container .calendar{padding:0}.calendar-container.open{grid-template-rows:1fr;grid-template-columns:1fr;min-width:290px}.calendar-container.open .calendar{padding:0 10px 10px}.calendar{display:grid;grid-template-rows:repeat(3,auto);gap:5px;overflow:hidden}.week-day-conatainer,.days-container{width:100%;display:grid;grid-template-columns:repeat(7,1fr);gap:5px 10px}.empty-day{border:none}.week-header{font-weight:700;font-size:14px;text-align:center;-webkit-user-select:none;user-select:none}.week-day,.week-end,.current-day,.selected-date{border:1px solid #7b7b7b;padding:5px;cursor:pointer;border-radius:50%;text-align:center;color:#494949;font-size:14px;height:30px;-webkit-user-select:none;user-select:none}.selected-date,.picked-year,.picked-month{background-color:#006bbd;color:#fff;border-color:#006bbd;transition:all .2s}.current-day{background-color:#d3d3d3;border-color:#d3d3d3}.selected-month,.selected-year{-webkit-user-select:none;user-select:none;padding:3px 10px}.week-day:hover,.selected-month:hover,.selected-year:hover,.year:hover,.month:hover{background-color:#d3d3d3}.week-day:active,.selected-month:active,.selected-year:active,.year:active{background-color:#adadad}.picked-year:hover,.picked-month:hover{background-color:#014375;color:#fff}.disabled-day{color:#b3b3bb;border-color:#c8c8c8;cursor:not-allowed;pointer-events:none}.picker{grid-column:1 / -1;width:100%;display:grid;grid-template-columns:auto auto 1fr;padding:5px 5px 0;align-items:center}.month-changer{display:flex;gap:5px;align-items:center;justify-content:flex-end}.selected-year,.selected-month{cursor:pointer;padding:0 5px;border-radius:3px}.icon-conatainer{cursor:pointer;height:28px;width:28px;display:flex;align-items:center;justify-content:center;border-radius:50%}.icon-conatainer svg{height:16px;width:14px;fill:#8a8a8a}.diabled-icon{background:none}.diabled-icon svg{fill:#c5c5c5}.icon-conatainer:hover{background-color:#d3d3d3}.icon-conatainer:hover svg{fill:#494949}.diabled-icon:hover{background-color:#ececec}.diabled-icon:hover svg{fill:#b8b8b8}.icon-conatainer:active svg{fill:#ebebeb}.diabled-icon:active svg{fill:#b8b8b8}.years-container,.months-container{display:grid;grid-template-columns:repeat(4,1fr);gap:5px;max-height:250px;overflow:hidden auto;padding:10px;border-radius:8px}.months-container{grid-template-columns:repeat(3,1fr);gap:10px}.year,.month{padding:2px 10px;border:1px solid #7b7b7b;cursor:pointer;text-align:center;-webkit-user-select:none;user-select:none;font-size:14px;border-radius:20px}.month{padding:5px 10px}.years-view{padding:0}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
(function(y,q){typeof exports=="object"&&typeof module<"u"?module.exports=q(require("react")):typeof define=="function"&&define.amd?define(["react"],q):(y=typeof globalThis<"u"?globalThis:y||self,y.MyDatePicker=q(y.React))})(this,function(y){"use strict";function q(n){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const i in n)if(i!=="default"){const s=Object.getOwnPropertyDescriptor(n,i);Object.defineProperty(l,i,s.get?s:{enumerable:!0,get:()=>n[i]})}}return l.default=n,Object.freeze(l)}const se=q(y);var Q={exports:{}},D={};/**
* @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 le;function Ve(){if(le)return D;le=1;var n=y,l=Symbol.for("react.element"),i=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,p={key:!0,ref:!0,__self:!0,__source:!0};function k(F,b,T){var E,w={},O=null,x=null;T!==void 0&&(O=""+T),b.key!==void 0&&(O=""+b.key),b.ref!==void 0&&(x=b.ref);for(E in b)s.call(b,E)&&!p.hasOwnProperty(E)&&(w[E]=b[E]);if(F&&F.defaultProps)for(E in b=F.defaultProps,b)w[E]===void 0&&(w[E]=b[E]);return{$$typeof:l,type:F,key:O,ref:x,props:w,_owner:o.current}}return D.Fragment=i,D.jsx=k,D.jsxs=k,D}var U={};/**
* @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 ce;function qe(){return ce||(ce=1,process.env.NODE_ENV!=="production"&&function(){var n=y,l=Symbol.for("react.element"),i=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),p=Symbol.for("react.profiler"),k=Symbol.for("react.provider"),F=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),T=Symbol.for("react.suspense"),E=Symbol.for("react.suspense_list"),w=Symbol.for("react.memo"),O=Symbol.for("react.lazy"),x=Symbol.for("react.offscreen"),A=Symbol.iterator,W="@@iterator";function Z(e){if(e===null||typeof e!="object")return null;var r=A&&e[A]||e[W];return typeof r=="function"?r:null}var m=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function v(e){{for(var r=arguments.length,t=new Array(r>1?r-1:0),a=1;a<r;a++)t[a-1]=arguments[a];f("error",e,t)}}function f(e,r,t){{var a=m.ReactDebugCurrentFrame,d=a.getStackAddendum();d!==""&&(r+="%s",t=t.concat([d]));var h=t.map(function(u){return String(u)});h.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,h)}}var S=!1,B=!1,Ge=!1,He=!1,Xe=!1,ge;ge=Symbol.for("react.module.reference");function Qe(e){return!!(typeof e=="string"||typeof e=="function"||e===s||e===p||Xe||e===o||e===T||e===E||He||e===x||S||B||Ge||typeof e=="object"&&e!==null&&(e.$$typeof===O||e.$$typeof===w||e.$$typeof===k||e.$$typeof===F||e.$$typeof===b||e.$$typeof===ge||e.getModuleId!==void 0))}function $e(e,r,t){var a=e.displayName;if(a)return a;var d=r.displayName||r.name||"";return d!==""?t+"("+d+")":t}function pe(e){return e.displayName||"Context"}function M(e){if(e==null)return null;if(typeof e.tag=="number"&&v("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 s:return"Fragment";case i:return"Portal";case p:return"Profiler";case o:return"StrictMode";case T:return"Suspense";case E:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case F:var r=e;return pe(r)+".Consumer";case k:var t=e;return pe(t._context)+".Provider";case b:return $e(e,e.render,"ForwardRef");case w:var a=e.displayName||null;return a!==null?a:M(e.type)||"Memo";case O:{var d=e,h=d._payload,u=d._init;try{return M(u(h))}catch{return null}}}return null}var N=Object.assign,J=0,ye,me,be,Ee,Re,_e,Te;function we(){}we.__reactDisabledLog=!0;function er(){{if(J===0){ye=console.log,me=console.info,be=console.warn,Ee=console.error,Re=console.group,_e=console.groupCollapsed,Te=console.groupEnd;var e={configurable:!0,enumerable:!0,value:we,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}J++}}function rr(){{if(J--,J===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:N({},e,{value:ye}),info:N({},e,{value:me}),warn:N({},e,{value:be}),error:N({},e,{value:Ee}),group:N({},e,{value:Re}),groupCollapsed:N({},e,{value:_e}),groupEnd:N({},e,{value:Te})})}J<0&&v("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var $=m.ReactCurrentDispatcher,ee;function z(e,r,t){{if(ee===void 0)try{throw Error()}catch(d){var a=d.stack.trim().match(/\n( *(at )?)/);ee=a&&a[1]||""}return`
`+ee+e}}var re=!1,G;{var tr=typeof WeakMap=="function"?WeakMap:Map;G=new tr}function Ce(e,r){if(!e||re)return"";{var t=G.get(e);if(t!==void 0)return t}var a;re=!0;var d=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var h;h=$.current,$.current=null,er();try{if(r){var u=function(){throw Error()};if(Object.defineProperty(u.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(u,[])}catch(j){a=j}Reflect.construct(e,[],u)}else{try{u.call()}catch(j){a=j}e.call(u.prototype)}}else{try{throw Error()}catch(j){a=j}e()}}catch(j){if(j&&a&&typeof j.stack=="string"){for(var c=j.stack.split(`
`),C=a.stack.split(`
`),R=c.length-1,_=C.length-1;R>=1&&_>=0&&c[R]!==C[_];)_--;for(;R>=1&&_>=0;R--,_--)if(c[R]!==C[_]){if(R!==1||_!==1)do if(R--,_--,_<0||c[R]!==C[_]){var P=`
`+c[R].replace(" at new "," at ");return e.displayName&&P.includes("<anonymous>")&&(P=P.replace("<anonymous>",e.displayName)),typeof e=="function"&&G.set(e,P),P}while(R>=1&&_>=0);break}}}finally{re=!1,$.current=h,rr(),Error.prepareStackTrace=d}var V=e?e.displayName||e.name:"",I=V?z(V):"";return typeof e=="function"&&G.set(e,I),I}function nr(e,r,t){return Ce(e,!1)}function ar(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function H(e,r,t){if(e==null)return"";if(typeof e=="function")return Ce(e,ar(e));if(typeof e=="string")return z(e);switch(e){case T:return z("Suspense");case E:return z("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case b:return nr(e.render);case w:return H(e.type,r,t);case O:{var a=e,d=a._payload,h=a._init;try{return H(h(d),r,t)}catch{}}}return""}var K=Object.prototype.hasOwnProperty,je={},ke=m.ReactDebugCurrentFrame;function X(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);ke.setExtraStackFrame(t)}else ke.setExtraStackFrame(null)}function or(e,r,t,a,d){{var h=Function.call.bind(K);for(var u in e)if(h(e,u)){var c=void 0;try{if(typeof e[u]!="function"){var C=Error((a||"React class")+": "+t+" type `"+u+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[u]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw C.name="Invariant Violation",C}c=e[u](r,u,a,t,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(R){c=R}c&&!(c instanceof Error)&&(X(d),v("%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).",a||"React class",t,u,typeof c),X(null)),c instanceof Error&&!(c.message in je)&&(je[c.message]=!0,X(d),v("Failed %s type: %s",t,c.message),X(null))}}}var ir=Array.isArray;function te(e){return ir(e)}function sr(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,t=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return t}}function lr(e){try{return Oe(e),!1}catch{return!0}}function Oe(e){return""+e}function Se(e){if(lr(e))return v("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",sr(e)),Oe(e)}var Pe=m.ReactCurrentOwner,cr={key:!0,ref:!0,__self:!0,__source:!0},Fe,xe;function ur(e){if(K.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function fr(e){if(K.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function dr(e,r){typeof e.ref=="string"&&Pe.current}function vr(e,r){{var t=function(){Fe||(Fe=!0,v("%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))};t.isReactWarning=!0,Object.defineProperty(e,"key",{get:t,configurable:!0})}}function hr(e,r){{var t=function(){xe||(xe=!0,v("%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))};t.isReactWarning=!0,Object.defineProperty(e,"ref",{get:t,configurable:!0})}}var gr=function(e,r,t,a,d,h,u){var c={$$typeof:l,type:e,key:r,ref:t,props:u,_owner:h};return c._store={},Object.defineProperty(c._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(c,"_self",{configurable:!1,enumerable:!1,writable:!1,value:a}),Object.defineProperty(c,"_source",{configurable:!1,enumerable:!1,writable:!1,value:d}),Object.freeze&&(Object.freeze(c.props),Object.freeze(c)),c};function pr(e,r,t,a,d){{var h,u={},c=null,C=null;t!==void 0&&(Se(t),c=""+t),fr(r)&&(Se(r.key),c=""+r.key),ur(r)&&(C=r.ref,dr(r,d));for(h in r)K.call(r,h)&&!cr.hasOwnProperty(h)&&(u[h]=r[h]);if(e&&e.defaultProps){var R=e.defaultProps;for(h in R)u[h]===void 0&&(u[h]=R[h])}if(c||C){var _=typeof e=="function"?e.displayName||e.name||"Unknown":e;c&&vr(u,_),C&&hr(u,_)}return gr(e,c,C,d,a,Pe.current,u)}}var ne=m.ReactCurrentOwner,Ye=m.ReactDebugCurrentFrame;function L(e){if(e){var r=e._owner,t=H(e.type,e._source,r?r.type:null);Ye.setExtraStackFrame(t)}else Ye.setExtraStackFrame(null)}var ae;ae=!1;function oe(e){return typeof e=="object"&&e!==null&&e.$$typeof===l}function Me(){{if(ne.current){var e=M(ne.current.type);if(e)return`
Check the render method of \``+e+"`."}return""}}function yr(e){return""}var Ae={};function mr(e){{var r=Me();if(!r){var t=typeof e=="string"?e:e.displayName||e.name;t&&(r=`
Check the top-level render call using <`+t+">.")}return r}}function Ne(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var t=mr(r);if(Ae[t])return;Ae[t]=!0;var a="";e&&e._owner&&e._owner!==ne.current&&(a=" It was passed a child from "+M(e._owner.type)+"."),L(e),v('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',t,a),L(null)}}function Ie(e,r){{if(typeof e!="object")return;if(te(e))for(var t=0;t<e.length;t++){var a=e[t];oe(a)&&Ne(a,r)}else if(oe(e))e._store&&(e._store.validated=!0);else if(e){var d=Z(e);if(typeof d=="function"&&d!==e.entries)for(var h=d.call(e),u;!(u=h.next()).done;)oe(u.value)&&Ne(u.value,r)}}}function br(e){{var r=e.type;if(r==null||typeof r=="string")return;var t;if(typeof r=="function")t=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===b||r.$$typeof===w))t=r.propTypes;else return;if(t){var a=M(r);or(t,e.props,"prop",a,e)}else if(r.PropTypes!==void 0&&!ae){ae=!0;var d=M(r);v("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",d||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&v("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Er(e){{for(var r=Object.keys(e.props),t=0;t<r.length;t++){var a=r[t];if(a!=="children"&&a!=="key"){L(e),v("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",a),L(null);break}}e.ref!==null&&(L(e),v("Invalid attribute `ref` supplied to `React.Fragment`."),L(null))}}var We={};function Le(e,r,t,a,d,h){{var u=Qe(e);if(!u){var c="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(c+=" 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 C=yr();C?c+=C:c+=Me();var R;e===null?R="null":te(e)?R="array":e!==void 0&&e.$$typeof===l?(R="<"+(M(e.type)||"Unknown")+" />",c=" Did you accidentally export a JSX literal instead of a component?"):R=typeof e,v("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",R,c)}var _=pr(e,r,t,d,h);if(_==null)return _;if(u){var P=r.children;if(P!==void 0)if(a)if(te(P)){for(var V=0;V<P.length;V++)Ie(P[V],e);Object.freeze&&Object.freeze(P)}else v("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 Ie(P,e)}if(K.call(r,"key")){var I=M(e),j=Object.keys(r).filter(function(jr){return jr!=="key"}),ie=j.length>0?"{key: someKey, "+j.join(": ..., ")+": ...}":"{key: someKey}";if(!We[I+ie]){var Cr=j.length>0?"{"+j.join(": ..., ")+": ...}":"{}";v(`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,Cr,I),We[I+ie]=!0}}return e===s?Er(_):br(_),_}}function Rr(e,r,t){return Le(e,r,t,!0)}function _r(e,r,t){return Le(e,r,t,!1)}var Tr=_r,wr=Rr;U.Fragment=s,U.jsx=Tr,U.jsxs=wr}()),U}process.env.NODE_ENV==="production"?Q.exports=Ve():Q.exports=qe();var g=Q.exports;const ue={"arrow-right":g.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 -960 960 960",children:g.jsx("path",{d:"m321-80-71-71 329-329-329-329 71-71 400 400L321-80Z"})}),"arrow-left":g.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 -960 960 960",children:g.jsx("path",{d:"M640-80 240-480l400-400 71 71-329 329 329 329-71 71Z"})})};let fe=["January","February","March","April","May","June","July","August","September","October","November","December"];const de=(n,l)=>(l==null?void 0:l.year)<n.getFullYear()?fe:fe.slice(0,n.getMonth()+1),De=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],Ue=({minYear:n,maxYear:l})=>{const i=[];for(let s=n||1970;s<=(l||2050);s++)i.push(s);return i},Ze=(n=0,l=new Date().getFullYear())=>{const i=new Date(l,n+1,0).getDate(),s=[];let o=new Date(l,n,1).getDay(),p=0;for(let k=1;k<=i;k++)s[p]||(s[p]=Array(7).fill(null)),s[p][o]=k,o===6&&p++,o=o===6?0:o+1;return s},Y=new Date,Be=n=>n?n.toLocaleDateString("en-IN",{year:"numeric",month:"2-digit",day:"2-digit"}):"",ve=n=>Y.getFullYear()>(n==null?void 0:n.getFullYear())?{year:n.getFullYear(),month:n.getMonth()}:Y.getMonth()>(n==null?void 0:n.getMonth())?{year:Y.getFullYear(),month:n.getMonth()}:{year:Y.getFullYear(),month:Y.getMonth()},he=({minDate:n,maxDate:l,userInput:i})=>n&&i.year===n.getFullYear()&&i.month===n.getMonth()||l&&i.year===l.getFullYear()&&i.month===l.getMonth()?"icon-conatainer diabled-icon":"icon-conatainer",Je=({date:n,maxDate:l,userInput:i,value:s,minDate:o})=>{const p=new Date(i.year,i.month,n);return n?s&&s.getDate()===n&&s.getMonth()===i.month&&s.getFullYear()===i.year?"selected-date":i.year===Y.getFullYear()&&i.month===Y.getMonth()&&n===Y.getDate()?"current-day":l&&o?p>l||p<o?"week-day disabled-day":"week-day":l&&p>l||o&&p<o?"week-day disabled-day":"week-day":"empty-day"},Ke=({setValue:n,maxDate:l,minDate:i,value:s})=>{const[o,p]=y.useState(ve(l)),[k,F]=y.useState([]),[b,T]=y.useState("days"),[E,w]=y.useState(!1),O=y.useRef(null),x=y.useRef(null);y.useEffect(()=>{E||(T("days"),p(ve(l)));const f=S=>{E&&x.current&&!x.current.contains(S.target)&&w(!1)};return document.addEventListener("click",f),()=>{document.removeEventListener("click",f)}},[E,l]),y.useEffect(()=>{const{year:f,month:S}=o;f&&S>=0&&F(Ze(parseInt(S),parseInt(f)))},[o]),y.useEffect(()=>{s&&p({year:s==null?void 0:s.getFullYear(),month:s==null?void 0:s.getMonth()})},[s]),y.useEffect(()=>{b==="years"&&O.current&&O.current.scrollIntoView({behavior:"smooth",block:"center"})},[b]);const A=y.useCallback(()=>{i&&o.year===i.getFullYear()&&o.month===i.getMonth()||p(f=>({month:f.month===0?11:f.month-1,year:f.month===0?f.year-1:f.year}))},[i,o.month,o.year]),W=y.useCallback(()=>{l&&o.year===l.getFullYear()&&o.month===l.getMonth()||p(f=>({month:f.month===11?0:f.month+1,year:f.month===11?f.year+1:f.year}))},[l,o.month,o.year]),Z=y.useCallback((f,S)=>{f.stopPropagation(),p(B=>({...B,year:S})),T("months")},[]),m=y.useCallback((f,S)=>{f.stopPropagation(),p(B=>({...B,month:S})),T("days")},[]),v=y.useCallback(f=>{n(new Date(o.year,o.month,f)),w(!1)},[n,o]);return{userInput:o,days:k,prevMonthChange:A,nextMonthChange:W,handleDateSelection:v,currentView:b,setCurrentView:T,handleYearChange:Z,handleMonthChange:m,selectedYearRef:O,open:E,setOpen:w,containerRef:x}},ze=n=>se.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",height:"24px",viewBox:"0 -960 960 960",width:"24px",fill:"#e8eaed",...n},se.createElement("path",{d:"M200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Zm280 240q-17 0-28.5-11.5T440-440q0-17 11.5-28.5T480-480q17 0 28.5 11.5T520-440q0 17-11.5 28.5T480-400Zm-160 0q-17 0-28.5-11.5T280-440q0-17 11.5-28.5T320-480q17 0 28.5 11.5T360-440q0 17-11.5 28.5T320-400Zm320 0q-17 0-28.5-11.5T600-440q0-17 11.5-28.5T640-480q17 0 28.5 11.5T680-440q0 17-11.5 28.5T640-400ZM480-240q-17 0-28.5-11.5T440-280q0-17 11.5-28.5T480-320q17 0 28.5 11.5T520-280q0 17-11.5 28.5T480-240Zm-160 0q-17 0-28.5-11.5T280-280q0-17 11.5-28.5T320-320q17 0 28.5 11.5T360-280q0 17-11.5 28.5T320-240Zm320 0q-17 0-28.5-11.5T600-280q0-17 11.5-28.5T640-320q17 0 28.5 11.5T680-280q0 17-11.5 28.5T640-240Z"}));return({value:n,setValue:l,maxDate:i,minDate:s})=>{const{userInput:o,days:p,prevMonthChange:k,nextMonthChange:F,handleDateSelection:b,currentView:T,setCurrentView:E,handleYearChange:w,selectedYearRef:O,handleMonthChange:x,open:A,setOpen:W,containerRef:Z}=Ke({value:n,setValue:l,maxDate:i,minDate:s});return g.jsxs("div",{ref:Z,className:"outer-container",children:[g.jsx("input",{type:"text",placeholder:"Date",className:"date-input-field",onFocus:()=>W(!0),onKeyDown:m=>m.preventDefault(),onChange:m=>m.preventDefault(),value:Be(n)}),g.jsx(ze,{className:"calendar-icon",onClick:()=>W(!A)}),g.jsx("div",{className:`calendar-container ${A?"open":""}`,children:g.jsxs("div",{className:`calendar ${T==="years"?"years-view":""}`,children:[g.jsxs("div",{className:"picker",children:[g.jsx("div",{className:"selected-year",onClick:()=>E("years"),children:o.year}),g.jsx("div",{className:"selected-month",onClick:()=>E("months"),children:de(i,o)[o.month]}),T==="days"&&g.jsxs("div",{className:"month-changer",children:[g.jsx("div",{className:`${he({minDate:s,userInput:o})}`,onClick:k,children:ue["arrow-left"]}),g.jsx("div",{className:`${he({maxDate:i,userInput:o})}`,onClick:F,children:ue["arrow-right"]})]})]}),T==="years"&&g.jsx("div",{className:"years-container",children:Ue({minYear:s==null?void 0:s.getFullYear(),maxYear:i==null?void 0:i.getFullYear()}).map((m,v)=>g.jsx("div",{className:`year ${m===o.year?"picked-year":""}`,onClick:f=>w(f,m),ref:m===o.year?O:null,children:m},v))}),T==="months"&&g.jsx("div",{className:"months-container",children:de(i,o).map((m,v)=>g.jsx("div",{className:`month ${v===o.month?"picked-month":""}`,onClick:f=>x(f,v),children:m},v))}),T==="days"&&g.jsxs(g.Fragment,{children:[g.jsx("div",{className:"week-day-conatainer",children:De.map((m,v)=>g.jsx("div",{className:"week-header",children:m},v))}),g.jsx("div",{className:"days-container",children:!!p.length&&p.map((m,v)=>m.map((f,S)=>g.jsx("div",{className:Je({date:f,maxDate:i,minDate:s,userInput:o,value:n}),onClick:()=>b(f),children:f||""},`${v}${S}`)))})]})]})})]})}});