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.placement="top",this.top=-1e4,this.left=-1e4}componentDidRender(){this.handleWindowScroll()}handleWindowScroll(){if(!this.open)return;if(!this.tooltip)return;const t=this.tooltip.getBoundingClientRect(),e=this.el.getBoundingClientRect();let i,o;"bottom"===this.placement?(i=e.bottom+this.padding,o=e.left+e.width/2-t.width/2):"left"===this.placement?(i=e.top+e.height/2-t.height/2,o=e.left-t.width-this.padding):"right"===this.placement?(i=e.top+e.height/2-t.height/2,o=e.right+this.padding):(i=e.top-(t.height+this.padding),o=e.left+e.width/2-t.width/2+this.padding);const r=document.documentElement.clientWidth-t.width-8;"top"!==this.placement&&"bottom"!==this.placement||(o>r?o=e.right-t.width:o<8&&(o=e.left)),this.top=i,this.left=Math.min(Math.max(o,8),Math.max(r,8))}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--dark":"dark"===this.type,"tooltip--top":"top"===this.placement,"tooltip--bottom":"bottom"===this.placement,"tooltip--left":"left"===this.placement,"tooltip--right":"right"===this.placement,"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' | 'dark'",resolved:'"danger" | "dark" | "info" | "primary" | "success" | "text" | "warning"',references:{}},required:!1,optional:!1,docs:{tags:[],text:'The tooltip\'s type.\n\n- `info` (default) — current SureCart blue/info style with a colored arrow.\n- `primary`/`success`/`warning`/`danger` — accent-colored variants.\n- `text` — legacy passthrough used by long-form tooltips.\n- `dark` — flat black background with white text, matching the\n  WordPress admin button tooltip ("View options"-style). No colored\n  accent, no arrow, no padding flourish — just the WP look.'},attribute:"type",reflect:!0,defaultValue:"'info'"},placement:{type:"string",mutable:!1,complexType:{original:"'top' | 'bottom' | 'left' | 'right'",resolved:'"bottom" | "left" | "right" | "top"',references:{}},required:!1,optional:!1,docs:{tags:[],text:"The tooltip's placement relative to the trigger."},attribute:"placement",reflect:!0,defaultValue:"'top'"}}}static get states(){return{top:{},left:{}}}static get elementRef(){return"el"}static get listeners(){return[{name:"scroll",method:"handleWindowScroll",target:"window",capture:!1,passive:!0},{name:"resize",method:"handleWindowScroll",target:"window",capture:!1,passive:!0}]}}