import{r as p,h as o,e as a,F as h}from"./index-B6uGkrgD.js";import{_ as v}from"./tslib.es6-CxX45GIN-BGVaTf34.js";import{c as l}from"./clsx-COFh-Vc8-D7cYsJM5.js";import{a as d,b as c}from"./align-floating-elements-DGbaInbL-CkTB7_ga.js";import{v as _}from"./inline-q8GZVjiZ-Ct3pP0fI.js";import{a as m}from"./align-DDUsWnWP-DSgjqBHS.js";import{n as f}from"./dev.utils-98sTB6ui-O8z9q0jz.js";import{s as g}from"./element-focus-y2O-Z32P-C32vUDP9.js";const u=(t,e)=>{m(t,"_popoverAlign",e)},b=t=>{const{align:e="bottom",popoverRef:s,arrowRef:i,class:n}=t,r=v(t,["align","popoverRef","arrowRef","class"]);return o("div",Object.assign({},r,{class:l("kol-popover",n),ref:s,popover:"auto"}),o("div",{class:l("kol-popover__arrow",`kol-popover__arrow--${e}`),ref:i}),o("slot",null))};class E{constructor(){this.show=!1,this.align="bottom",this.setPopoverElementRef=e=>{this.popoverElement=e,this.arrowElement=e?.querySelector(".kol-popover__arrow")},this.setTriggerElement=e=>{this.triggerElement=e},this.setAlign=e=>{this.align=e},this.alignPopover=async()=>{!this.popoverElement||!this.triggerElement||await d({align:this.align,referenceElement:this.triggerElement,arrowElement:this.arrowElement,floatingElement:this.popoverElement})},this.setupAutoUpdate=()=>{!this.popoverElement||!this.triggerElement||this.cleanupAutoUpdate||(this.cleanupAutoUpdate=c(this.triggerElement,this.popoverElement,()=>{this.alignPopover()}))}}setShow(e){if(this.show=e,!this.popoverElement)return;const s=()=>{var i;if(!this.popoverElement)return;const n=this.popoverElement.matches(":popover-open");if(this.show){if(!n)try{this.popoverElement.showPopover(),this.setupAutoUpdate(),this.alignPopover()}catch{}}else if(n)try{this.popoverElement.hidePopover(),(i=this.cleanupAutoUpdate)===null||i===void 0||i.call(this),this.cleanupAutoUpdate=void 0}catch{}};this.popoverElement.isConnected?s():requestAnimationFrame(()=>{s()})}destroy(){var e;(e=this.cleanupAutoUpdate)===null||e===void 0||e.call(this),this.cleanupAutoUpdate=void 0,this.popoverElement=void 0,this.arrowElement=void 0,this.triggerElement=void 0}}const U=class{constructor(t){p(this,t),this.popoverCtrl=new E,this.popoverId=`popover-${f()}`,this.setPopoverElementRef=e=>{this.popoverElement=e,this.popoverCtrl.setPopoverElementRef(e)},this.setButtonElementRef=e=>{this.refButton=e,e&&this.popoverCtrl.setTriggerElement(e)},this.on={onClick:()=>{this.popoverCtrl.setShow(!this.popoverOpen)}},this.state={_label:"",_popoverAlign:"bottom",_inline:!1},this.popoverOpen=!1,this.handleToggle=e=>{this.popoverOpen=e.newState==="open"},this._disabled=!1,this._hideLabel=!1,this._inline=!1,this._popoverAlign="bottom",this._tooltipAlign="top",this._type="button",this._variant="normal"}async hidePopover(){this.popoverCtrl.setShow(!1)}async showPopover(){this.popoverCtrl.setShow(!0)}async focus(){return g(this.refButton)}render(){return o(h,null,o(a,{key:"88e4a778fbf3d32fbee36106fddb8e64ac7b3495",class:l("kol-popover-button",{"kol-popover-button--open":this.popoverOpen,"kol-popover-button--inline":this.state._inline===!0,"kol-popover-button--standalone":this.state._inline===!1}),_accessKey:this._accessKey,_ariaControls:this.popoverId,_ariaDescription:this._ariaDescription,_ariaExpanded:this.popoverOpen,_customClass:this._customClass,_disabled:this._disabled,_hideLabel:this._hideLabel,_icons:this._icons,_id:this._id,_inline:this._inline,_label:this._label,_name:this._name,_on:this.on,_shortKey:this._shortKey,_syncValueBySelector:this._syncValueBySelector,_tabIndex:this._tabIndex,_tooltipAlign:this._tooltipAlign,_type:this._type,_value:this._value,_variant:this._variant,ref:this.setButtonElementRef},o("slot",{key:"a64d7ddf1ea8a6b1f536e723f2bb61cb17f4cfab",name:"expert",slot:"expert"})),o(b,{key:"b717fa3c67316c1f4f58c6473853b2ea6e003436",align:this.state._popoverAlign||"bottom",popoverRef:this.setPopoverElementRef,class:"kol-popover-button__popover",id:this.popoverId},o("slot",{key:"aa0a7a1750a3bb4731d724d5d3294a44ec14a15b"})))}validateInline(t){_(this,t,{defaultValue:!1})}validatePopoverAlign(t){u(this,t),t&&this.popoverCtrl.setAlign(t)}componentWillLoad(){this.validateInline(this._inline),this.validatePopoverAlign(this._popoverAlign)}componentDidRender(){this.popoverElement&&this.popoverElement.addEventListener("toggle",this.handleToggle),this.state._popoverAlign&&this.popoverCtrl.setAlign(this.state._popoverAlign)}disconnectedCallback(){this.popoverElement&&this.popoverElement.removeEventListener("toggle",this.handleToggle),this.popoverCtrl.destroy(),this.popoverElement=void 0}static get watchers(){return{_inline:["validateInline"],_popoverAlign:["validatePopoverAlign"]}}};export{U as kol_popover_button_wc};
//# sourceMappingURL=kol-popover-button-wc.entry-D4zQtTLO.js.map
