import{o as e}from"./rolldown-runtime.C0FnF6B9.js";import{r as t}from"./emotion-is-prop-valid.esm.CuYlOKOk.js";import{t as n}from"./types.cZoyy9Y-.js";import{n as r}from"./FormClearHelper.G2WY61Ig.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});(0,i.useEffect)(()=>{n(f)||(p(null),d(f.value),a(o,s,f,c))},[f,a,o,s,c]);let m=(0,i.useCallback)(()=>{p({value:t(s,o),fromUi:!0}),l?.()},[p,o,t,s,l]);return r({widgetMgr:s,element:o,onFormCleared:m}),[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),_=f?.urlDefault===void 0?void 0:JSON.stringify(f.urlDefault),v=(0,i.useMemo)(()=>{if(g)return f?.urlDefault===void 0?r(l):f.urlDefault},[g,l,r,_]),y=(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`,v,f?.clearable??!1,y),(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};