import{z as t,c as f,j as O,k as I}from"./JQJBiNWj.js";import{o as T}from"./FcRkkR--.js";import{T as A,G as C}from"./BKl0aY3w.js";import{g as E}from"./Dd3ROLQd.js";const h={MONIT:"MONITORACAO",DOCTO:"DOCUMENTAL"},v={MANUT:"PARAMETRO_MANUTENCAO",CONSE:"PARAMETRO_CONSERVACAO",OPERA:"PARAMETRO_OPERACIONAL"},P={PER:"PER",CTR:"Contrato"},k=T(P);function g(o,r,i){var m;const a={},s={},u=o.sort(b);for(const e of u){if(e.idEstruturaPerPai&&(s[e.idEstruturaPerPai]=!0),i==="SEM_VOLUME"&&e.volume||i!=="SEM_VOLUME"&&e.volume!==i||r&&!(e.nroItem+" "+e.descricao).toLocaleLowerCase().includes(r.toLocaleLowerCase()))continue;const n=e.id.idEstrutura.toString(),c={key:n,data:{...e,name:e.nroItem+" - "+e.descricao},children:[]};r&&!((m=c.data.name)!=null&&m.toLocaleLowerCase().includes(r.toLocaleLowerCase()))||(a[n]=c)}return r?Object.values(a).filter(e=>e).map(e=>({...e,data:{...e.data,hasChildren:s[e.data.id.idEstrutura]}})):(Object.keys(a).forEach(e=>{var d,p;const n=a[e];if(!n)return;const c=(p=(d=n==null?void 0:n.data)==null?void 0:d.idEstruturaPerPai)==null?void 0:p.toString();if(!c||!a[c])return;const l=a[c];l.children?l.children.push(n):l.children=[n],l.data.hasChildren=!0,n.isChildren=!0}),Object.values(a).filter(e=>e&&!e.isChildren).sort((e,n)=>{var c,l,d,p;return isNaN(Number((c=e==null?void 0:e.data)==null?void 0:c.nroItem))||isNaN(Number((l=n==null?void 0:n.data)==null?void 0:l.nroItem))?(p=e==null?void 0:e.data)==null?void 0:p.nroItem.toLowerCase().localeCompare((d=n==null?void 0:n.data)==null?void 0:d.nroItem.toLowerCase()):Number(e.data.nroItem)-Number(n.data.nroItem)}))}function b(o,r){const i=o.nroItem.split(".").map(u=>parseInt(u,10)),a=r.nroItem.split(".").map(u=>parseInt(u,10)),s=Math.max(i.length,a.length);for(let u=0;u<s;u++){const m=i[u]||0,e=a[u]||0;if(m<e)return-1;if(m>e)return 1}return 0}const w=t.object({nroItem:t.string().trim().min(1),descricao:t.string().trim().min(1),idEstruturaPerPai:t.number().optional().nullable(),volume:t.number().optional().nullable(),tipoEstruturaContrato:t.enum(Object.keys(P)),observacao:t.string().trim().min(1).optional()});function N(o){const r=new Set;let i=!1;o.forEach(s=>{s.volume?r.add(s.volume):i=!0});const a=Array.from(r).map(s=>({label:"Volume "+s,value:s}));return a.length&&i&&a.push({value:"SEM_VOLUME",label:"Sem volume"}),a}function V(o){const r=new Set;for(const i of o)i.idEstruturaPerPai&&r.add(i.idEstruturaPerPai);return o.filter(i=>!r.has(i.id.idEstrutura))}const x=t.object({descricao:t.string().optional().nullable(),faseConcessao:t.string(),periodoInicial:t.coerce.number().min(0),periodoFinal:t.coerce.number().min(0),tipoPeriodo:t.string(),expressao:t.string().optional().nullable(),extensao:t.coerce.number().optional().nullable()}),R=E(Object.keys(v)),S=E(Object.keys(A).map(o=>A[o])),M=E(Object.keys(C).map(o=>C[o])),L=E(Object.keys(h)),D=t.object({descricao:t.string().min(1),idItemContrato:t.coerce.number().min(1),tipoParametro:t.enum(R),grupoAtivo:t.enum(M).optional().nullable(),tipoAtivo:t.enum(S).optional().nullable(),tipoEntrega:t.enum(L)}).superRefine((o,r)=>{!o.grupoAtivo&&!o.tipoAtivo&&(r.addIssue({code:t.ZodIssueCode.custom,path:["grupoAtivo"],message:"Selecione uma opção"}),r.addIssue({code:t.ZodIssueCode.custom,path:["tipoAtivo"],message:"Selecione uma opção"}))});function G(o){const r=f(()=>Array.isArray(o.value)?o.value:o),i=O(),a=O(1),s=f(()=>N(r.value)),u=f(()=>g(r.value,i.value,a.value));return I(s,m=>{var e;a.value=((e=m[0])==null?void 0:e.value)||"SEM_VOLUME"},{immediate:!0}),{volumeSelected:a,volumesAvailable:s,treeData:u,search:i}}export{x as I,k as O,D as P,V as g,w as i,b as s,G as u};
