/*!
 * KoliBri - The accessible HTML-Standard
 */
import{h as t,r as i,F as s}from"./index-Brmny3Vg.js";import{a as e,_ as o}from"./tslib.es6-QNbPBOk5.js";import{b as h}from"./component-names-Dy77vq43.js";import{c as n}from"./clsx-COFh-Vc8.js";import{a,b as l}from"./align-floating-elements-DTTpkCAK.js";import"./common-DEEjER7G.js";import{v as r}from"./inline-D3v7pifU.js";import{b as p}from"./align-ChLoh-Dq.js";import{c}from"./dev.utils-HhhlYW_9.js";import{b as f,e as d,c as v}from"./element-interaction-C5-6aPzz.js";import"./element-focus-BQXzaLL9.js";const m=(t,i)=>{p(t,"_popoverAlign",i)};const u=i=>{const{align:s="bottom",popoverRef:o,arrowRef:h,class:a}=i,l=e(i,["align","popoverRef","arrowRef","class"]);return t("div",Object.assign({},l,{class:n("kol-popover",a),ref:o,popover:"auto"}),t("div",{class:n("kol-popover__arrow",`kol-popover__arrow--${s}`),ref:h}),t("slot",null))};class _{constructor(){this.show=false;this.align="bottom";this.setPopoverElementRef=t=>{this.popoverElement=t;this.arrowElement=t===null||t===void 0?void 0:t.querySelector(".kol-popover__arrow")};this.setTriggerElement=t=>{this.triggerElement=t};this.setAlign=t=>{this.align=t};this.alignPopover=async()=>{if(!this.popoverElement||!this.triggerElement){return}await a({align:this.align,referenceElement:this.triggerElement,arrowElement:this.arrowElement,floatingElement:this.popoverElement})};this.setupAutoUpdate=()=>{if(!this.popoverElement||!this.triggerElement||this.cleanupAutoUpdate){return}this.cleanupAutoUpdate=l(this.triggerElement,this.popoverElement,(()=>{void this.alignPopover()}))}}setShow(t){this.show=t;if(!this.popoverElement){return}const i=()=>{var t;if(!this.popoverElement){return}const i=this.popoverElement.matches(":popover-open");if(this.show){if(!i){try{this.popoverElement.showPopover();this.setupAutoUpdate();void this.alignPopover()}catch(t){}}}else{if(i){try{this.popoverElement.hidePopover();(t=this.cleanupAutoUpdate)===null||t===void 0?void 0:t.call(this);this.cleanupAutoUpdate=undefined}catch(t){}}}};if(this.popoverElement.isConnected){i()}else{requestAnimationFrame((()=>{i()}))}}destroy(){var t;(t=this.cleanupAutoUpdate)===null||t===void 0?void 0:t.call(this);this.cleanupAutoUpdate=undefined;this.popoverElement=undefined;this.arrowElement=undefined;this.triggerElement=undefined}}const b=class{constructor(t){i(this,t);this.ctaRef=v();this.popoverCtrl=new _;this.popoverId=c("popover");this.setPopoverElementRef=t=>{this.popoverElement=t;this.popoverCtrl.setPopoverElementRef(t)};this.setButtonElementRef=t=>{this.ctaRef(t);if(t){this.popoverCtrl.setTriggerElement(t)}};this.on={onClick:()=>{this.popoverCtrl.setShow(!this.popoverOpen)}};this.state={_label:"",_popoverAlign:"bottom",_inline:false};this.popoverOpen=false;this.handleToggle=t=>{this.popoverOpen=t.newState==="open"};this._disabled=false;this._hideLabel=false;this._inline=false;this._popoverAlign="bottom";this._tooltipAlign="top";this._type="button";this._variant="normal"}async hidePopover(){this.popoverCtrl.setShow(false)}async showPopover(){this.popoverCtrl.setShow(true)}async focus(t){}async click(){}render(){return t(s,null,t(h,{key:"9e1a7324de0e3164562d41b81d9b794304508658",class:n("kol-popover-button",{"kol-popover-button--open":this.popoverOpen,"kol-popover-button--inline":this.state._inline===true,"kol-popover-button--standalone":this.state._inline===false}),_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},t("slot",{key:"647d8e36914dd39d3b5ed610051ba0a3fb081052",name:"expert",slot:"expert"})),t(u,{key:"4158958c2efaf7f7bf7c02537e9aa4c45b855c88",align:this.state._popoverAlign||"bottom",popoverRef:this.setPopoverElementRef,class:"kol-popover-button__popover",id:this.popoverId},t("slot",{key:"0cc270905c7835fc7db5119b7609553d86b49050"})))}validateInline(t){r(this,t,{defaultValue:false})}validatePopoverAlign(t){m(this,t);if(t){this.popoverCtrl.setAlign(t)}}componentWillLoad(){this.validateInline(this._inline);this.validatePopoverAlign(this._popoverAlign)}componentDidRender(){if(this.popoverElement){this.popoverElement.addEventListener("toggle",this.handleToggle)}if(this.state._popoverAlign){this.popoverCtrl.setAlign(this.state._popoverAlign)}}disconnectedCallback(){if(this.popoverElement){this.popoverElement.removeEventListener("toggle",this.handleToggle)}this.popoverCtrl.destroy();this.popoverElement=undefined}static get watchers(){return{_inline:["validateInline"],_popoverAlign:["validatePopoverAlign"]}}};o([f("ctaRef")],b.prototype,"focus",null);o([d("ctaRef")],b.prototype,"click",null);export{b as kol_popover_button_wc};
//# sourceMappingURL=kol-popover-button-wc.entry.js.map