var __awaiter=this&&this.__awaiter||function(t,n,e,i){function o(t){return t instanceof e?t:new e((function(n){n(t)}))}return new(e||(e=Promise))((function(e,s){function r(t){try{c(i.next(t))}catch(t){s(t)}}function a(t){try{c(i["throw"](t))}catch(t){s(t)}}function c(t){t.done?e(t.value):o(t.value).then(r,a)}c((i=i.apply(t,n||[])).next())}))};var __generator=this&&this.__generator||function(t,n){var e={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,o,s,r;return r={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(r[Symbol.iterator]=function(){return this}),r;function a(t){return function(n){return c([t,n])}}function c(a){if(i)throw new TypeError("Generator is already executing.");while(r&&(r=0,a[0]&&(e=0)),e)try{if(i=1,o&&(s=a[0]&2?o["return"]:a[0]?o["throw"]||((s=o["return"])&&s.call(o),0):o.next)&&!(s=s.call(o,a[1])).done)return s;if(o=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:e.label++;return{value:a[1],done:false};case 5:e.label++;o=a[1];a=[0];continue;case 7:a=e.ops.pop();e.trys.pop();continue;default:if(!(s=e.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){e.label=a[1];break}if(a[0]===6&&e.label<s[1]){e.label=s[1];s=a;break}if(s&&e.label<s[2]){e.label=s[2];e.ops.push(a);break}if(s[2])e.ops.pop();e.trys.pop();continue}a=n.call(t,e)}catch(t){a=[6,t];o=0}finally{i=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{r as registerInstance,h,H as Host,g as getElement}from"./index-6191c26c.js";import{c as cls}from"./helpers-2fce0c0e.js";import{c as computePosition,f as flip,s as shift,o as offset}from"./floating-ui.dom.esm-6802681c.js";var styleCss="x-dropdown{display:inherit;text-align:inherit}x-dropdown .dropdown-container{display:block;width:-webkit-max-content;width:-moz-max-content;width:max-content;top:0;left:0;position:absolute;z-index:10000;visibility:hidden;opacity:0;-webkit-transition:opacity 0.3s;transition:opacity 0.3s;pointer-events:none}x-dropdown .dropdown-container.dropdown-show{pointer-events:initial;opacity:1;visibility:visible}";var XDropdownStyle0=styleCss;var XDropdown=function(){function t(t){registerInstance(this,t);this.show=false;this.align="bottom";this.hover=false;this.syncWidth=false;this.offset=0}t.prototype.watchAlignAndShow=function(){this.updateDropdownContainer()};t.prototype.componentDidLoad=function(){this.container=this.el.querySelector(".dropdown-container");this.updateDropdownContainer();this.el.addEventListener("mouseenter",this.onMouseEnterOnContainer.bind(this));this.el.addEventListener("mouseleave",this.onMouseLeaveOnContainer.bind(this))};t.prototype.disconectedCallback=function(){if(this.el){this.el.removeEventListener("mouseenter",this.onMouseEnterOnContainer);this.el.removeEventListener("mouseleave",this.onMouseLeaveOnContainer)}};t.prototype.onMouseEnterOnContainer=function(){if(this.hover){this.show=true}};t.prototype.onMouseLeaveOnContainer=function(){if(this.hover){this.show=false}};t.prototype.updateDropdownContainer=function(){var t=this;if(this.syncWidth){this.container.style.maxWidth="".concat(this.el.offsetWidth,"px");this.container.style.width="100%"}else{this.container.style.maxWidth="auto";this.container.style.width="auto"}setTimeout((function(){computePosition(t.el,t.container,{placement:t.align,middleware:[flip(),shift({padding:10}),offset(t.offset)]}).then((function(n){var e=n.x,i=n.y;t.container.style.left="".concat(e,"px");t.container.style.top="".concat(i,"px")}))}),50)};t.prototype.display=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(n){this.show=t;return[2]}))}))};t.prototype.render=function(){return h(Host,{key:"48df29d08ae8077798b586c71443872e1894f0bf"},h("slot",{key:"4c623391741dfad19c2e61e20a57327f0ca13c92"}),h("div",{key:"2d058e90c91481f871c41354c964ce87975e7732",class:cls("dropdown-container",{"dropdown-show":this.show,"dropdown-hover":this.hover})},h("slot",{key:"71cc31936e0aefa2fd1570ede53838f1278139ff",name:"dropdown"})))};Object.defineProperty(t.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{align:["watchAlignAndShow"],show:["watchAlignAndShow"]}},enumerable:false,configurable:true});return t}();XDropdown.style=XDropdownStyle0;export{XDropdown as x_dropdown};