import{C as Comparison}from"./filter-cbaa3d7d.js";import{L as ListFetchState}from"./list-fetch-state-d8c2f8ef.js";function buildQuery(t,i){var e=t?t.filter:undefined;if(i){if(t&&t.filter){e={operator:"and",filters:[t.filter,i]}}else{e=i}}return e}function generateQuickSearchFilters(t,i){if(!t||!i){return undefined}return{operator:"or",filters:t.fields.map((function(t){return{comparison:Comparison.Contain,id:t.fieldId,value:i}}))}}var DvnDataProvider=function(){function t(t,i,e,r,a){this.didQuickSearchChangeAfterLastFetch=false;this.list=ListFetchState.init();this.collection=i;this.query=e;this.initialData=r;this.quickSearch=a;this.api=t}t.prototype.getInitialData=function(){return Promise.resolve(this.initialData)};t.prototype.getData=function(){var t=this;var i=this,e=i.api,r=i.collection,a=i.query,n=i.quickSearchText;var c=this;return new Promise((function(i,s){if(c.list.data&&!t.didQuickSearchChangeAfterLastFetch){i(c.list.data);return}var o=buildQuery(a,generateQuickSearchFilters(t.quickSearch,n));e.query(r,{fields:a.fields,filter:o,limit:50,skip:0,sort:a.sort}).then((function(e){c.list=ListFetchState.init().afterFetch(e);t.didQuickSearchChangeAfterLastFetch=false;i(c.list.data)}),(function(t){c.list=ListFetchState.init().afterFetchError(t);s(t)}))}))};t.prototype.setInitialData=function(t){this.initialData=t};t.prototype.setQuickSearchText=function(t){this.quickSearchText=t;this.didQuickSearchChangeAfterLastFetch=true};t.prototype.getQuickSearchText=function(){return this.quickSearchText};t.prototype.isQuickSearchEnabled=function(){return!!this.quickSearch};return t}();export{DvnDataProvider as D};