import{h}from"@stencil/core";export class ScTooltip{constructor(){this.open=void 0,this.width=void 0,this.text=void 0,this.freeze=void 0,this.padding=5,this.type="info",this.top=-1e4,this.left=-1e4}componentDidLoad(){this.handleWindowScroll()}handleWindowScroll(){if(!this.open)return;if(!this.tooltip)return;var t=this.tooltip.getBoundingClientRect(),e=this.el.getBoundingClientRect();this.top=e.top-(t.height+this.padding);const i=Math.max(e.left+e.width/2-t.width/2+this.padding,0);this.left=Math.min(i,window.innerWidth-t.width)}handleOpenChange(){setTimeout((()=>this.handleWindowScroll()),0)}handleBlur(){this.freeze||(this.open=!1)}handleClick(){this.freeze||(this.open=!0)}handleFocus(){this.freeze||(this.open=!0)}handleMouseOver(){this.freeze||(this.open=!0)}handleMouseOut(){this.freeze||(this.open=!1)}render(){return this.text?h("span",{part:"base",class:{tooltip:!0,"tooltip--primary":"primary"===this.type,"tooltip--success":"success"===this.type,"tooltip--info":"info"===this.type,"tooltip--warning":"warning"===this.type,"tooltip--danger":"danger"===this.type,"tooltip--has-width":!!this.width},onClick:()=>this.handleClick(),onBlur:()=>this.handleBlur(),onFocus:()=>this.handleFocus(),onMouseOver:()=>this.handleMouseOver(),onMouseOut:()=>this.handleMouseOut()},h("slot",null),!!this.open&&h("div",{part:"text",ref:t=>this.tooltip=t,class:"tooltip-text",style:{top:`${this.top}px`,left:`${this.left}px`,...this.width?{"--sc-tooltip-width":this.width}:{}}},this.text)):h("slot",null)}static get is(){return"sc-tooltip"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-tooltip.scss"]}}static get styleUrls(){return{$:["sc-tooltip.css"]}}static get properties(){return{open:{type:"boolean",mutable:!0,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Open or not"},attribute:"open",reflect:!1},width:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Tooltip fixed width"},attribute:"width",reflect:!1},text:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Tooltip text"},attribute:"text",reflect:!1},freeze:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Freeze open or closed."},attribute:"freeze",reflect:!1},padding:{type:"number",mutable:!1,complexType:{original:"number",resolved:"number",references:{}},required:!1,optional:!1,docs:{tags:[],text:"The tooltip's padding."},attribute:"padding",reflect:!1,defaultValue:"5"},type:{type:"string",mutable:!1,complexType:{original:"'primary' | 'success' | 'info' | 'warning' | 'danger' | 'text'",resolved:'"danger" | "info" | "primary" | "success" | "text" | "warning"',references:{}},required:!1,optional:!1,docs:{tags:[],text:"The tooltip's type."},attribute:"type",reflect:!0,defaultValue:"'info'"}}}static get states(){return{top:{},left:{}}}static get elementRef(){return"el"}static get watchers(){return[{propName:"open",methodName:"handleOpenChange"}]}static get listeners(){return[{name:"scroll",method:"handleWindowScroll",target:"window",capture:!1,passive:!0},{name:"resize",method:"handleWindowScroll",target:"window",capture:!1,passive:!0}]}}