import{c as e,i as t}from"./preload-helper-B45gAKPr.js";import{pn as n}from"./iframe-GmIo3IOR.js";import{a as r,i,n as a,o,r as s,s as c}from"./odata-BXYPW5TY.js";function l(e,t,n){return e?`${e}/${t}:${n}`:`${t}:${n}`}function u(e,t,n){let r=n[t];return r&&e[r]||e[t]}function d(e){return[...new Set(e.filter(Boolean))].join(` `)}function f(e){return{id:l(e.parentId,e.codeKey,e.value),codeKey:e.codeKey,value:e.value,label:e.label,code:e.code,searchText:d([e.value,e.label,e.code]),children:[],childByBranchKey:new Map}}function p(e){return{id:e.id,codeKey:e.codeKey,value:e.value,label:e.label,code:e.code,searchText:e.searchText,children:e.children.length>0?e.children.map(p):void 0}}function m({items:e,orderedCodeKeys:t,keyPairsMap:n,hiddenCodeKeys:r,textValueCodeKeys:i}){if(t.length===0||e.length===0)return[];let a=[],o=new Map;for(let s of e){let e;for(let c of t){let t=String(s[c]??``);if(!t)break;let l=String(u(s,c,n)??``),d=i?.has(c)?l:t,p=`${c}:${d}`,m=e?e.childByBranchKey:o,h=m.get(p);h||(h=f({parentId:e?.id,codeKey:c,value:d,label:l,code:r.has(c)?void 0:t}),m.set(p,h),e?e.children.push(h):a.push(h)),e=h}}return a.map(p)}var h=t((()=>{}));function g(e,t){return i(e,t)}var _=t((()=>{c()}));function v(e,t,n){return s([{odata:e,segments:t,model:n}])}function y(e){return e[0]?.id}function b({odata:e,segments:t,model:n}){let i=`${e.service}.${e.target}`,s=(0,x.useMemo)(()=>v(e,t,n),[e,t,n]),c=a([e]),l=(0,x.useMemo)(()=>g(s,c),[s,c]),u=(0,x.useMemo)(()=>l.map(e=>e.id),[l]),d=o({odata:e,model:r({codeKey:y(l)??Object.keys(t)[0],...n})}),{hiddenCodeKeys:f,textValueCodeKeys:p}=(0,x.useMemo)(()=>{let t=new Set,n=new Set;for(let r of l)(r.segment.hideCode??e.hideCode)&&t.add(r.id),r.segment.selectText&&n.add(r.id);return{hiddenCodeKeys:t,textValueCodeKeys:n}},[e.hideCode,l]),h=(0,x.useMemo)(()=>m({items:d.data?.items??[],orderedCodeKeys:u,keyPairsMap:d.data?.keyPairsMap??{},hiddenCodeKeys:f,textValueCodeKeys:p}),[d.data?.items,d.data?.keyPairsMap,f,u,p]),_=l[0]?.segment.placeholder??`Выберите значение`,b=!!c[i]?.length;return{nodes:h,orderedSegmentItems:l,orderedCodeKeys:u,isLoading:d.isLoading,isError:d.isError,placeholder:_,hasResolvedChain:b}}var x,S=t((()=>{x=e(n(),1),c(),h(),_()}));export{b as n,S as t};