import{k,a4 as y,ad as h,ae as $}from"./index-B-YXshIJ.js";import{l as f}from"./utils-DWxAE1Fn.js";const m=e=>n=>e.path===n.path&&e.method===n.method&&e.specId===n.specId&&e.serviceId===n.serviceId,T=e=>h("serviceId",e.serviceId),I=e=>e==="GET"?"bg-blue-400":e==="DELETE"?"bg-red-500":e==="PUT"?"bg-yellow-400":"bg-green-500",b=e=>n=>'\n    <li class="mb-1">\n      <span class="'.concat(I(n.method),' w-12 text-theme-base px-1 rounded inline-block mr-2 text-xs font-bold text-center">\n        ').concat(n.method,"\n      </span>\n      ").concat(n.path,"\n      ").concat(e(n)?"":'<span class="text-theme-base-inverted ml-2 inline-block uppercase text-xs bg-slate-600 rounded px-1 py-0.5">Unused</span>',"\n    </li>\n  "),u=e=>'\n    <div class="flex items-center gap-2">\n      <span class="inline-block w-1 h-4" style="background: '.concat(f(e.serviceId),'"> </span>\n      <span class="font-medium">').concat(e.name,"</span>\n    </div>\n  "),E=(e,n)=>{var o;if(!e)return"Unknown";const r=((o=n.serviceTypes.http)==null?void 0:o.dependsOn.filter(a=>a.serviceId===e.serviceId))||[];return"\n    <div>\n      <div>\n        Provider\n        ".concat(u(e),'\n      </div>\n      <div class="mt-2">\n        Consumer\n        ').concat(u(n),'\n      </div>\n      <div class="mt-2">\n        <strong>').concat(y(r.length,"Endpoint","Endpoints")," used:</strong>\n        <ul>\n          ").concat(r.map(b($)).join(""),"\n        </ul>\n      </div>\n    </div>\n  ")},l=(e,n)=>e.length?n:"",O=e=>n=>{var a,d,p,c,i,t;const r=e.consumers(n),o=e.providers(n);return'\n    <div class="flex items-center gap-2 text-lg font-medium">\n      <span class="inline-block w-2 h-2" style="background: '.concat(f(n.serviceId),'"> </span>\n      ').concat(n.name,"\n    </div>\n    ").concat(l(r,'<div class="mt-3">\n        <strong>Used by</strong>\n        <ul>\n          '.concat(r.map(u).join(""),"\n        </ul>\n      </div>")),"\n    ").concat(l(((a=n.serviceTypes.http)==null?void 0:a.endpoints)||[],'<div class="mt-3">\n        <strong>Exposes</strong>\n        <ul>\n          '.concat((d=n.serviceTypes.http)==null?void 0:d.endpoints.map(b(e.isEndpointUsed)).join(""),"\n        </ul>\n      </div>")),"\n    ").concat(l(o,'<div class="mt-3">\n        <strong>Depends on</strong>\n        <ul>\n          '.concat(o.map(u).join(""),"\n        </ul>\n      </div>")),"\n    ").concat(l((((p=n.serviceTypes.kafka)==null?void 0:p.channels)||[]).filter(s=>s.type==="subscribe"),'<div class="mt-3">\n        <strong>Subscribes to</strong>\n        <ul>\n          '.concat((c=n.serviceTypes.kafka)==null?void 0:c.channels.filter(s=>s.type==="subscribe").map(s=>"<li>Kafka: ".concat(s.name,"</li>")).join(""),"\n        </ul>\n      </div>")),"\n    ").concat(l((((i=n.serviceTypes.kafka)==null?void 0:i.channels)||[]).filter(s=>s.type==="publish"),'<div class="mt-3">\n        <strong>Publishes to</strong>\n        <ul>\n          '.concat((t=n.serviceTypes.kafka)==null?void 0:t.channels.filter(s=>s.type==="publish").map(s=>"<li>Kafka: ".concat(s.name,"</li>")).join(""),"\n        </ul>\n      </div>")),"\n    ")},j=e=>'\n    <div>\n      <div class="mb-2">\n        <strong>'.concat(e.name,"</strong>\n      </div>\n      ").concat(e.isPublisher?"<div>Publishing to this queue</div>":"","\n      ").concat(e.isSubscriber?"<div>Subscribing to this queue</div>":"","\n    </div>\n  "),S=e=>{const n=i=>e.filter(t=>{var s;return(s=i.serviceTypes.http)==null?void 0:s.dependsOn.some(T(t))}),r=i=>e.filter(t=>{var s;return(s=i.serviceTypes.http)==null?void 0:s.endpoints.some(g=>{var v;return(v=t.serviceTypes.http)==null?void 0:v.dependsOn.some(m(g))})}),o=k(Object.entries(e.reduce((i,t)=>(t.serviceTypes.kafka&&t.serviceTypes.kafka.channels.forEach(s=>{i[s.name]=t}),i),{})).map(([i,t])=>({name:i,service:t}))),a=i=>i.serviceTypes.kafka?Object.entries(i.serviceTypes.kafka.channels.reduce((t,s)=>(t[s.name]=t[s.name]||{},s.type==="subscribe"&&(t[s.name].isSubscriber=!0),s.type==="publish"&&(t[s.name].isPublisher=!0),t),{})).map(([t,s])=>({name:t,...s})):null,d=i=>e.some(t=>{var s;return(s=t.serviceTypes.http)==null?void 0:s.dependsOn.some(m(i))}),p=i=>e.filter(t=>{var s;return(s=t.serviceTypes.http)==null?void 0:s.dependsOn.some(m(i))}),c=i=>e.find(h("serviceId",i));return{providers:n,consumers:r,kafkaQueues:a,consumersOfEndpoint:p,isEndpointUsed:d,connectionTooltip:E,serviceTooltip:O({providers:n,consumers:r,isEndpointUsed:d}),kafkaQueueTooltip:j,serviceById:c,allKafkaTopics:o}},w=()=>Math.random().toString(36).slice(2,11),U=e=>e.reduce((n,r)=>(n.set(r,w()),n),new Map);export{U as g,I as m,S as s};
