persian-fullcalendar
Version:
React component that helps you to makes simple Farsi/Jalali/Shamsi date picker. It also has range date picker you can select multiple days in multiple months.
179 lines (171 loc) • 28 kB
JavaScript
import e,{useMemo as t,useRef as r,useState as n,forwardRef as a}from"react";import{ThemeProvider as o}from"@emotion/react";import s from"@emotion/styled";const i=(e,t,r)=>`hsl(${e}deg ${t}% ${r}%)`,l=e=>{const{h:t,s:r,l:n}=function(e){const t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);if(null==t)throw new Error("Could not parse Hex Color");const r=parseInt(t[1],16)/255,n=parseInt(t[2],16)/255,a=parseInt(t[3],16)/255,o=Math.max(r,n,a),s=Math.min(r,n,a);let i=(o+s)/2,l=i,c=i;if(o===s)return{h:0,s:0,l:c};const d=o-s;switch(l=c>.5?d/(2-o-s):d/(o+s),o){case r:i=(n-a)/d+(n<a?6:0);break;case n:i=(a-r)/d+2;break;case a:i=(r-n)/d+4}return i/=6,l*=100,l=Math.round(l),c*=100,c=Math.round(c),i=Math.round(360*i),{h:i,s:l,l:c}}(e),a={};return a[40]=i(t,r,n-10),a[50]=i(t,r,n),a[85]=i(t,r,85),a[90]=i(t,r,90),a[95]=i(t,r,95),a},c=850,d="cubic-bezier(0.4, 0, 0.2, 1)",u="#0D59F2",m={localeDefault:"en",setLocale(e){null!=e&&(this.localeDefault=e)},get locale(){return this.localeDefault}},h={0:"#FFFFFF",20:"#F5F5F5",30:"#EBEBEB",40:"#DEDEDE",50:"#BFBFBF",60:"#B0B0B0",70:"#575757",80:"#666666",600:"#2E2E2E"},f=r=>{const{accentColor:n=u,locale:a,round:s="thin",direction:i="rtl"}=r;t((()=>m.setLocale(a)),[a]);const c={colors:{primary:t((()=>l(n)),[]),gray:h},round:s,direction:i};return e.createElement(o,{theme:c},r.children)},p={thin:{wrapper:0,calendarItem:0},x1:{wrapper:8,calendarItem:4},x2:{wrapper:16,calendarItem:8},x3:{wrapper:24,calendarItem:16},x4:{wrapper:24,calendarItem:20}},y=s.button`
cursor: pointer;
outline: none;
border: none;
display: flex;
justify-content: center;
align-items: center;
width: 40px;
height: 40px;
transition: background-color 0.2s ease-in;
color: ${e=>e.theme.colors.primary[50]};
background-color: transparent;
border-radius: ${e=>p[e.theme.round].calendarItem}px;
&:hover,
&:focus {
background-color: ${e=>e.theme.colors.primary[90]};
}
`,g=()=>{if(""!==document.dir)return"rtl"===document.dir;const{body:e}=document;return"rtl"===getComputedStyle(e).direction},b=()=>e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"feather feather-chevron-right",style:{transform:g()?"unset":"rotate(180deg)"}},e.createElement("polyline",{points:"9 18 15 12 9 6"})),k=()=>e.createElement("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"feather feather-chevron-left",style:{transform:g()?"unset":"rotate(180deg)"}},e.createElement("polyline",{points:"15 18 9 12 15 6"})),x=s.div`
display: flex;
justify-content: space-between;
align-items: center;
height: 56px;
padding-right: 8px;
padding-left: 8px;
background-color: ${e=>e.theme.colors.primary[95]};
border-bottom: 2px solid ${e=>e.theme.colors.primary[85]};
`,v=s.button`
will-change: auto;
min-width: 100px;
outline: none;
border: 0;
font-family: inherit;
background-color: transparent;
cursor: pointer;
color: ${e=>e.theme.colors.primary[50]};
padding: 8px 16px;
font-weight: 500;
transition: background-color 0.2s ease-in;
border-radius: ${e=>p[e.theme.round].calendarItem}px;
&:hover,
&:focus {
background-color: ${e=>e.theme.colors.primary[90]};
}
`;s.div`
text-align: right;
font-size: 14px;
width: 300px;
color: #8c8c8c;
border-bottom: 1px solid #cccccc;
border-left: 1px solid #cccccc;
`;const M=t=>e.createElement(x,{className:"zm-Header"},e.createElement(y,{"aria-label":"Previous month",onClick:t.onPrevClick,className:"zm-IconPrevButton",tabIndex:0},e.createElement(b,null)),e.createElement(v,{className:"zm-MonthYearButton",role:"presentation",onClick:t.onClickOnTitle,"aria-label":"calendar view is open, switch to year and month view",tabIndex:0},t.monthName),e.createElement(y,{"aria-label":"Next month",onClick:t.onNextClick,className:"zm-IconNextButton",tabIndex:0},e.createElement(k,null)));"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;var w={};({get exports(){return w},set exports(e){w=e}}).exports=function(){var e=1e3,t=6e4,r=36e5,n="millisecond",a="second",o="minute",s="hour",i="day",l="week",c="month",d="quarter",u="year",m="date",h="Invalid Date",f=/^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/,p=/\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g,y={name:"en",weekdays:"Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"),months:"January_February_March_April_May_June_July_August_September_October_November_December".split("_"),ordinal:function(e){var t=["th","st","nd","rd"],r=e%100;return"["+e+(t[(r-20)%10]||t[r]||t[0])+"]"}},g=function(e,t,r){var n=String(e);return!n||n.length>=t?e:""+Array(t+1-n.length).join(r)+e},b={s:g,z:function(e){var t=-e.utcOffset(),r=Math.abs(t),n=Math.floor(r/60),a=r%60;return(t<=0?"+":"-")+g(n,2,"0")+":"+g(a,2,"0")},m:function e(t,r){if(t.date()<r.date())return-e(r,t);var n=12*(r.year()-t.year())+(r.month()-t.month()),a=t.clone().add(n,c),o=r-a<0,s=t.clone().add(n+(o?-1:1),c);return+(-(n+(r-a)/(o?a-s:s-a))||0)},a:function(e){return e<0?Math.ceil(e)||0:Math.floor(e)},p:function(e){return{M:c,y:u,w:l,d:i,D:m,h:s,m:o,s:a,ms:n,Q:d}[e]||String(e||"").toLowerCase().replace(/s$/,"")},u:function(e){return void 0===e}},k="en",x={};x[k]=y;var v="$isDayjsObject",M=function(e){return e instanceof Y||!(!e||!e[v])},w=function e(t,r,n){var a;if(!t)return k;if("string"==typeof t){var o=t.toLowerCase();x[o]&&(a=o),r&&(x[o]=r,a=o);var s=t.split("-");if(!a&&s.length>1)return e(s[0])}else{var i=t.name;x[i]=t,a=i}return!n&&a&&(k=a),a||!n&&k},$=function(e,t){if(M(e))return e.clone();var r="object"==typeof t?t:{};return r.date=e,r.args=arguments,new Y(r)},D=b;D.l=w,D.i=M,D.w=function(e,t){return $(e,{locale:t.$L,utc:t.$u,x:t.$x,$offset:t.$offset})};var Y=function(){function y(e){this.$L=w(e.locale,null,!0),this.parse(e),this.$x=this.$x||e.x||{},this[v]=!0}var g=y.prototype;return g.parse=function(e){this.$d=function(e){var t=e.date,r=e.utc;if(null===t)return new Date(NaN);if(D.u(t))return new Date;if(t instanceof Date)return new Date(t);if("string"==typeof t&&!/Z$/i.test(t)){var n=t.match(f);if(n){var a=n[2]-1||0,o=(n[7]||"0").substring(0,3);return r?new Date(Date.UTC(n[1],a,n[3]||1,n[4]||0,n[5]||0,n[6]||0,o)):new Date(n[1],a,n[3]||1,n[4]||0,n[5]||0,n[6]||0,o)}}return new Date(t)}(e),this.init()},g.init=function(){var e=this.$d;this.$y=e.getFullYear(),this.$M=e.getMonth(),this.$D=e.getDate(),this.$W=e.getDay(),this.$H=e.getHours(),this.$m=e.getMinutes(),this.$s=e.getSeconds(),this.$ms=e.getMilliseconds()},g.$utils=function(){return D},g.isValid=function(){return!(this.$d.toString()===h)},g.isSame=function(e,t){var r=$(e);return this.startOf(t)<=r&&r<=this.endOf(t)},g.isAfter=function(e,t){return $(e)<this.startOf(t)},g.isBefore=function(e,t){return this.endOf(t)<$(e)},g.$g=function(e,t,r){return D.u(e)?this[t]:this.set(r,e)},g.unix=function(){return Math.floor(this.valueOf()/1e3)},g.valueOf=function(){return this.$d.getTime()},g.startOf=function(e,t){var r=this,n=!!D.u(t)||t,d=D.p(e),h=function(e,t){var a=D.w(r.$u?Date.UTC(r.$y,t,e):new Date(r.$y,t,e),r);return n?a:a.endOf(i)},f=function(e,t){return D.w(r.toDate()[e].apply(r.toDate("s"),(n?[0,0,0,0]:[23,59,59,999]).slice(t)),r)},p=this.$W,y=this.$M,g=this.$D,b="set"+(this.$u?"UTC":"");switch(d){case u:return n?h(1,0):h(31,11);case c:return n?h(1,y):h(0,y+1);case l:var k=this.$locale().weekStart||0,x=(p<k?p+7:p)-k;return h(n?g-x:g+(6-x),y);case i:case m:return f(b+"Hours",0);case s:return f(b+"Minutes",1);case o:return f(b+"Seconds",2);case a:return f(b+"Milliseconds",3);default:return this.clone()}},g.endOf=function(e){return this.startOf(e,!1)},g.$set=function(e,t){var r,l=D.p(e),d="set"+(this.$u?"UTC":""),h=(r={},r[i]=d+"Date",r[m]=d+"Date",r[c]=d+"Month",r[u]=d+"FullYear",r[s]=d+"Hours",r[o]=d+"Minutes",r[a]=d+"Seconds",r[n]=d+"Milliseconds",r)[l],f=l===i?this.$D+(t-this.$W):t;if(l===c||l===u){var p=this.clone().set(m,1);p.$d[h](f),p.init(),this.$d=p.set(m,Math.min(this.$D,p.daysInMonth())).$d}else h&&this.$d[h](f);return this.init(),this},g.set=function(e,t){return this.clone().$set(e,t)},g.get=function(e){return this[D.p(e)]()},g.add=function(n,d){var m,h=this;n=Number(n);var f=D.p(d),p=function(e){var t=$(h);return D.w(t.date(t.date()+Math.round(e*n)),h)};if(f===c)return this.set(c,this.$M+n);if(f===u)return this.set(u,this.$y+n);if(f===i)return p(1);if(f===l)return p(7);var y=(m={},m[o]=t,m[s]=r,m[a]=e,m)[f]||1,g=this.$d.getTime()+n*y;return D.w(g,this)},g.subtract=function(e,t){return this.add(-1*e,t)},g.format=function(e){var t=this,r=this.$locale();if(!this.isValid())return r.invalidDate||h;var n=e||"YYYY-MM-DDTHH:mm:ssZ",a=D.z(this),o=this.$H,s=this.$m,i=this.$M,l=r.weekdays,c=r.months,d=r.meridiem,u=function(e,r,a,o){return e&&(e[r]||e(t,n))||a[r].slice(0,o)},m=function(e){return D.s(o%12||12,e,"0")},f=d||function(e,t,r){var n=e<12?"AM":"PM";return r?n.toLowerCase():n};return n.replace(p,(function(e,n){return n||function(e){switch(e){case"YY":return String(t.$y).slice(-2);case"YYYY":return D.s(t.$y,4,"0");case"M":return i+1;case"MM":return D.s(i+1,2,"0");case"MMM":return u(r.monthsShort,i,c,3);case"MMMM":return u(c,i);case"D":return t.$D;case"DD":return D.s(t.$D,2,"0");case"d":return String(t.$W);case"dd":return u(r.weekdaysMin,t.$W,l,2);case"ddd":return u(r.weekdaysShort,t.$W,l,3);case"dddd":return l[t.$W];case"H":return String(o);case"HH":return D.s(o,2,"0");case"h":return m(1);case"hh":return m(2);case"a":return f(o,s,!0);case"A":return f(o,s,!1);case"m":return String(s);case"mm":return D.s(s,2,"0");case"s":return String(t.$s);case"ss":return D.s(t.$s,2,"0");case"SSS":return D.s(t.$ms,3,"0");case"Z":return a}return null}(e)||a.replace(":","")}))},g.utcOffset=function(){return 15*-Math.round(this.$d.getTimezoneOffset()/15)},g.diff=function(n,m,h){var f,p=this,y=D.p(m),g=$(n),b=(g.utcOffset()-this.utcOffset())*t,k=this-g,x=function(){return D.m(p,g)};switch(y){case u:f=x()/12;break;case c:f=x();break;case d:f=x()/3;break;case l:f=(k-b)/6048e5;break;case i:f=(k-b)/864e5;break;case s:f=k/r;break;case o:f=k/t;break;case a:f=k/e;break;default:f=k}return h?f:D.a(f)},g.daysInMonth=function(){return this.endOf(c).$D},g.$locale=function(){return x[this.$L]},g.locale=function(e,t){if(!e)return this.$L;var r=this.clone(),n=w(e,t,!0);return n&&(r.$L=n),r},g.clone=function(){return D.w(this.$d,this)},g.toDate=function(){return new Date(this.valueOf())},g.toJSON=function(){return this.isValid()?this.toISOString():null},g.toISOString=function(){return this.$d.toISOString()},g.toString=function(){return this.$d.toUTCString()},y}(),E=Y.prototype;return $.prototype=E,[["$ms",n],["$s",a],["$m",o],["$H",s],["$W",i],["$M",c],["$y",u],["$D",m]].forEach((function(e){E[e[1]]=function(t){return this.$g(t,e[0],e[1])}})),$.extend=function(e,t){return e.$i||(e(t,Y,$),e.$i=!0),$},$.locale=w,$.isDayjs=M,$.unix=function(e){return $(1e3*e)},$.en=x[k],$.Ls=x,$.p={},$}();var $=w,D={};({get exports(){return D},set exports(e){D=e}}).exports=function(e){function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e),n={name:"fa",weekdays:"یکشنبه_دوشنبه_سهشنبه_چهارشنبه_پنجشنبه_جمعه_شنبه".split("_"),weekdaysShort:"یکشنبه_دوشنبه_سهشنبه_چهارشنبه_پنجشنبه_جمعه_شنبه".split("_"),weekdaysMin:"ی_د_س_چ_پ_ج_ش".split("_"),weekStart:6,months:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),monthsShort:"ژانویه_فوریه_مارس_آوریل_مه_ژوئن_ژوئیه_اوت_سپتامبر_اکتبر_نوامبر_دسامبر".split("_"),ordinal:function(e){return e},formats:{LT:"HH:mm",LTS:"HH:mm:ss",L:"DD/MM/YYYY",LL:"D MMMM YYYY",LLL:"D MMMM YYYY HH:mm",LLLL:"dddd, D MMMM YYYY HH:mm"},relativeTime:{future:"در %s",past:"%s پیش",s:"چند ثانیه",m:"یک دقیقه",mm:"%d دقیقه",h:"یک ساعت",hh:"%d ساعت",d:"یک روز",dd:"%d روز",M:"یک ماه",MM:"%d ماه",y:"یک سال",yy:"%d سال"}};return r.default.locale(n,null,!0),n}(w);var Y={};({get exports(){return Y},set exports(e){Y=e}}).exports=function(e,t){t.prototype.weekday=function(e){var t=this.$locale().weekStart||0,r=this.$W,n=(r<t?r+7:r)-t;return this.$utils().u(e)?n:this.subtract(n,"day").add(e,"day")}};var E,_=Y,S={};({get exports(){return S},set exports(e){S=e}}).exports=(E={LTS:"h:mm:ss A",LT:"h:mm A",L:"MM/DD/YYYY",LL:"MMMM D, YYYY",LLL:"MMMM D, YYYY h:mm A",LLLL:"dddd, MMMM D, YYYY h:mm A"},function(e,t,r){var n=t.prototype,a=n.format;r.en.formats=E,n.format=function(e){void 0===e&&(e="YYYY-MM-DDTHH:mm:ssZ");var t=this.$locale().formats,r=function(e,t){return e.replace(/(\[[^\]]+])|(LTS?|l{1,4}|L{1,4})/g,(function(e,r,n){var a=n&&n.toUpperCase();return r||t[n]||E[n]||t[a].replace(/(\[[^\]]+])|(MMMM|MM|DD|dddd)/g,(function(e,t,r){return t||r.slice(1)}))}))}(e,void 0===t?{}:t);return a.call(this,r)}});var C=S;const L=(e,t,r)=>{const{locale:n}=m,a=Object.assign(Object.assign({},t),null!=r&&{numberingSystem:r});return new Date(e).toLocaleString(n,a)},T=(e,t)=>L(e,{day:"numeric"},t),I=(e,t)=>L(e,{year:"numeric"},t),O=(e,t)=>L(e,{month:"2-digit"},t);var N={};({get exports(){return N},set exports(e){N=e}}).exports=function(e,t,r){t.prototype.isBetween=function(e,t,n,a){var o=r(e),s=r(t),i="("===(a=a||"()")[0],l=")"===a[1];return(i?this.isAfter(o,n):!this.isBefore(o,n))&&(l?this.isBefore(s,n):!this.isAfter(s,n))||(i?this.isBefore(o,n):!this.isAfter(o,n))&&(l?this.isAfter(s,n):!this.isBefore(s,n))}};var A=N;$.extend(A);const B=(e,t)=>O(e)===O(t),F=(e,t)=>void 0!==e&&$(e).isSame(t,"day"),H={MMMM:(e,t)=>L(e,{month:"short"},t),MM:O,M:O,YYYY:I,YY:(e,t)=>L(e,{year:"2-digit"},t),DD:T,D:T},W=/\/|\s|-/,j=(e,t,r)=>{try{(e=>{const t=e.trimStart().trimEnd().split(W);if(""===e||""===e.trim())throw new Error("format is empty");t.forEach((e=>{if(!(e in H))throw new Error(`format is not valid, format passed is: ${e}`)}))})(t);const n=t.trimStart().trimEnd().split(W),a=t.match(W),o=null!==a?a[0]:"";return n.map((t=>H[t](e,r))).join(o)}catch(e){console.error(e)}return""};$.extend(_),$.extend(C);const z=e=>{const{locale:t}=m;$.locale(t);const r=void 0===e?new Date:$(e).toDate(),n=(e=>parseInt(L(e,{day:"numeric"},"latn"),10))(new Date(r)),a=$(new Date(r)).subtract(n-1,"days"),o=a.weekday(),s=$(a).subtract(o,"days"),i=a.add(15,"days");let l={days:[],current:0};const c=[];let d=$(s.format());for(let e=0;e<=5;e++){const e=[];for(let t=0;t<7;t++){const t=new Date(d.format());e.push({date:t,disabled:!B(a.toDate(),t),current:F(t,new Date)}),d=d.add(1,"day"),l={days:e,current:e.findIndex((e=>e.current))}}c.push(l)}return{id:Date.now(),monthName:j(new Date(r),"MMMM YYYY"),middleOfMonth:i.toDate(),weeks:c}},P=()=>g()?c:-850,R=({daysElementRefs:e,days:t,setDays:n})=>{const a=r(!1),o=t[0].middleOfMonth;return{slideToTheNextMonth:()=>{if(a.current)return;const r=$(o).add(1,"month"),s=z(r.toDate());n([...t,s]),requestAnimationFrame((()=>{a.current=!0;const[t,r]=e.current;t.style.transition=`transform 250ms ${d}`,t.style.transform=`translateX(${P()}px)`,r.style.transition=`transform 250ms ${d}`,r.style.transform=`translateX(${P()}px)`,setTimeout((()=>{n((e=>e.filter((e=>e.id===s.id)))),r.style.transition=null,r.style.transform=null,a.current=!1}),300)}))},slideToPrevMonth:()=>{if(a.current)return;const r=$(o).subtract(1,"month"),s=z(r.toDate());n([s,...t]),requestAnimationFrame((()=>{a.current=!0;const[t,r]=e.current;t.style.transform=`translateX(${P()}px)`,r.style.transform=`translateX(${P()}px)`,requestAnimationFrame((()=>{r.style.transition=`transform 250ms ${d}`,r.style.transform="translateX(0px)",t.style.transition=`transform 250ms ${d}`,t.style.transform="translateX(0px)",setTimeout((()=>{n((e=>e.filter((e=>e.id===s.id)))),t.style.transition=null,t.style.transform=null,a.current=!1}),300)}))}))}}},J={fa:{shortWeekDays:[{key:0,name:"شنبه"},{key:1,name:"یکشنبه"},{key:2,name:"دوشنبه"},{key:3,name:"سه شنبه"},{key:4,name:"چهارشنبه"},{key:5,name:"پنجشنبه"},{key:6,name:"جمعه"}],months:[{key:1,name:"فروردین"},{key:2,name:"اردیبهشت"},{key:3,name:"خرداد"},{key:4,name:"تیر"},{key:5,name:"مرداد"},{key:6,name:"شهریور"},{key:7,name:"مهر"},{key:8,name:"آبان"},{key:9,name:"آذر"},{key:10,name:"دی"},{key:11,name:"بهمن"},{key:12,name:"اسفند"}],format:"YYYY/MM/DD",am:"ق.ظ",pm:"ب.ظ"},en:{shortWeekDays:[{key:0,name:"S"},{key:1,name:"M"},{key:2,name:"T"},{key:3,name:"W"},{key:4,name:"T"},{key:5,name:"F"},{key:6,name:"S"}],months:[{key:1,name:"January"},{key:2,name:"February"},{key:3,name:"March"},{key:4,name:"April"},{key:5,name:"May"},{key:6,name:"June"},{key:7,name:"July"},{key:8,name:"August"},{key:9,name:"September"},{key:10,name:"October"},{key:11,name:"November"},{key:12,name:"December"}],format:"MM-DD-YY",am:"AM",pm:"PM"}};s.div`
color: inherit;
`;const U=s.button`
position: relative;
outline: none;
background-color: transparent;
display: flex;
font-family: inherit;
align-items: center;
justify-content: center;
width: ${e=>e.width}px;
height: ${e=>e.height}px;
border: 1px solid transparent;
user-select: none;
color: ${e=>e.theme.colors.gray[600]};
border-radius: ${e=>p[e.theme.round].calendarItem}px;
// pseudos
&:hover,
&:focus {
border-color: ${e=>e.theme.colors.gray[50]};
}
&:active {
background-color: ${e=>e.theme.colors.primary[40]};
border-color: transparent;
color: ${e=>e.theme.colors.gray[0]};
}
// days picker
&[data-selected='true'] {
background-color: ${e=>e.theme.colors.primary[50]};
border-color: transparent;
color: ${e=>e.theme.colors.gray[0]};
}
&[data-disabled='true'] {
border-color: transparent;
}
&[data-disabled='true'] .cl-text {
opacity: 0.5;
}
&:not([data-range='true']) {
transition: all 0.1s linear;
border-radius: ${e=>p[e.theme.round].calendarItem}px;
}
&:not([data-selected='true'])&[data-weekend='true'] {
color: #ff4d4d;
}
&:not([data-disabled='true']) {
cursor: pointer;
}
// range picker
&[data-in-range='true'] {
background-color: ${e=>e.theme.colors.primary[90]};
border-color: transparent;
}
&[data-start-range='true'] {
background-color: ${e=>e.theme.colors.primary[40]};
color: ${e=>e.theme.colors.gray[0]};
border-radius: ${e=>p[e.theme.round].calendarItem}px;
border-color: transparent;
}
&[data-end-range='true'] {
background-color: ${e=>e.theme.colors.primary[40]};
color: ${e=>e.theme.colors.gray[0]};
border-radius: ${e=>p[e.theme.round].calendarItem}px;
border-color: transparent;
}
&[data-in-range='true']:before,
&[data-end-range='true']:before {
content: ' ';
display: block;
position: absolute;
width: 40px;
height: 40px;
top: -1px;
left: ${e=>"rtl"===e.theme.direction?"20px":"unset"};
right: ${e=>"rtl"===e.theme.direction?"unset":"20px"};
background-color: ${e=>e.theme.colors.primary[90]};
z-index: -1;
}
&[data-in-range='true']:nth-of-type(1):before,
&[data-start-range='true']:before {
display: none;
}
`;U.defaultProps={width:40,height:40};const X=s.div`
display: flex;
justify-content: center;
align-items: center;
flex-wrap: wrap;
gap: 4px;
//height: ${c}px;
`,q=t=>{const{locale:r}=m,n=j(t.value,"MM","latn");return e.createElement(X,null,J[r].months.map((r=>e.createElement(U,{key:r.key,className:"zm-MonthPickerButton",width:90,height:48,"data-selected":r.key===parseInt(n,10),onClick:()=>t.onMonthSelect(r.key),"aria-current":"date",type:"button",tabIndex:0},r.name))))},V=s.div`
display: grid;
grid-template-columns: repeat(3, 92px);
grid-template-rows: auto;
justify-content: center;
gap: 4px;
max-height: ${c}px;
overflow: auto;
padding-top: 8px;
padding-bottom: 8px;
`,Z=r=>{const n=parseInt(j(r.value,"YYYY","latn"),10),a=t((()=>((e,t=80,r=50)=>{const n=parseInt(I(e,"latn"),10),a=n+r,o=[];for(let e=n-t;e<=a;e++)o.push(e);return o})(r.value)),[]),o=e.useCallback((e=>{if(null===e)return;const t=e.querySelector("button[data-selected=true]");if(null!=t){const{height:r,top:n}=e.getBoundingClientRect(),{top:a}=t.getBoundingClientRect();e.scrollTop=Math.abs(n-a)-r/2}}),[]);return e.createElement(V,{ref:o},a.map((t=>e.createElement(U,{className:"zm-YearPickerButton",key:t,width:90,height:48,"data-selected":n===t,"aria-selected":n===t,"aria-current":"date",type:"button",tabIndex:0,onClick:()=>r.onYearSelect(t)},(e=>{if("test"===process.env.NODE_ENV)return e;const{locale:t}=m;return Number(e).toLocaleString(t,{useGrouping:!1})})(t)))))},G=e=>!0===e.range,Q=e=>{const[t,r]=n(!1),[a,o]=n(void 0!==e.from?new Date(e.from):void 0),[s,i]=n(void 0!==e.to?new Date(e.to):void 0),l=(t,r)=>{"function"==typeof e.onChange&&G(e)&&null!=t&&null!=r&&e.onChange({from:t,to:r})};return{handlers:Object.assign({onClick:n=>!0===e.range?(e=>{const{value:n}=e.currentTarget.dataset;t||(void 0!==n&&(o(new Date(n)),i(null)),r(!0)),t&&null===s&&(void 0!==n&&(i(new Date(n)),l(a,new Date(n))),r(!1)),t&&void 0!==s&&(l(a,s),r(!1))})(n):(t=>{const{value:r,disabled:n}=t.currentTarget.dataset;if(void 0!==r&&"true"!==n)return G(e)||"function"!=typeof e.onChange||e.onChange({value:new Date(r)}),r})(n)},!0===e.range&&{onMouseMove:e=>{const{value:r}=e.currentTarget.dataset;t&&void 0!==r&&$(r).isAfter($(a))&&i(new Date(r))}}),from:a,to:s}},K=(a,o)=>{const{locale:s}=m,{defaultValue:i,weekends:l,events:c,width:d}=a,u=void 0===i?new Date:i,h=t((()=>z(i)),[]),[f,p]=n([h]),[y,g]=n("days"),b=r([]),k=R({daysElementRefs:b,days:f,setDays:p});Q(a);return e.createElement("div",{style:{width:d}},e.createElement(M,{monthName:f[0].monthName,onNextClick:()=>{if("days"===y)return k.slideToTheNextMonth()},onPrevClick:()=>{if("days"===y)return k.slideToPrevMonth()},onClickOnTitle:()=>{g("month"!==y&&"year"!==y?"year":"days")}}),"year"===y?e.createElement(Z,{value:u,onYearSelect:e=>{const t=((e,t)=>{const r=t-parseInt(I(e,"latn"),10);return r>0?$(e).add(r,"years").toDate():$(e).subtract(Math.abs(r),"years").toDate()})(u,e);p([z(t)]),g("month")}}):null,"month"===y?e.createElement(q,{value:u,onMonthSelect:e=>{const t=((e,t)=>{const r=t-parseInt(O(e,"latn"),10);return r>0?$(e).add(r,"months").toDate():$(e).subtract(Math.abs(r),"months").toDate()})(f[0].middleOfMonth,e);p([z(t)]),g("days")}}):null,"days"===y?e.createElement(e.Fragment,null,e.createElement("div",{style:{display:"grid",gridTemplateColumns:"repeat(7, 1fr)",fontSize:"12px",padding:"10px 0",color:"#414141"}},J[s].shortWeekDays.map((t=>e.createElement("div",{style:{textAlign:"center"},key:t.key},t.name)))),e.createElement("div",{style:{display:"flex",overflow:"hidden"}},f.map(((t,r)=>e.createElement("div",{key:t.id,style:{width:"100%"},ref:e=>{b.current[r]=e},role:"rowgroup"},t.weeks.map(((t,r)=>e.createElement("div",{key:r,style:{display:"grid",gridTemplateColumns:"repeat(7, 1fr)",fontSize:"14px",position:"relative"}},t.days.map(((t,r)=>{let n;if(c&&c.length){let e=c.find((e=>j(e.date,"YYYY/MM/DD")===j(t.date,"YYYY/MM/DD")));e&&(n=e.title)}let a={margin:"2px",border:"1px solid #b6b6b6",borderRadius:"3px",color:"#414141",height:"50px",padding:"0 5px"};return(null==l?void 0:l.some((e=>e===r)))&&Object.assign(a,{backgroundColor:"#ffcdcd",color:"#e04242"}),t.disabled&&Object.assign(a,{color:"#cbcbcb"}),F(u,t.date)&&Object.assign(a,{backgroundColor:"#72acff",color:"#083872"}),n&&Object.assign(a,{backgroundColor:"#c3fdc3",color:"#22522c"}),e.createElement("div",{style:a},e.createElement("div",{style:{textAlign:"right"}},j(t.date,"DD")),e.createElement("div",{style:{fontSize:12,textAlign:"center"}},n))})))))))))):null)};K.displayName="Calendar";var ee=a(K);const te=s.div`
label {
padding: 4px 8px;
margin: 0 8px;
background-color: #d0f8d0;
border-radius: 5px;
white-space: nowrap;
font-size: 12px;
font-weight: bold;
color: #343434;
cursor: pointer;
&[data-weekend='true'] {
background-color: #ffcdcd;
}
}
input[type="radio"] {
display: none;
}
input[type="radio"]:checked + label {
background-color: #31e731;
}
`,re=e=>{const t=["0","1","2","3","4","5","6","7","8","9"],r=["۰","۱","۲","۳","۴","۵","۶","۷","۸","۹"];let n="";for(let a=0;a<e.length;a++){const o=t.indexOf(e[a]);n+=-1!==o?r[o]:e[a]}return n},ne=(a,o)=>{const{locale:s}=m,{defaultTime:i,weekends:l,events:c,width:d,onChecked:u}=a,[h,f]=n(i),p=new Date,y=t((()=>z(new Date)),[]),[g,x]=n([y]),[v,M]=n("days"),w=y.weeks.findIndex((e=>e.current>-1)),[D,Y]=n(w),E=r([]),_=R({daysElementRefs:E,days:g,setDays:x});return e.createElement("div",{ref:o,style:{width:d}},e.createElement("div",{style:{display:"flex",alignItems:"center",justifyContent:"end",gap:"20px"}},e.createElement("div",{style:{display:"flex",alignItems:"center"}},e.createElement("div",{style:{display:"flex",alignItems:"center"}},e.createElement("button",{style:{border:"none",background:"transparent",fontSize:"20px",fontWeight:"bold",color:"#1b83fa",cursor:"pointer"},onClick:()=>{D>0&&Y(D-1)}},e.createElement(b,null)),e.createElement("span",{style:{backgroundColor:"#b6d7ff",color:"#1b83fa",borderRadius:"20px",padding:"2px 10px",fontSize:12}},"هفته ",re((D+1).toString())),e.createElement("button",{style:{border:"none",background:"transparent",fontSize:"20px",fontWeight:"bold",color:"#1b83fa",cursor:"pointer"},onClick:()=>{let e;g[0].weeks[D+1]&&(e=g[0].weeks[D+1].days.filter((e=>!0===e.disabled))),D<g[0].weeks.length-1&&e.length<7&&Y(D+1)}},e.createElement(k,null))),e.createElement("div",{style:{display:"flex",alignItems:"center"}},e.createElement("button",{style:{border:"none",background:"transparent",fontSize:"20px",fontWeight:"bold",color:"#1b83fa",cursor:"pointer"},onClick:()=>{if(Y(0),"days"===v)return _.slideToPrevMonth()}},e.createElement(b,null)),e.createElement("span",{style:{backgroundColor:"#b6d7ff",color:"#1b83fa",borderRadius:"20px",padding:"2px 10px",fontSize:12}},g[0].monthName),e.createElement("button",{style:{border:"none",background:"transparent",fontSize:"20px",fontWeight:"bold",color:"#1b83fa",cursor:"pointer"},onClick:()=>{if(Y(0),"days"===v)return _.slideToTheNextMonth()}},e.createElement(k,null))))),e.createElement("div",{style:{display:"flex",overflow:"hidden"}},g.map(((t,r)=>e.createElement("div",{key:t.id,style:{width:"100%"},ref:e=>{E.current[r]=e},role:"rowgroup"},t.weeks[D].days.map(((t,r)=>{const n=$(t.date).format("YYYY-MM-DD"),a=c.filter((e=>e.date_str===n));return t.times=a,e.createElement("div",{role:"row",style:{display:"flex",alignItems:"center",borderBottom:"1px solid #ccc"}},e.createElement("div",{key:J[s].shortWeekDays[r].key,style:{width:"15%",padding:"15px 8px",textAlign:"right",fontSize:12,fontWeight:"bold",borderLeft:"1px solid #ccc",color:F(p,t.date)?"#296fe0":"#343434"}},J[s].shortWeekDays[r].name,e.createElement("span",{style:{margin:"0 4px"}},"-"),e.createElement("span",null,j(t.date,"DD MMMM YYYY"))),e.createElement("div",{style:{display:"flex",padding:8,width:"85%"}},t.times.map((t=>{let n={};return"1"===t.is_book&&Object.assign(n,{backgroundColor:"#f6f6f6"}),e.createElement(te,null,e.createElement("input",{type:"radio",id:t.id,name:"time",value:t.id,checked:h===t.id,disabled:!("1"!==t.is_book&&!(null==l?void 0:l.some((e=>e===r)))),onChange:()=>{f(t.id),u&&u(t)}}),e.createElement("label",{htmlFor:t.id,id:"label"+t.id,"data-weekend":null==l?void 0:l.some((e=>e===r)),style:n},re(t.from_time_str)+" الی "+re(t.to_time_str)))}))))})))))))};ne.displayName="Calendar";var ae=a(ne);export{ee as Calendar,f as CalendarProvider,ae as WeekCalendar};