"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
;/* empty css                                               */
;/* empty css                                                  */
;/* empty css                                               */
const Vue = require("vue");
const datasource = require("../../../utils/datasource.js");
const VueRender = require("../../../utils/idea/VueRender.vue.js");
;/* empty css               */
const _pluginVue_exportHelper = require("../../../../../../_virtual/_plugin-vue_export-helper.js");
const index = require("../../../../node_modules/vant/es/list/index.js");
const _sfc_main = /* @__PURE__ */ Object.assign({
  inheritAttrs: false
}, {
  __name: "CardList",
  props: {
    compId: {
      type: String
    },
    modelValue: {
      type: Array,
      default: []
    },
    disabledLoad: {
      type: Boolean,
      default: false
    },
    offset: {
      type: String,
      default: "0"
    },
    direction: {
      type: String,
      default: "down"
    },
    dataSourceValue: {
      type: String,
      default: ""
    },
    dataSources: {
      type: Array,
      default: () => []
    },
    pageSize: {
      type: Number,
      default: 10
    },
    swipeDelete: {
      type: Boolean,
      default: false
    },
    vueTemplate: {
      type: String,
      default: ""
    },
    enableFilter: {
      type: Boolean,
      default: false
    },
    filterPlaceholder: {
      type: String,
      default: ""
    },
    filterMode: {
      type: String,
      default: ""
    },
    quickFilter: {
      type: Array,
      default: []
    },
    autoHeight: {
      type: Boolean,
      default: false
    }
  },
  setup(__props) {
    const props = __props;
    const currentInstance = Vue.getCurrentInstance();
    const ctx = currentInstance.proxy;
    const listRef = Vue.ref();
    Vue.onMounted(() => {
      var _a, _b;
      (_b = (_a = listRef.value) == null ? void 0 : _a.$el) == null ? void 0 : _b.closest(".device-content");
      initDataSourceManager();
    });
    function eventHandler(funcName, rowData) {
      console.log("🚀 ~ eventHandler ~ funcName, rowData:", funcName, rowData);
    }
    const tableData = Vue.ref([]);
    const finished = Vue.ref(false);
    const error = Vue.ref(false);
    const loading = Vue.ref(false);
    let pageNo = 1;
    const dataSourceManager = Vue.ref();
    function initDataSourceManager() {
      dataSourceManager.value = datasource.createDataSource({
        http: ctx.$http,
        dataSources: props.dataSources,
        currentDataSourceId: props.dataSourceValue,
        pagination: {
          pageNo,
          pageSize: props.pageSize
        }
        // data: hiddenFormData.value,
        // fields: fieldsData.value,
        // sortRules: localConfig.value.sortRules,
        // templateId: localConfig.value.templateKey,
      });
      dataSourceManager.value.on("loaded", (data) => {
      });
      dataSourceManager.value.on("error", (err) => {
      });
      if (dataSourceManager.value) {
        tableData.value = [];
        if (props.disabledLoad) {
          tableData.value = [];
          call();
        } else {
          pageNo = 0;
        }
      } else {
        loading.value = false;
      }
    }
    function onLoad() {
      if (dataSourceManager.value) {
        loading.value = true;
        pageNo++;
        call();
      } else {
        loading.value = false;
      }
    }
    async function call() {
      var _a;
      error.value = false;
      try {
        dataSourceManager.value.updatePagination(pageNo, props.pageSize);
        await dataSourceManager.value.fetch();
        const data = ((_a = dataSourceManager.value) == null ? void 0 : _a.getData().list) || [];
        tableData.value.push(...data);
        if (tableData.value.length == 0) {
          tableData.value = [{}];
        }
        if (data.length < props.pageSize) {
          finished.value = true;
        }
        loading.value = false;
      } catch (err) {
        console.error(err);
        error.value = true;
        loading.value = false;
      }
    }
    const quickFilterConfig = Vue.computed(() => {
      return props.quickFilter;
    });
    return (_ctx, _cache) => {
      const _component_fec_mobile_search = Vue.resolveComponent("fec-mobile-search");
      const _component_fec_mobile_card = Vue.resolveComponent("fec-mobile-card");
      const _component_van_list = index.List;
      return Vue.openBlock(), Vue.createElementBlock(Vue.Fragment, null, [
        __props.enableFilter ? (Vue.openBlock(), Vue.createBlock(_component_fec_mobile_search, {
          key: 0,
          placeholder: __props.filterPlaceholder,
          filterMode: __props.filterMode,
          dataSources: __props.dataSources,
          filterConfig: Vue.unref(quickFilterConfig)
        }, null, 8, ["placeholder", "filterMode", "dataSources", "filterConfig"])) : Vue.createCommentVNode("", true),
        Vue.createVNode(_component_van_list, {
          ref_key: "listRef",
          ref: listRef,
          loading: Vue.unref(loading),
          "onUpdate:loading": _cache[0] || (_cache[0] = ($event) => Vue.isRef(loading) ? loading.value = $event : null),
          error: Vue.unref(error),
          "onUpdate:error": _cache[1] || (_cache[1] = ($event) => Vue.isRef(error) ? error.value = $event : null),
          finished: Vue.unref(finished),
          disabled: __props.disabledLoad,
          offset: __props.offset,
          "finished-text": "没有更多了",
          "error-text": "请求失败，点击重新加载",
          onLoad,
          class: "fec-card-list"
        }, {
          default: Vue.withCtx(() => [
            (Vue.openBlock(true), Vue.createElementBlock(Vue.Fragment, null, Vue.renderList(Vue.unref(tableData), (item) => {
              return Vue.openBlock(), Vue.createBlock(_component_fec_mobile_card, {
                key: item.id,
                swipeDelete: __props.swipeDelete
              }, {
                default: Vue.withCtx(() => [
                  Vue.createVNode(VueRender.default, {
                    code: __props.vueTemplate,
                    params: { data: item, eventHandler }
                  }, null, 8, ["code", "params"])
                ]),
                _: 2
              }, 1032, ["swipeDelete"]);
            }), 128))
          ]),
          _: 1
        }, 8, ["loading", "error", "finished", "disabled", "offset"])
      ], 64);
    };
  }
});
const _CardList = /* @__PURE__ */ _pluginVue_exportHelper.default(_sfc_main, [["__scopeId", "data-v-38039905"]]);
exports.default = _CardList;
