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