"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("@gem-sdk/core");exports.default=r=>{let{setting:u,builderProps:n,children:i}=r,{activeKey:c,expandItem:o,expandedMode:l}=u??{},s=e.useRef([]),[f,a]=e.useState([]),d=t.useEditorMode(),{onListener:g,saveToElementInteractionData:p,ref:m,findElementIncludingSelf:S}=t.useInteraction(),E=e.useMemo(()=>"multiple"===l,[l]);e.useEffect(()=>{o||(s.current=[],a([]))},[o]),e.useEffect(()=>{E||c||(s.current=["0"],a(["0"])),c||(s.current=[],a([]))},[E,c]),e.useEffect(()=>{if(c&&o){let e=c?.toString()?.toLowerCase()?.split(",")?.map(e=>parseInt(e.trim())-1)?.map(e=>e.toString());a(e),s.current=e}},[c,o]),e.useEffect(()=>{if(o||(a([]),s.current=[]),c?.toString()?.toLowerCase()==="all"&&o){let t=Array.from(e.Children?.map(i,(e,t)=>t.toString()));a(t),s.current=t}},[c,i,o]);let v=e=>{f.includes(e)?(a([]),s.current=[]):(a([e]),s.current=[e])},h=e=>{let t=[];a(t=f.includes(e)?f.filter(t=>t!==e):[...f,e]),s.current=t};return e.useEffect(()=>{let e=`[data-id="${n?.uid}"]`;g({event:"gp:change-expanded-item-original",selector:e},t=>{let r=S(m.current||document,e),{data:u,isRollback:n,key:i}=t||{};if(void 0===u&&n)return;if(n){a(u);return}let c=[...s.current];p(r,i,JSON.stringify({data:c}));let o=u.toString();a(c=E?[...c.filter(e=>e!==o),o]:[o])})},[n?.uid,E,S,g,m,p]),e.useEffect(()=>{s.current=f},[f]),{ref:m,mode:d,accordions:f,activeKey:c,setAccordions:a,handleDropdown:e=>{E?h(e.toString()):v(e.toString())}}};
