import{a8 as j,v as l,J as x,N as E,i as L,g as O}from"./B08CJtNn.js";const R={"Content-Seite":"contentPage",Nutzerbereich:"userArea",Rechtstexte:"legalText","Redaktionelle Seiten":"editorialPage",Shopseiten:"ecommercePage","Technische Seite":"technicalPage","Technische Seiten":"technicalPages",Unternehmensseite:"companyPage",none:"unsorted"},A=j("SystemStore",()=>{const g=l(!0),s=l({}),{t:h}=x(),{kapi:f}=E(),p=l(null),S=async(e,n=!1)=>{if(s.value[e]&&!n)return s.value[e];g.value=!0;try{const t=await f("System"),[{components:o},{suggestions:i},{limit:a}]=await Promise.all([t.getComponents(Number(e)),t.getComponentSuggestions(Number(e)),t.getComponentLimit(Number(e))]),u=Object.entries(i).map(d=>d[1].map(y=>y.identifier)).flat();s.value[e]||(s.value[e]={});const r=i.length===0?C(a,o):b(i,o);Object.assign(s.value[e],{suggestionTypes:u,suggestions:i,components:o,limit:a,combinedSuggestions:r})}catch(t){p.value=t}finally{g.value=!1}},C=(e,n)=>({componentLimit:e,componentCount:n.length,suggestionKeys:[],entries:n.map(t=>({id:t.suggestion?.id||0,suggestionKey:"unsorted",identifier:t.suggestion?.identifier||"",optional:!0,priority:"0",component:{id:t.id,name:t.name,url:t.url},system_type:{id:t.type.id,name:t.type.name}}))}),b=(e,n)=>{const t=[],o=[];return Object.entries(e).forEach(([i,a])=>{const u=R[i]||"unsorted";o.push(u),a.forEach(r=>{const{name:d,description:y,...P}=r,c=n.find(T=>T.suggestion.id===r.id),N=c?{id:c.id,name:c.name,url:c.url}:{id:0,name:h(`admin.components.names.${r.identifier}`),url:""},K={suggestionKey:u,...P,component:N};t.push(K)})}),{componentCount:n.length,componentLimit:e.length,suggestionKeys:o,entries:t}},v=L(),m=O(()=>{const{sid:e}=v.params;return e?s.value[String(e)]:null});return{polling:g,systemStore:s,getPageComponents:S,getPageComponent:e=>m.value?m.value.components?.find(n=>n.id===Number(e)):null,selectCurrentSystem:m,systemStoreErrors:p}});export{A as u};
