import{a as e,i as t,n,o as r,r as i,t as a}from"./vendor-CErFFJO6.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var o=document.getElementById(`cyoa-upload`),s=document.getElementById(`search-bar`),c=document.getElementById(`search-results`);function l(e){return e.addonParent!==void 0}function u(e){return e.addons!==void 0}var d={};async function f(e){let t=await e.text(),n=JSON.parse(t);d={};for(let e of n.rows){d[e.id]={id:e.id,title:e.title,text:e.titleText,requireds:e.requireds,isRow:!0};for(let t of e.objects){d[t.id]=t;for(let e of t.addons)d[e.id]={...e,addonParent:t.id}}}m(s.value)}var p=``;async function m(e){if(e==p)return;let t=document.createElement(`form`);c.replaceWith(t),c=t;let n=Object.values(d).filter(t=>t.id===e||t.title.toLowerCase().includes(e.toLowerCase()));if(n.length===0)t.append(`No Results`);else if(n.length===1)t.append(`One Result: `+n[0].title),h(n[0].id);else{t.addEventListener(`click`,()=>h(t.elements.namedItem(`result-radio`).value));let e=document.createElement(`fieldset`);e.setAttribute(`id`,`results`),t.appendChild(e);let r=document.createElement(`legend`);r.append(`Search Results`),e.appendChild(r);for(let t of n){let n=document.createElement(`div`);n.setAttribute(`id`,`result-`+t.id),e.appendChild(n);let r=document.createElement(`input`);r.setAttribute(`type`,`radio`),r.setAttribute(`id`,`result-radio-`+t.id),r.setAttribute(`name`,`result-radio`),r.setAttribute(`value`,t.id),n.appendChild(r);let i=document.createElement(`label`);i.setAttribute(`for`,`result-radio-`+t.id),i.append(`${l(t)?`(Addon) `:``}${t.title}`),n.appendChild(i)}}}async function h(o){let s=new r(`G`,{size:`18,50`}),c=new i(`A`);s.addSubgraph(c);let f={},p=[o];for(;p.length>0;){let e=[],n=p.shift(),r=d[n];if(d[n]===void 0&&console.log(n,d[n]),f[r.id])continue;let i=new t(r.id,{label:r.title,tooltip:`id: ${r.id}`,shape:u(r)?`rectangle`:`invhouse`,fontname:`inherit`});c.addNode(i);for(let t of r.requireds)if(t.required!==!1){if(t.type==`id`)p.push(t.reqId),e.push({type:`id`,id:t.reqId});else if(t.type==`or`){let n=[];for(let e of t.orRequired)e.req!==``&&(p.push(e.req),n.push(e.req));e.push({type:`or`,ids:n})}}l(r)&&(p.push(r.addonParent),e.push({type:`id`,id:r.addonParent})),f[r.id]={id:r.id,title:r.title,text:r.text,deps:e,node:i}}let m=0;for(let n of Object.values(f))for(let r of n.deps)if(r.type==`id`){let t=new e([n.node,f[r.id]]);c.addEdge(t)}else if(r.type==`or`){let i=new t(`or-`+m,{label:`Or`,tooltip:`Only one of the selected options needs to be chosen.`,shape:`diamond`,fixedsize:!0,width:.25,height:.25,fontsize:10});m++,c.addNode(i);let a=new e([n.node,i]);c.addEdge(a);for(let t of r.ids){let n=new e([i,f[t]]);c.addEdge(n)}}let h=n(s),g=(await a()).renderSVGElement(h,{engine:`dot`,graphAttributes:{tooltip:`Dependency Graph`}});g.setAttribute(`id`,`render`),document.getElementById(`render`).replaceWith(g),console.log(d.j4fl)}o.addEventListener(`change`,async()=>{let e=o.files[0];e!==void 0&&await f(e)}),o.files[0]&&f(o.files[0]),document.getElementById(`search-button`).addEventListener(`click`,async()=>await m(s.value)),s.addEventListener(`change`,async e=>await m(s.value));