import{ref as h,onMounted as x,watch as A,createElementBlock as m,openBlock as k,createVNode as M,Transition as N,withCtx as T,withDirectives as S,createElementVNode as C,vShow as P,unref as B}from"/vue.js";const O={class:"nc-svg-map"},$={id:"nc-svg-map-tooltip"},H=Object.assign({name:"NcSvgMap"},{__name:"nc-svg-map",props:{svg:{type:String,required:!0},highlight:{type:Array,default:()=>[]},hover:{type:Array,default:()=>[]}},emits:["update:hover","click","dblclick"],setup(E,{emit:_}){console.time("* nc-svg-map time");const o=_,r=E;let g=h(null),l=h(!1),i;x(async()=>{const t=r.svg;if(!t){console.error(`🚀 ~ nc-svg-map onMounted ~ svgPath does not exist: '${t}'`);return}let e=await fetch(t);if(!e.ok){console.error(`🚀 ~ nc-svg-map onMounted ~ svg '${t} fetch(svgPath), res.ok:`,e.ok);return}if(i=await e.text(),!(i.startsWith("<?xml ")||i.startsWith("<svg "))||!i.includes("</svg>")){console.error(`🚀 ~ nc-svg-map onMounted ~ svg '${t} is not valid, fetch result: `,i,e);return}const s=g.value;s&&(s.innerHTML=i),setTimeout(()=>{f(s),c(s)},200),A(()=>r.highlight,n=>{c(s)},{deep:!0}),console.timeEnd("* nc-svg-map time")});function a(t){if(t.hasAttribute&&t.hasAttribute("id"))return t.getAttribute("id");if(t.parentNode?.hasAttribute&&t.parentNode.hasAttribute("id"))return t.parentNode.getAttribute("id")}function v(t,e){t.classList?t.classList.add(e):t.class=e}function d(t,e){t.classList&&t.classList.remove(e)}function c(t){if(!t)return;var e=t.childNodes;for(let n=0;n<e.length;n++)c(e[n]);const s=a(t);s&&(r.highlight?.includes(s)?v(t,"svg-map-selected"):t.classList&&d(t,"svg-map-selected"))}function L(t,e){const s=document.getElementById("nc-svg-map-tooltip");s.innerHTML=e,s.style.left=t.pageX+-60+"px",s.style.top=t.pageY+-60+"px",l.value=!0}function b(){l.value=!1}function w(t){const e=a(t.target);e!=null&&(L(t,e),v(t.target,"svg-map-hover"),o("update:hover",[...r.hover,e]))}function y(t){const e=a(t.target);e!=null&&(b(),d(t.target,"svg-map-hover"),o("update:hover",r.hover.filter(s=>s!==e)))}function p(t,e){const s=a(t.target);t.preventDefault(),t.stopPropagation(),o(e,{id:s,event:t})}function f(t){for(var e=t.childNodes,s=0;s<e.length;s++)f(e[s]);a(t)&&(t.addEventListener("mouseover",w),t.addEventListener("mouseout",y),t.addEventListener("click",u=>p(u,"click")),t.addEventListener("dblclick",u=>p(u,"dblclick")))}return(t,e)=>(k(),m("div",O,[(k(),m("svg",{class:"nc-svg-map-svg",ref_key:"mapElem",ref:g},null,512)),M(N,{name:"nc-fade-fast"},{default:T(()=>[S(C("div",$,null,512),[[P,B(l)]])]),_:1})]))}});export{H as default};
