let treeParams,pathNumber=1,allLinks=[],strokeWidth="5px",strokeColor="#000000";function treeMaker(t,e){let r=document.getElementById(e.id);treeParams=void 0===e.treeParams?{}:e.treeParams,void 0!==e.link_width&&(strokeWidth=e.link_width),void 0!==e.link_color&&(strokeColor=e.link_color),pathNumber=1,allLinks=[];const n=document.createElement("div");n.id="tree__svg-container",r.appendChild(n);const s=document.createElementNS("http://www.w3.org/2000/svg","svg");s.id="tree__svg-container__svg",n.appendChild(s);const o=document.createElement("div");o.id="tree__container",r.appendChild(o);const i=document.createElement("div");i.classList="tree__container__step__card",i.id="tree__container__step__card__first",o.appendChild(i);const a=void 0!==treeParams[Object.keys(t)[0]]&&void 0!==treeParams[Object.keys(t)[0]].trad?treeParams[Object.keys(t)[0]].trad:Object.keys(t)[0].trad;i.innerHTML=`<p class="tree__container__step__card__p" id="card_${Object.keys(t)[0]}">${a}</p>`,addStyleToCard(treeParams[Object.keys(t)[0]],Object.keys(t)[0]),iterate(t[Object.keys(t)[0]],!0,"tree__container__step__card__first"),connectCard(),document.querySelectorAll(".tree__container__step__card__p").forEach(t=>{t.addEventListener("click",function(t){"function"==typeof e.card_click&&e.card_click(t.target)})}),window.onresize=function(){n.setAttribute("height","0"),n.setAttribute("width","0"),connectCard()}}function connectCard(){const t=document.getElementById("tree__svg-container__svg");for(let e=0;allLinks.length>e;e++)connectElements(t,document.getElementById(allLinks[e][0]),document.getElementById(allLinks[e][1]),document.getElementById(allLinks[e][2]))}function iterate(t,e,r){const n=document.getElementById("tree__svg-container__svg"),s=document.createElement("div");s.classList.add("tree__container__branch",`from_${r}`),document.getElementById(r).after(s);for(const o in t){const i=void 0!==treeParams[o]&&void 0!==treeParams[o].trad?treeParams[o].trad:o;if(document.getElementById(`card_${o}`)||(s.innerHTML+=`<div class="tree__container__step"><div class="tree__container__step__card" id="${o}"><p id="card_${o}" class="tree__container__step__card__p">${i}</p></div></div>`,addStyleToCard(treeParams[o],o)),r&&!e||e){const t=document.createElementNS("http://www.w3.org/2000/svg","path");t.id="path"+pathNumber,t.setAttribute("stroke",strokeColor),t.setAttribute("fill","none"),t.setAttribute("stroke-width",strokeWidth),n.appendChild(t),allLinks.push(["path"+pathNumber,r||"tree__container__step__card__first",o]),pathNumber++}Object.keys(t[o]).length>0&&iterate(t[o],!1,o)}}function addStyleToCard(t,e){if(void 0!==t&&void 0!==t.styles){let r=document.getElementById("card_"+e);for(const n in treeParams[e].styles)r.style[n]=t.styles[n]}}function signum(t){return t<0?-1:1}function absolute(t){return t<0?-t:t}function drawPath(t,e,r,n,s,o){let i=parseFloat(e.getAttribute("stroke-width"));t.getAttribute("height")<o&&t.setAttribute("height",o),t.getAttribute("width")<r+i&&t.setAttribute("width",r+i),t.getAttribute("width")<s+i&&t.setAttribute("width",s+i);let a=.15*(s-r),d=.15*(o-n),c=d<absolute(a)?d:absolute(a),_=0,l=1;r>s&&(_=1,l=0),e.setAttribute("d","M"+r+" "+n+" V"+(n+c)+" A"+c+" "+c+" 0 0 "+_+" "+(r+c*signum(a))+" "+(n+2*c)+" H"+(s-c*signum(a))+" A"+c+" "+c+" 0 0 "+l+" "+s+" "+(n+3*c)+" V"+o)}function connectElements(t,e,r,n){const s=document.getElementById("tree__svg-container");if(r.offsetTop>n.offsetTop){const t=r;r=n,n=t}const o=s.offsetTop,i=s.offsetLeft;drawPath(t,e,r.offsetLeft+.5*r.offsetWidth-i,r.offsetTop+r.offsetHeight-o,n.offsetLeft+.5*n.offsetWidth-i,n.offsetTop-o)}