import{proxyCustomElement as e,HTMLElement as t,createEvent as s,h as i,Host as n,transformTag as a}from"@stencil/core/internal/client";import{E as r}from"./keycodes.js";import{d as o}from"./empty-state.js";const l=e(class extends t{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.cancel=s(this,"cancel",7),this.itemSelected=s(this,"itemSelected",7),this.items=[],this.open=!1,this.isSearching=!1,this.emptyMessage="",this.handleCancel=e=>{e instanceof KeyboardEvent&&e.key!==r||(e.stopPropagation(),e.preventDefault(),this.cancel.emit())},this.selectOnInteract=e=>{e.stopPropagation(),e.preventDefault(),this.itemSelected.emit(e.detail)}}watchOpen(e){!0===e?this.setupHandlers():!1===e&&this.teardownHandlers()}connectedCallback(){this.open&&this.setupHandlers()}disconnectedCallback(){this.teardownHandlers()}setupHandlers(){this.host.addEventListener("keyup",this.handleCancel)}teardownHandlers(){this.host&&this.host.removeEventListener("keyup",this.handleCancel)}render(){return 0===this.items.length?this.isSearching?this.renderSpinner():i(n,{onMouseDown:this.handleMouseDown},i("limebb-empty-state",{value:this.emptyMessage,icon:{name:"search_more",color:"rgb(var(--contrast-800))"}})):i(n,{onMouseDown:this.handleMouseDown},[i("div",null,i("limel-list",{type:"selectable",items:this.getItems(),onInteract:this.selectOnInteract}),i("div",{class:"spinner-in-list"},this.renderSpinner()))])}renderSpinner(){if(this.isSearching)return i("limel-spinner",{size:"small",class:"search-spinner"})}handleMouseDown(e){e.preventDefault()}getItems(){return this.items.map((e=>"separator"in e?e:Object.assign(Object.assign({},e),{disabled:e.disabled||this.isSearching})))}get host(){return this}static get watchers(){return{open:[{watchOpen:0}]}}static get style(){return":host(limebb-text-editor-picker){animation:fade-in 0.3s ease forwards;animation-delay:0.1s;display:block;max-width:calc(100vw - 2rem);padding:0.125rem;border-radius:0.5rem;background-color:rgba(var(--contrast-100));box-shadow:var(--shadow-depth-16);max-height:50vh;overflow-y:auto}limel-menu-list{position:relative}limel-spinner{margin:0 auto}.spinner-in-list{position:absolute;top:50%;left:50%;transform:translate(-50%, -50%)}@keyframes fade-in{0%{opacity:0}100%{opacity:1}}"}},[1,"limebb-text-editor-picker",{items:[16],open:[516],isSearching:[4,"is-searching"],emptyMessage:[1,"empty-message"]},void 0,{open:[{watchOpen:0}]}]);function c(){"undefined"!=typeof customElements&&["limebb-text-editor-picker","limebb-empty-state"].forEach((e=>{switch(e){case"limebb-text-editor-picker":customElements.get(a(e))||customElements.define(a(e),l);break;case"limebb-empty-state":customElements.get(a(e))||o()}}))}export{l as T,c as d}