import{r as t,c as s,h as i,H as e,a}from"./p-7d0be017.js";import{h as l}from"./p-50a111ca.js";import{c as o,a as c}from"./p-96db9919.js";const h=class{constructor(i){t(this,i),this.gascoReady=s(this,"gascoReady",7),this.gascoChangeSelect=s(this,"gascoChangeSelect",7),this.selectId="gasco-sel-"+n++,this.element=[],this.multiple=!1,this.name=this.selectId,this.disabled=!1,this.placeholder="Seleccione un elemento",this.isExpanded=!1,this.onClick=()=>{this.isExpanded=!this.isExpanded}}componentWillLoad(){this.gascoReady.emit()}componentDidLoad(){this.getChoices()}onSelect(t,s,i){if(t.preventDefault(),!this.multiple)return t.stopPropagation(),void(this.value=s);if(this.element.some((t=>s===t.label))){var e=this.element.filter((t=>t.label!==s));this.element=e}else this.element.push({label:s,value:i});const a=this.element.map((t=>t.label)),l=this.element.map((t=>t.value));this.value=this.parseValue(a),this.gascoChangeSelect.emit({target:this.el,detail:l.join(",")}),t.stopPropagation()}parseValue(t){if(null!=t)return Array.isArray(t)&&t.length>1?t.join(", "):t.join("")}getChoices(){return this.choices?this.choices.map((t=>t)):[]}handleWindowClick(t){!this.el.contains(t.target)&&this.isExpanded&&(this.isExpanded=!1)}render(){const{el:t,isExpanded:s,disabled:a,value:h,multiple:n,placeholder:r,label:d}=this;return i(e,{role:"button","aria-haspopup":"listbox","aria-disabled":a?"true":null,class:{"in-item":l("gasco-item",t),"select-disabled":a,"gasco-select":!0,"select-expanded":s,"gasco-color":!0,"gasco-color-primary":!0}},i("div",{class:"select-native"},i("gasco-input",{readonly:!0,value:h,label:d,onClick:this.onClick,placeholder:r},i("ion-icon",{slot:"end",lazy:!1,icon:s?o:c})),i("gasco-list",null,this.getChoices().length>0&&s&&this.getChoices().map((({label:t,value:s,disabled:e})=>i("gasco-item",{disabled:e,onClick:i=>this.onSelect(i,t,s)},n&&i("gasco-checkbox",{slot:"start",color:"primary",checked:this.element.some((s=>s.label===t))}),t))))))}get el(){return a(this)}};let n=0;h.style=":host(.gasco-select){width:100%;max-width:400px}.select-native{position:relative;width:100%;max-width:400px}.select-native gasco-input,.select-native gasco-list{max-width:100%}.select-native gasco-list{position:absolute;left:0;right:0;top:55px;z-index:100;opacity:0;contain:layout;visibility:hidden;transition:300ms;width:100%}:host(.select-expanded) .select-native gasco-list{opacity:1;visibility:visible}";export{h as gasco_select}