import{r as i,h as t,H as s,g as e}from"./p-9f21f85f.js";import{g as r}from"./p-2bb9af72.js";import{r as n,c as o}from"./p-f46dff5e.js";import{d as l}from"./p-62d69891.js";import{L as a}from"./p-e8a169b7.js";import"./p-d343a062.js";import"./p-aa5ffe14.js";function f(i){if(i&&i.sort)return i.sort}const d=class{constructor(t){i(this,t),this.list=a.init(),this.onSimpleFilterChange=({filter:i})=>{this.quickFilter=i,this.fetchList(!0,!0)}}async invalidate(i){this.fetchList(!0,!0)}async retainPosition(){const i=this.el.querySelector(".list-container");i&&(i.scrollTop=this.scrollPosition)}async componentWillLoad(){this.strings=await this.apiSozluk.getContent(this.view.i18nEntryId,l),this.fetchList()}fetchList(i=!1,t=!1){const{list:s,quickFilter:e}=this;if(s.isPending||!t&&s.isEndReached()||s.error&&!i)return;const{query:l,table:a,ui:d}=this.view,c=d.quickSearch?r(d.quickSearch,a.fields):void 0,p=function(i,t,s){let e=i?i.filter:void 0;if(t&&(e=i&&i.filter?{operator:"and",filters:[i.filter,t]}:t),e)return n(o(e),s)}(l,e||c,this.params);this.list=s.beforeFetch(),this.apiData.query(a.name,{fields:l.fields,filter:p,limit:25,skip:t?0:s.data?s.data.length:0,sort:f(l)}).then((i=>{this.list=s.afterFetch(i,!t)}),(i=>{this.list=s.afterFetchError(i)}))}render(){const{list:i,view:e}=this,{ui:r}=e;return t(s,null,r.quickSearch&&t("dvn-filter-simple",{fields:this.view.table.fields,progressing:i.isPending&&!!i.data,config:r.quickSearch,onFilterChange:i=>this.onSimpleFilterChange(i.detail)}),i.data&&t("div",{class:"list-container",onScroll:i=>{const t=i.target;this.scrollPosition=t.scrollTop,t.offsetHeight+t.scrollTop>=t.scrollHeight-100&&this.fetchList()}},t("dvn-card-list-view",{config:e.ui,fields:e.table.fields,items:i.data,strings:this.strings}),i.isPending&&!r.quickSearch&&t("div",{class:"d-flex justify-content-center pb-3"},t("dvn-progress",{indefinite:!0,tint:"primary"}))),i.isPending&&!i.data&&t("div",{class:"d-flex justify-content-center"},t("dvn-progress",{indefinite:!0,tint:"primary"})),i.error&&t("devingen-error-card",{error:i.error,message:"Fetching list failed.",onRetry:()=>this.fetchList(!0)}))}get el(){return e(this)}};d.style="dvn-app-view-list-view-card{-ms-flex:1;flex:1;display:-ms-flexbox;display:flex;-ms-flex-direction:column;flex-direction:column;overflow:hidden;padding:1rem}dvn-app-view-list-view-card dvn-filter-simple{margin-bottom:1rem}dvn-app-view-list-view-card .list-container{-ms-flex:1;flex:1;overflow-y:auto;overflow-x:hidden}";export{d as dvn_app_view_list_view_card}