import{r as o,F as s}from"./index-DCNLpqIv.js";import{u as F}from"./FormClearHelper-fvwQICEk.js";function S({getStateFromWidgetMgr:i,getDefaultState:r,updateWidgetMgrState:m,element:t,widgetMgr:e,fragmentId:n,onFormCleared:l}){const[d,f]=o.useState(()=>i(e,t)??r(e,t)),[g,a]=o.useState({value:d,fromUi:!1});o.useEffect(()=>{s(g)||(a(null),f(g.value),m(t,e,g,n))},[g,m,t,e,n]);const u=o.useCallback(()=>{a({value:r(e,t),fromUi:!0}),l?.()},[a,t,r,e,l]);return F({widgetMgr:e,element:t,onFormCleared:u}),[d,a]}function M({getStateFromWidgetMgr:i,getDefaultStateFromProto:r,getCurrStateFromProto:m,updateWidgetMgrState:t,element:e,widgetMgr:n,fragmentId:l,onFormCleared:d}){const f=o.useCallback((u,c)=>r(c),[r]),[g,a]=S({getStateFromWidgetMgr:i,getDefaultState:f,updateWidgetMgrState:t,element:e,widgetMgr:n,fragmentId:l,onFormCleared:d});return o.useEffect(()=>{e.setValue&&(e.setValue=!1,a({value:m(e),fromUi:!1}))},[e,m,a]),[g,a]}export{M as a,S as u};
