import{proxyCustomElement as t,HTMLElement as i,createEvent as e,h as s,transformTag as o}from"@stencil/core/internal/client";import{b as n}from"./index.esm.js";const l=t(class extends i{constructor(t){super(),!1!==t&&this.__registerHost(),this.__attachShadow(),this.change=e(this,"change",7),this.copy=e(this,"copy",7),this.type="component",this.copyLabel="Copy value",this.hideCopyButton=!1,this.allItems=[],this.getConfigs=()=>({component:()=>this.webComponentRegistry.getAll(),command:()=>this.commandbus.getAll()}[this.type]()),this.getConfigValue=t=>"name"in t&&"string"==typeof t.name?t.name:"id"in t&&"string"==typeof t.id?t.id:"",this.hasTag=t=>!this.tags||this.tags.some((i=>{var e;return null===(e=t.tags)||void 0===e?void 0:e.includes(i)})),this.handleBlur=()=>{this.emitIfValidValue(this.currentInput)},this.handleChange=t=>{var i;t.stopPropagation(),this.change.emit(null===(i=t.detail)||void 0===i?void 0:i.value)},this.handleCopyButton=()=>{navigator.clipboard.writeText(this.value),this.copy.emit(this.value)},this.handleKeyUp=t=>{"Enter"===t.key&&this.emitIfValidValue(this.currentInput)},this.emitIfValidValue=t=>{this.isValidIdentifier(t)&&this.change.emit(t)},this.isValidIdentifier=t=>!!t&&("component"===this.type?!!customElements.get(t):this.allItems.some((i=>i.value===t))),this.renderPicker=()=>{let t=this.allItems.find((t=>this.value===t.value));return!t&&this.value&&(t={text:this.value,value:this.value,icon:{name:"question",color:"rgb(var(--color-glaucous-light))"}}),s("limel-picker",{disabled:this.disabled,helperText:this.helperText,label:this.label,readonly:this.readonly,required:this.required,searcher:this.search,value:t,title:null==t?void 0:t.text,onBlur:this.handleBlur,onChange:this.handleChange,onKeyUp:this.handleKeyUp})},this.renderCopyButton=()=>{if(!this.hideCopyButton)return s("limel-icon-button",{icon:"copy",disabled:!this.value,label:this.copyLabel,onClick:this.handleCopyButton})},this.search=async t=>t?this.allItems.filter(this.isItemMatching(t.toLocaleLowerCase())):this.allItems,this.isItemMatching=t=>i=>t.split(/\s+/).every((t=>{var e,s;return i.text.toLocaleLowerCase().includes(t)||(null===(e=i.secondaryText)||void 0===e?void 0:e.toLocaleLowerCase().includes(t))||(null===(s=i.value)||void 0===s?void 0:s.toLocaleLowerCase().includes(t))}))}componentWillLoad(){this.allItems=this.getConfigs().filter(this.hasTag).map((t=>{var i,e;return{value:this.getConfigValue(t),text:this.translator.get(null!==(i=t.title)&&void 0!==i?i:this.getConfigValue(t)),secondaryText:this.translator.get(null!==(e=t.description)&&void 0!==e?e:""),icon:t.icon}})).sort(((t,i)=>t.text.localeCompare(i.text)))}render(){return[this.renderPicker(),this.renderCopyButton()]}get currentInput(){var t,i,e,s,o,n,l;return null!==(l=null===(n=null===(o=null===(s=null===(e=null===(i=null===(t=this.host.shadowRoot)||void 0===t?void 0:t.querySelector("limel-picker"))||void 0===i?void 0:i.shadowRoot)||void 0===e?void 0:e.querySelector("limel-chip-set"))||void 0===s?void 0:s.shadowRoot)||void 0===o?void 0:o.querySelector("input"))||void 0===n?void 0:n.value)&&void 0!==l?l:""}get webComponentRegistry(){return this.platform.get(n.WebComponentRegistry)}get commandbus(){return this.platform.get(n.CommandBus)}get translator(){return this.platform.get(n.Translate)}get host(){return this}static get style(){return":host(limebb-component-picker){position:relative;display:flex;align-items:center}:host(limebb-component-picker) limel-picker{flex-grow:1;min-width:0}:host(limebb-component-picker) limel-icon-button{position:absolute;right:0.25rem}"}},[1,"limebb-component-picker",{platform:[16],context:[16],type:[1],tags:[16],value:[1],copyLabel:[1,"copy-label"],hideCopyButton:[4,"hide-copy-button"],required:[4],readonly:[4],disabled:[4],label:[1],helperText:[1,"helper-text"]}]),h=l,r=function(){"undefined"!=typeof customElements&&["limebb-component-picker"].forEach((t=>{"limebb-component-picker"===t&&(customElements.get(o(t))||customElements.define(o(t),l))}))};export{h as LimebbComponentPicker,r as defineCustomElement}