import{o as e}from"./chunk.DuxOD-Sk.js";import{r as t}from"./emotion-is-prop-valid.esm.DV_OErv-.js";import{Q as n}from"./protobuf.DyZGXwGk.js";import{n as r}from"./FormClearHelper.DblyIMUS.js";var i=e(t(),1);function a(e,t,n,r,a,o,s){(0,i.useEffect)(()=>{if(n)return e.registerQueryParamBinding(t,n,r,a,o,s?.urlFormat,...s?.dateType?[s.dateType]:[]),()=>{e.unregisterQueryParamBinding(t)}},[e,t,n,r,a,o,s])}function o({getStateFromWidgetMgr:e,getDefaultState:t,updateWidgetMgrState:a,element:o,widgetMgr:s,fragmentId:c,onFormCleared:l}){let[u,d]=(0,i.useState)(()=>e(s,o)??t(s,o)),[f,p]=(0,i.useState)({value:u,fromUi:!1});return(0,i.useEffect)(()=>{n(f)||(p(null),d(f.value),a(o,s,f,c))},[f,a,o,s,c]),r({widgetMgr:s,element:o,onFormCleared:(0,i.useCallback)(()=>{p({value:t(s,o),fromUi:!0}),l?.()},[p,o,t,s,l])}),[u,p]}function s(e){let{getStateFromWidgetMgr:t,getDefaultStateFromProto:r,getCurrStateFromProto:s,updateWidgetMgrState:c,element:l,widgetMgr:u,fragmentId:d,queryParamBinding:f}=e,p=e.formClearBehavior===`resetValueAndRunCallback`?e.onFormCleared:void 0,[m,h]=o({getStateFromWidgetMgr:t,getDefaultState:(0,i.useCallback)((e,t)=>t.setValue?s(t):r(t),[r,s]),updateWidgetMgrState:c,element:l,widgetMgr:u,fragmentId:d,onFormCleared:p}),g=!n(f),_=(0,i.useMemo)(()=>{if(g)return f?.urlDefault===void 0?r(l):f.urlDefault},[g,l,r,f?.urlDefault===void 0?void 0:JSON.stringify(f.urlDefault)]),v=(0,i.useMemo)(()=>g?{urlFormat:f?.urlFormat,dateType:f?.dateType}:void 0,[g,f?.urlFormat,f?.dateType]);return a(u,l.id,f?.paramKey??null,f?.valueType??`string_value`,_,f?.clearable??!1,v),(0,i.useEffect)(()=>{l.setValue&&(l.setValue=!1,h({value:s(l),fromUi:!1}))},[l,s,h]),[m,h]}export{s as n,o as t};