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