import{r as u}from"./index-BP8_t0zE.js";import{S as Q}from"./DeleteButton-BNKEwqMZ.js";import{p as U}from"./pick-BQz50zYv.js";import{c as X}from"./defaultI18nProvider-C_r1y4tu.js";import{u as Z,I as _,s as ee}from"./SimpleForm-DxY-i_Qk.js";import{T as re}from"./TextField-z9WrHgJg.js";import{F as te}from"./getFieldLabelTranslationArgs-DwcCC9dO.js";var ge=function(e){var r=e.children,a=e.value;return u.createElement(Q.Provider,{value:a},r)},pe=function(e){var r=u.useMemo(function(){return U(e,["save","saving","mutationMode","registerMutationMiddleware","unregisterMutationMiddleware"])},[e.save,e.saving,e.mutationMode,e.registerMutationMiddleware,e.unregisterMutationMiddleware]);return r},M=function(e,r,a){if(a||arguments.length===2)for(var t=0,n=r.length,l;t<n;t++)(l||!(t in r))&&(l||(l=Array.prototype.slice.call(r,0,t)),l[t]=r[t]);return e.concat(l||Array.prototype.slice.call(r))},me=function(){var e=u.useRef([]),r=u.useCallback(function(l){e.current.push(l)},[]),a=u.useCallback(function(l){e.current=e.current.filter(function(s){return s!==l})},[]),t=u.useCallback(function(l){var s=M([],e.current,!0);return function(){for(var p=[],v=0;v<arguments.length;v++)p[v]=arguments[v];var m=s.length-1,D=function(){for(var h=[],g=0;g<arguments.length;g++)h[g]=arguments[g];return m--,m>=0?s[m].apply(s,M(M([],h,!1),[D],!1)):l.apply(void 0,h)};return s.length>0?s[m].apply(s,M(M([],p,!1),[D],!1)):l.apply(void 0,p)}},[]),n=u.useMemo(function(){return{registerMutationMiddleware:r,getMutateWithMiddlewares:t,unregisterMutationMiddleware:a}},[r,t,a]);return n};function ae(e){return function(r){e.forEach(function(a){typeof a=="function"?a(r):a!=null&&(a.current=r)})}}var C=function(){return C=Object.assign||function(e){for(var r,a=1,t=arguments.length;a<t;a++){r=arguments[a];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},C.apply(this,arguments)},ne=function(e,r){var a={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(a[t]=e[t]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,t=Object.getOwnPropertySymbols(e);n<t.length;n++)r.indexOf(t[n])<0&&Object.prototype.propertyIsEnumerable.call(e,t[n])&&(a[t[n]]=e[t[n]]);return a},he=function(e){var r=e.className,a=e.defaultValue,t=e.format,n=t===void 0?b:t,l=e.label,s=e.source,p=e.resource,v=e.helperText,m=e.margin,D=e.onBlur,h=e.onChange,g=e.onFocus,d=e.parse,E=e.validate,j=e.variant,T=e.disabled,O=e.readOnly,x=ne(e,["className","defaultValue","format","label","source","resource","helperText","margin","onBlur","onChange","onFocus","parse","validate","variant","disabled","readOnly"]),w=Z(C({defaultValue:a,onBlur:D,resource:p,source:s,validate:E,disabled:T,readOnly:O},x)),i=w.field,F=w.fieldState,q=w.id,z=w.isRequired,I=u.useState(1),H=I[0],N=I[1],R=u.useRef(!1),f=u.useRef(),A=u.useRef(i.value);u.useEffect(function(){var o=new Date(A.current).getTime()||null,c=new Date(i.value).getTime()||null;o!==c&&!R.current&&(N(function(y){return y+1}),d?i.onChange(d(i.value)):i.onChange(i.value),A.current=i.value,R.current=!1)},[N,d,i]);var P=i.onBlur,V=u.useRef(!1),L=function(o){if(h&&h(o),!(typeof o.target>"u"||typeof o.target.value>"u")){var c=o.target,y=c.valueAsDate!==void 0&&c.valueAsDate!==null&&!isNaN(new Date(c.valueAsDate).getTime())?d?d(c.valueAsDate):b(c.valueAsDate):d?d(c.value):b(c.value);y!==""&&y!=null&&(i.onChange(y),R.current=!0)}},W=function(o){g&&g(o),V.current=!0},Y=function(){if(V.current=!1,!!f.current){var o=f.current.valueAsDate!==void 0&&f.current.valueAsDate!==null&&!isNaN(new Date(f.current.valueAsDate).getTime())?d?d(f.current.valueAsDate):b(f.current.valueAsDate):d?d(f.current.value):b(f.current.value);o!==i.value&&i.onChange(o??""),P&&P()}},S=F.error,k=F.invalid,$=v!==!1||k,G=i.ref,J=i.name,K=ae([G,f]);return u.createElement(re,C({id:q,name:J,inputRef:K,defaultValue:n(A.current),key:H,type:"date",onChange:L,onFocus:W,onBlur:Y,className:X("ra-input","ra-input-".concat(s),r),size:"small",variant:j,margin:m,error:k,disabled:T||O,readOnly:O,helperText:$?u.createElement(_,{error:S==null?void 0:S.message,helperText:v}):null,label:u.createElement(te,{label:l,source:s,resource:p,isRequired:z}),InputLabelProps:le},ee(x)))},B=function(e){if(!(e instanceof Date)||isNaN(e.getDate()))return"";var r="00",a=e.getFullYear().toString(),t=(e.getMonth()+1).toString(),n=e.getDate().toString();return"".concat(a,"-").concat((r+t).slice(-2),"-").concat((r+n).slice(-2))},ue=/^\d{4}-\d{2}-\d{2}$/,le={shrink:!0},b=function(e){return e==null||e===""?null:e instanceof Date?B(e):ue.test(e)?e:B(new Date(e))};export{he as D,ge as S,pe as a,me as u};
