2 lines
4.3 KiB
JavaScript
2 lines
4.3 KiB
JavaScript
import{j as e,b,an as X,I as j,cb as _,b3 as I,aM as T,cc as tt,T as M,C as et,a5 as m}from"./mui-vendor-D_SVL-Dx.js";import{r as p}from"./react-vendor-CmFgShSM.js";import{et as a,v as V}from"./index-D80MdVQn.js";const rt=({onDateSelect:v,dayData:d={},selectedDate:f=null,label:W="انتخاب تاریخ",className:Z="",disableToday:$=!1,maxGregorianDate:D=null,customDateFilter:Y=null})=>{const[r,w]=p.useState(new a),[S,B]=p.useState([]),[A,E]=p.useState(null),k=p.useRef(null),L=!!A,z=()=>{E(k.current)},R=()=>{E(null)},F=["فروردین","اردیبهشت","خرداد","تیر","مرداد","شهریور","مهر","آبان","آذر","دی","بهمن","اسفند"],N=["ش","ی","د","س","چ","پ","ج"],O=t=>d[t]||null,P=t=>{const s=t.format("YYYY/MM/DD");if(Y)return Y(t,s,d);const u=new a,x=new a().subtract("day",2),c=new a().subtract("day",1),l=u.format("YYYY/MM/DD"),o=x.format("YYYY/MM/DD"),n=c.format("YYYY/MM/DD"),i=$?!1:s===l;let h=!1;if(D){const g=t.toDate?t.toDate():new Date;h=V(g).isAfter(V(D),"day")}const C=d[s]!==void 0&&(d[s].active===void 0||d[s].active===!0);return!h&&(i||s===o||s===n||C)};p.useEffect(()=>{(()=>{const s=[],u=r.year(),x=r.month(),c=r.daysInMonth();let o=new a([u,x,1]).day();o>=1&&o<=7&&(o=o-1),o=o%7;for(let n=0;n<o;n++)s.push(null);for(let n=1;n<=c;n++){const i=new a([u,x,n]),h=new a,y=P(i),C=i.format("YYYY/MM/DD"),g=O(C),U=y&&g&&g.value1===0;s.push({date:i,day:n,formattedDate:C,isToday:i.year()===h.year()&&i.month()===h.month()&&i.date()===h.date(),isEnabled:y,hasZeroValue:U})}B(s)})()},[r,d]);const H=t=>{t&&t.isEnabled&&!t.hasZeroValue&&v&&(v(t),R())},q=()=>{const t=new a([r.year(),r.month()+1,1]);w(t)},G=()=>{const t=new a([r.year(),r.month()-1,1]);w(t)},J=t=>f&&f===t,K=t=>t==null?"":t.toLocaleString("fa-IR"),Q=()=>{if(!f)return"";const t=S.find(s=>s&&s.formattedDate===f);return t?`${t.day.toLocaleString("fa-IR")} ${F[t.date.month()-1]}`:f};return e.jsxs(b,{className:Z,sx:{width:"100%"},children:[e.jsx(X,{ref:k,fullWidth:!0,value:Q(),onClick:z,label:W,placeholder:"انتخاب تاریخ...",size:"medium",InputProps:{readOnly:!0,startAdornment:e.jsx(j,{size:"small",onClick:z,children:e.jsx(_,{fontSize:"small"})})},sx:{cursor:"pointer",width:"100%",fontSize:{xs:"13px",sm:"16px"}}}),e.jsx(I,{open:L,anchorEl:A,onClose:R,anchorOrigin:{vertical:"bottom",horizontal:"left"},transformOrigin:{vertical:"top",horizontal:"left"},children:e.jsxs(T,{elevation:3,sx:{p:{xs:1,sm:2},borderRadius:3,backgroundColor:"#fff",maxWidth:500,width:"99%"},children:[e.jsxs(b,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center",mb:{xs:1,sm:2},pb:{xs:1,sm:2},borderBottom:"2px solid #f0f0f0"},children:[e.jsx(j,{onClick:G,size:"small",children:e.jsx(tt,{})}),e.jsxs(M,{variant:"h6",sx:{fontWeight:"bold",color:"#333",fontSize:{xs:"16px",sm:"20px"}},children:[F[r.month()-1]," ",r.year()]}),e.jsx(j,{onClick:q,size:"small",children:e.jsx(et,{})})]}),e.jsx(m,{container:!0,spacing:{xs:.5,sm:1},sx:{mb:{xs:.5,sm:1}},children:N.map((t,s)=>e.jsx(m,{item:!0,xs:12/7.3,children:e.jsx(b,{sx:{textAlign:"center",fontWeight:"bold",color:"#666",fontSize:{xs:"12px",sm:"14px"},py:{xs:.5,sm:1}},children:t})},s))}),e.jsx(m,{container:!0,spacing:{xs:.5,sm:1},children:S.map((t,s)=>{if(!t)return e.jsx(m,{item:!0,xs:12/7.3,children:e.jsx(b,{sx:{aspectRatio:"1/1"}})},`empty-${s}`);const u=O(t.formattedDate),x=J(t.formattedDate);let c="#fff",l="#e0e0e0",o=1,n="pointer";return!t.isEnabled||t.hasZeroValue?(c="#f5f5f5",l="#d0d0d0",o=t.hasZeroValue?.4:.25,n="not-allowed"):x&&(c="#e3f2fd",l="#1976d2"),t.isToday&&t.isEnabled&&!t.hasZeroValue&&(l="#ff9800"),e.jsx(m,{item:!0,xs:12/7.3,children:e.jsxs(T,{onClick:()=>H(t),sx:{aspectRatio:"1/1",cursor:n,transition:"all 0.2s ease",backgroundColor:c,border:{xs:`1.5px solid ${l}`,sm:`2px solid ${l}`},display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",p:{xs:.5,sm:1},gap:{xs:.25,sm:.5},opacity:o,"&:hover":t.isEnabled&&!t.hasZeroValue?{transform:"scale(1.05)",boxShadow:"0 4px 12px rgba(0,0,0,0.15)",backgroundColor:"#f5f5f5"}:{}},children:[e.jsx(M,{variant:"body1",sx:{fontWeight:"bold",fontSize:{xs:"16px",sm:"20px"},color:t.isToday?"#ff9800":"#333",lineHeight:1.2},children:t.day.toLocaleString("fa-IR")}),u&&u.value1!==void 0&&e.jsx(M,{variant:"caption",sx:{fontSize:{xs:"10px",sm:"13px"},color:"#1976d2",fontWeight:"600",lineHeight:1.2},children:K(u.value1)})]})},s)})})]})})]})};export{rt as M};
|