import{r as e}from"./rolldown-runtime-CMxvf4Kt.mjs";import{F as t,M as n,d as r,f as i,k as a,m as o,p as s,t as c,u as l}from"./design-system-components-Y2tugS6v.mjs";import{t as u}from"./applyCustomProp-Dj0PE6ai.mjs";import{t as d}from"./translations-YGcDE8uS.mjs";var f=new WeakMap,p=async e=>{let t=f.get(e);if(!t||t.tooltipEl)return;let n=document.createElement(`div`);n.setAttribute(`role`,`tooltip`);let a=document.createElement(`span`);a.classList.add(`oc-tooltip-content`),a.textContent=t.content,n.appendChild(a);let c=document.createElement(`div`);c.classList.add(`arrow`),n.appendChild(c),document.body.appendChild(n),t.tooltipEl=n;let{x:u,y:d,placement:p,middlewareData:m}=await r(e,n,{placement:`top`,middleware:[s(8),i(),o({padding:5}),l({element:c})]});if(Object.assign(n.style,{left:`${u}px`,top:`${d}px`}),m.arrow){let{x:e,y:t}=m.arrow,n=p.split(`-`)[0];Object.assign(c.style,{left:e==null?``:`${e}px`,top:t==null?``:`${t}px`,[{top:`bottom`,right:`left`,bottom:`top`,left:`right`}[n]]:`-4px`})}},m=e=>{let t=f.get(e);!t||!t.tooltipEl||(t.tooltipEl.remove(),t.tooltipEl=null)},h=e=>{let t=f.get(e);t&&(m(e),e.removeEventListener(`mouseenter`,t.showHandler),e.removeEventListener(`focus`,t.showHandler),e.removeEventListener(`mouseleave`,t.hideHandler),e.removeEventListener(`blur`,t.hideHandler),e.removeEventListener(`click`,t.clickHandler),document.removeEventListener(`keydown`,t.escapeHandler),f.delete(e))},g=(e,{value:t})=>{if(!t||t===``){h(e);return}let n=f.get(e);if(n){if(n.content=t,n.tooltipEl){let e=n.tooltipEl.querySelector(`.oc-tooltip-content`);e&&(e.textContent=t)}return}let r=()=>p(e),i=()=>m(e),a=()=>m(e),o=t=>{t.code===`Escape`&&m(e)};f.set(e,{content:t,tooltipEl:null,showHandler:r,hideHandler:i,clickHandler:a,escapeHandler:o}),e.addEventListener(`mouseenter`,r),e.addEventListener(`mouseleave`,i),e.addEventListener(`focus`,r),e.addEventListener(`blur`,i),e.addEventListener(`click`,a),document.addEventListener(`keydown`,o)},_={name:`OcTooltip`,beforeMount:g,updated:g,unmounted:h},v=e({OcTooltip:()=>_}),y=null,b=(e,n)=>{for(let r in e)u(n+t(r),e[r])},x={install(e,t={}){a(t.iconUrlPrefix||``),t?.language?.initGettext&&(y=n({defaultLanguage:t.language.defaultLanguage||`en`,silent:!0,translations:{...d,...t.language.translations||{}}}),e.use(y));let r=t.tokens;b(r?.colorPalette,`color-`),b(r?.roles,`role-`),u(`font-family`,r?.fontFamily),r?.roles?.chrome||(u(`role-chrome`,r?.roles?.surfaceContainer),u(`role-on-chrome`,r?.roles?.onSurface)),Object.values(c).forEach(t=>e.component(t.__name,t)),Object.values(v).forEach(t=>e.directive(t.name,t))}};export{x as default};