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