import{r as s,e as F}from"./index.RuhrnD1v.js";import{u as V}from"./FormClearHelper.DFo50Lfo.js";function p(o,l,t,e,a,r,n){s.useEffect(()=>{if(t)return o.registerQueryParamBinding(l,t,e,a,r,n?.urlFormat,...n?.dateType?[n.dateType]:[]),()=>{o.unregisterQueryParamBinding(l)}},[o,l,t,e,a,r,n])}function h({getStateFromWidgetMgr:o,getDefaultState:l,updateWidgetMgrState:t,element:e,widgetMgr:a,fragmentId:r,onFormCleared:n}){const[c,u]=s.useState(()=>o(a,e)??l(a,e)),[i,f]=s.useState({value:c,fromUi:!1});s.useEffect(()=>{F(i)||(f(null),u(i.value),t(e,a,i,r))},[i,t,e,a,r]);const d=s.useCallback(()=>{f({value:l(a,e),fromUi:!0}),n?.()},[f,e,l,a,n]);return V({widgetMgr:a,element:e,onFormCleared:d}),[c,f]}function D(o){const{getStateFromWidgetMgr:l,getDefaultStateFromProto:t,getCurrStateFromProto:e,updateWidgetMgrState:a,element:r,widgetMgr:n,fragmentId:c,queryParamBinding:u}=o,i=o.formClearBehavior==="resetValueAndRunCallback"?o.onFormCleared:void 0,f=s.useCallback((P,v)=>v.setValue?e(v):t(v),[t,e]),[d,C]=h({getStateFromWidgetMgr:l,getDefaultState:f,updateWidgetMgrState:a,element:r,widgetMgr:n,fragmentId:c,onFormCleared:i}),m=!F(u),y=u?.urlDefault!==void 0?JSON.stringify(u.urlDefault):void 0,B=s.useMemo(()=>{if(m)return u?.urlDefault!==void 0?u.urlDefault:t(r)},[m,r,t,y]),S=s.useMemo(()=>m?{urlFormat:u?.urlFormat,dateType:u?.dateType}:void 0,[m,u?.urlFormat,u?.dateType]);return p(n,r.id,u?.paramKey??null,u?.valueType??"string_value",B,u?.clearable??!1,S),s.useEffect(()=>{r.setValue&&(r.setValue=!1,C({value:e(r),fromUi:!1}))},[r,e,C]),[d,C]}export{h as a,D as u};
