import{r as i,d as t,h as n}from"./p-03169580.js";import{D as s}from"./p-bd7cdf38.js";import{p as e}from"./p-c5cf028c.js";import"./p-bd8b186e.js";import"./p-4cb16df5.js";import"./p-7cbdb4ea.js";function o(i,t){return t.split(".").reduce(((i,t)=>i[t]),i)}const r='fireenjin-input-search .search-input ion-label{color:var(--ion-color-medium) !important;font-size:12px;font-weight:bold;text-transform:uppercase;font-family:arial;display:block;background:transparent;text-align:left;padding:0 0 8px 0;font-family:var(--ion-font-family)}fireenjin-input-search ion-icon{color:var(--ion-text-color)}fireenjin-input-search .search-input ion-icon[slot="start"]{margin-right:5px}fireenjin-input-search .search-input [slot="end"]{margin-left:5px}fireenjin-input-search .invalid{--border-color:var(--ion-color-danger) !important}fireenjin-input-search .invalid ion-label{color:var(--ion-color-danger) !important}fireenjin-input-search .valid{--border-color:var(--ion-color-success) !important}fireenjin-input-search .valid ion-label{color:var(--ion-color-success) !important}';var a=undefined&&undefined.__decorate||function(i,t,n,s){var e=arguments.length,o=e<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,n):s,r;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")o=Reflect.decorate(i,t,n,s);else for(var a=i.length-1;a>=0;a--)if(r=i[a])o=(e<3?r(o):e>3?r(t,n,o):r(t,n))||o;return e>3&&o&&Object.defineProperty(t,n,o),o};let l=class{constructor(n){i(this,n);this.ionInput=t(this,"ionInput",7);this.fireenjinFetch=t(this,"fireenjinFetch",7);this.type="text";this.searchParams={};this.disableSearch=false;this.mode="popover";this.results=[]}async checkValidity(i){if(this.required||i&&i.setValidationClass){await this.setValidationClass(i&&i.validationClassOptions?i.validationClassOptions:null)}return this.inputEl?await(await this.inputEl.getInputElement()).checkValidity():true}async reportValidity(){const i=this.inputEl?await(await this.inputEl.getInputElement()).reportValidity():true;this.inputEl.classList[i?"remove":"add"]("invalid");await this.setValidationClass();return i}async onBlur(){const i=await this.checkValidity();this.inputEl.classList[i?"remove":"add"]("invalid");await this.setValidationClass()}async onSuccess(i){var t,n;if(((t=i===null||i===void 0?void 0:i.detail)===null||t===void 0?void 0:t.endpoint)!==this.endpoint||!((n=i===null||i===void 0?void 0:i.detail)===null||n===void 0?void 0:n.data))return;this.results=await o(i.detail.data,this.resultsKey?this.resultsKey:"searchUsers.results");if(this.mode==="popover"){this.resultsPopover=await e.create({translucent:true,showBackdrop:false,event:i.detail.event,component:"fireenjin-input-search-popover",componentProps:{results:this.results,template:this.template}});this.resultsPopover.present()}}onInput(i){var t,n;if(this.disableSearch||((n=(t=i===null||i===void 0?void 0:i.target)===null||t===void 0?void 0:t.value)===null||n===void 0?void 0:n.length)<=1)return;this.fireenjinFetch.emit({event:i,endpoint:this.endpoint,params:{data:Object.assign({query:i.target.value},this.searchParams)},dataPropsMap:this.dataPropsMap})}async clearResults(){return this.results=[]}async closePopover(){return this.resultsPopover.dismiss()}async openPopover(){return this.resultsPopover.present()}async setValidationClass(i){const t=Object.values(this.itemEl.classList);if(t.indexOf("invalid")>=0){this.itemEl.classList.remove("invalid")}if(t.indexOf("valid")>=0){this.itemEl.classList.remove("valid")}const n=await(await this.inputEl.getInputElement()).checkValidity();if(!i||!i.ignoreInvalid||i&&i.ignoreInvalid&&n){this.itemEl.classList.add(n?"valid":"invalid")}}render(){var i;return[n("ion-item",{lines:this.lines,class:"search-input",ref:i=>this.itemEl=i,onClick:i=>this.onInput(i)},n("slot",{name:"start"}),this.iconStart&&n("ion-icon",{name:this.iconStart,slot:"start"}),this.label&&n("ion-label",{position:this.labelPosition},this.label),n("ion-input",{onInput:i=>this.onInput(i),ref:i=>this.inputEl=i,disabled:this.disabled,type:this.type,name:this.name,placeholder:this.placeholder,required:this.required,autofocus:this.autofocus,value:this.value}),this.iconEnd&&n("ion-icon",{name:this.iconEnd,slot:"end"}),n("slot",{name:"end"})),this.mode==="inline"&&((i=this.results)===null||i===void 0?void 0:i.length)?this.results.map((i=>this.template(i))):null]}};a([s(1e3)],l.prototype,"onInput",null);l.style=r;export{l as fireenjin_input_search};
//# sourceMappingURL=p-597a9f8a.entry.js.map