import{r as i,c as t,h as e,H as s,g as n}from"./p-9f21f85f.js";import{a as l,b as a}from"./p-2bb9af72.js";import{a as h,R as o}from"./p-bb86e4ad.js";import{M as r}from"./p-6c8be41c.js";import{S as c}from"./p-1187cc7c.js";import{T as d}from"./p-968ee2ec.js";import"./p-d343a062.js";import"./p-31e77e7b.js";import"./p-105f7627.js";function p(i,t,s,n,l,a="horizontal",h={}){var o;const p="horizontal"===a,v=t.value||s[t.id],u=null===(o=i.fieldUIConfigs)||void 0===o?void 0:o.find((i=>i.fieldId===t.id));switch(t.type){case d.type:return e("dvn-input",{enableClear:!0,leaned:p,onChange:i=>n(t.id,i.detail),placeholder:t.title,width:"horizontal"===a?(null==u?void 0:u.width)||"100px":"inherit",overrideStyle:Object.assign(Object.assign({},"horizontal"===a?{marginRight:"calc(1.5 * var(--spacing-unit))"}:{display:"flex",flex:"1"}),h),value:v});case c.type:return t.dataAdapter?e("dvn-select",{enableClear:!0,enableSearch:!0,leaned:p,dataAdapter:t.dataAdapter,dataProvider:t.dataProvider,onChange:i=>l(t.id,i.detail),width:"horizontal"===a?(null==u?void 0:u.width)||"100px":"inherit",style:Object.assign({marginRight:"calc(1.5 * var(--spacing-unit))"},h),value:v},e("dvn-select-option",null,t.title)):e("dvn-select",{enableClear:!0,enableSearch:!0,leaned:p,onChange:i=>l(t.id,i.detail),width:"horizontal"===a?(null==u?void 0:u.width)||"100px":"inherit",style:Object.assign({marginRight:"calc(1.5 * var(--spacing-unit))"},h),value:v},e("dvn-select-option",null,t.title),t.options.map((i=>e("dvn-select-option",{value:i.value},i.label))));case r.type:return e("dvn-select",{enableClear:!0,enableSearch:!0,leaned:p,onChange:i=>l(t.id,i.detail),width:"horizontal"===a?(null==u?void 0:u.width)||"100px":"inherit",style:Object.assign({marginRight:"calc(1.5 * var(--spacing-unit))"},h),value:v},e("dvn-select-option",null,t.title),t.options.map((i=>e("dvn-select-option",{value:i.value},i.label))))}}function v(i,t,e,s,n,l="horizontal"){return t.map((t=>p(i,t,e,s,n,l)))}const u=class{constructor(e){i(this,e),this.filterChange=t(this,"filterChange",7),this.filterValues={text:""},this.showInputsDialog=!1,this.lastFilterItemIndexToShow=0,this.leaned=!1,this.placeholder="Quick search",this.progressing=!1,this.onSizeChange=i=>{this.size=i},this.onWidthChange=i=>{var t;let e=100,s=0;for(let n=0;n<this.config.fields.length;n++){const l=this.config.fields[n].fieldId,a=null===(t=this.config.fieldUIConfigs)||void 0===t?void 0:t.find((i=>i.fieldId===l));if(e+=parseInt((null==a?void 0:a.width)||"100px",10),e>i)break;s=n,e+=6}this.lastFilterItemIndexToShow=s},this.onNonTextFieldChange=(i,t)=>{if(t)this.filterValues=Object.assign(Object.assign({},this.filterValues),{[i]:t});else{const t=Object.assign({},this.filterValues);delete t[i],this.filterValues=t}this.filterChange.emit({filter:l(this.filterFields,this.filterValues)})},this.onTextChange=(i,t)=>{if(t)this.filterValues=Object.assign(Object.assign({},this.filterValues),{[i]:t});else{const t=Object.assign({},this.filterValues);delete t[i],this.filterValues=t}clearTimeout(this.quickSearchDelayTimer),this.quickSearchDelayTimer=setTimeout((()=>{this.filterChange.emit({filter:l(this.filterFields,this.filterValues)})}),500)}}componentWillLoad(){this.uiHelper=new h(this.el,this.onSizeChange,this.onWidthChange);const{config:i,fields:t}=this;this.filterFields=i.fields.map((i=>i.field||t.find((t=>t.id===i.fieldId)))),this.filterValues=a(i,t)}render(){const{size:i}=this;if(i<o.Small)return e(s,{class:"d-block"},e("div",{class:"d-flex"},e("dvn-input-group",{leaned:!0,overrideStyle:{flex:"1"}},p(this.config,this.filterFields[0],this.filterValues,this.onTextChange,this.onNonTextFieldChange,"horizontal",{display:"flex",flex:"1"}),this.filterFields.length>1&&e("dvn-icon-button",{tint:"primary",onClick:()=>this.showInputsDialog=!0,progressing:this.progressing,"icon-name":"uil uil-filter"}))),e("dvn-dialog",{clip:!1,shown:this.showInputsDialog,onDismiss:()=>this.showInputsDialog=!1},e("div",{class:"d-flex flex-column"},v(this.config,this.filterFields,this.filterValues,this.onTextChange,this.onNonTextFieldChange,"vertical"))));const t=this.lastFilterItemIndexToShow+1<this.filterFields.length,n=[...this.filterFields].slice(0,this.lastFilterItemIndexToShow+1);return e(s,{class:"d-flex justify-content-end"},v(this.config,n,this.filterValues,this.onTextChange,this.onNonTextFieldChange),t&&e("div",{class:"d-flex"},e("dvn-button",{leaned:!0,tint:"primary",onClick:()=>this.showInputsDialog=!0},e("dvn-icon",{"icon-name":"uil uil-filter"}))),this.progressing&&e("div",{style:{display:"flex",alignItems:"center"}},e("dvn-progress",{indefinite:!0,leaned:!0,tint:"primary",scale:"small"})),e("dvn-dialog",{clip:!1,shown:this.showInputsDialog,onDismiss:()=>this.showInputsDialog=!1},e("div",{class:"d-flex flex-column"},v(this.config,this.filterFields,this.filterValues,this.onTextChange,this.onNonTextFieldChange,"vertical"))))}get el(){return n(this)}};export{u as dvn_filter_simple}