(function(s,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("@wix/builder-state"),require("react"),require("@wix/services-manager-react")):typeof define=="function"&&define.amd?define(["exports","@wix/builder-state","react","@wix/services-manager-react"],i):(s=typeof globalThis<"u"?globalThis:s||self,i(s["Builder-state-react"]={},s.BuilderState,s.React,s.ServicesManagerReact))})(this,function(s,i,r,O){"use strict";const f=new i.StateStoreImpl,d=r.createContext(f),b=({itemIds:e,children:t})=>e.map(o=>r.createElement(v,{itemId:o,key:o},t)),v=({children:e,itemId:t})=>{const o=r.useContext(d),c=r.useMemo(()=>o.createScopedStore(t),[o,t]);return r.useEffect(()=>()=>{o.disposeScopedStore(t)},[t,o]),r.createElement(d.Provider,{value:c},e)},m=e=>{let t="";for(const[o,c]of Object.entries(e)){t+=`.${o} {`;for(const[l,u]of Object.entries(c))t+=`${l}: ${u};`;t+="}"}return t},C=({styles:e})=>{const t=r.useSyncExternalStore(e.subscribe,()=>e.getAllStyles(),()=>e.getAllStyles());return t?r.createElement("style",{"data-testid":"style-overrides"},m(t)):null},E=({createState:e,VeloRuntime:t})=>({subscribeToChanges:c,overrides:l,...u})=>{const y=O.useGetService(),{stateStore:a,velo:p}=u.stateStore?u:r.useMemo(()=>e(u,y),[]);return r.useMemo(()=>{c?.(n=>{Object.entries(n).forEach(([S,j])=>{a.props.updateOverrides(S,j)})}),Object.entries(l||{}).forEach(([n,S])=>a.props.updateOverrides(n,S))},[]),r.createElement(r.Fragment,null,r.createElement(d.Provider,{value:a},t?r.createElement(t,{...u,...u.velo?u.velo:p},u.children):u.children),r.createElement(C,{styles:a.styles}))},P=e=>{const t=r.useContext(d),[,o]=r.useState(0),c=()=>o(n=>n+1),l=t.props.getOverrides(e);r.useEffect(()=>{const n=t.props.subscribeByNickname(e,c);return()=>{n()}},[e]);const u=r.useSyncExternalStore(n=>t.deletedComponents.subscribeByNickname(e,n),()=>t.deletedComponents.getOverrides(e),()=>t.deletedComponents.getOverrides(e));return[l,!!u,{updateProps:n=>{t.props.updateOverrides(e,n)},updateStyles:n=>{const S=t.props.getOverrides(e)?.id;t.styles.updateOverrides(S,n)}}]},g=e=>({scopeId:t})=>r.createElement(v,{itemId:t,key:t},e({scopeId:t})),h=e=>r.useCallback(g(e),[e]);s.ContextualStateProvider=v,s.Repeat=b,s.StateContext=d,s.createStateProvider=E,s.stateStore=f,s.useRepeaterChildren=h,s.useStateOverrides=P,Object.keys(i).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(s,e)&&Object.defineProperty(s,e,{enumerable:!0,get:()=>i[e]})}),Object.defineProperty(s,Symbol.toStringTag,{value:"Module"})});
//# sourceMappingURL=builder-state-react.js.map