'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var lodashEs = require('lodash-es');
require('../../../../utils/index.js');
require('../../../index.js');
var advancedFiltering = require('../advanced-filtering.js');
var createNamespace = require('../../../../utils/create-namespace.js');
var index = require('../../../form/index.js');

"use strict";
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlAdvancedFilteringParams" },
  __name: "advanced-filtering-params",
  props: advancedFiltering.advancedFilteringParamsProps,
  emits: advancedFiltering.advancedFilteringParamsEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const bem = createNamespace.createNamespace("advanced-filtering-params");
    const innerValue = vue.ref({});
    const key = vue.ref(0);
    const computeFormColumns = vue.computed(() => {
      return props.filterColumns.map((column) => {
        if (lodashEs.has(column, "options")) {
          if (column.options.length && column.options[0].value === advancedFiltering.ALL_VALUE || column.unUseDefaultOption) {
            return column;
          }
          column.options = [
            {
              label: column?.defaultOptionLabel ?? "\u5168\u90E8",
              value: advancedFiltering.ALL_VALUE
            },
            ...column.options
          ];
        }
        return column;
      });
    });
    const handleClose = () => {
      emits("close");
    };
    const handleAdvancedFilterConfirm = () => {
      emits("confirm");
    };
    const handleChange = (params) => {
      setData(params);
    };
    const setData = (params) => {
      const value = lodashEs.cloneDeep(params.formData);
      const obj = {};
      computeFormColumns.value.forEach((item) => {
        const i = item.key;
        obj[i] = advancedFiltering.filterAllValue(value[i], item);
      });
      emits("update:value", obj);
      emits("changeValue", { ...params, formData: obj });
    };
    vue.watch(
      () => props.value,
      (val) => {
        const value = lodashEs.cloneDeep(val);
        const obj = advancedFiltering.initValue(computeFormColumns.value, value);
        if (JSON.stringify(val) !== JSON.stringify(innerValue.value)) {
          innerValue.value = lodashEs.cloneDeep(obj);
        }
        if (key.value === 0) {
          innerValue.value = lodashEs.cloneDeep(obj);
          key.value++;
        }
      },
      {
        deep: true,
        immediate: true
      }
    );
    return (_ctx, _cache) => {
      const _component_ll_icon = vue.resolveComponent("ll-icon");
      const _component_ll_button = vue.resolveComponent("ll-button");
      const _component_a_card = vue.resolveComponent("a-card");
      return vue.openBlock(), vue.createBlock(_component_a_card, {
        title: "\u9AD8\u7EA7\u7B5B\u9009",
        class: vue.normalizeClass(vue.unref(bem).b()),
        bordered: false
      }, {
        extra: vue.withCtx(() => [
          vue.createVNode(_component_ll_icon, {
            "icon-name": "icon-close2",
            style: {
              cursor: "pointer"
            },
            onClick: handleClose
          })
        ]),
        default: vue.withCtx(() => [
          vue.createElementVNode(
            "div",
            {
              class: vue.normalizeClass(vue.unref(bem).m("content"))
            },
            [
              props.filterColumns.length > 0 ? (vue.openBlock(), vue.createBlock(vue.unref(index.LlForm), vue.mergeProps({ key: 0 }, _ctx.$attrs, {
                "form-columns": computeFormColumns.value,
                "form-options": props.formOptions,
                "form-data": innerValue.value,
                "row-options": _ctx.$attrs["row-options"] || {
                  gutter: 30
                },
                onChange: handleChange
              }), null, 16, ["form-columns", "form-options", "form-data", "row-options"])) : (vue.openBlock(), vue.createElementBlock(
                "div",
                {
                  key: 1,
                  class: vue.normalizeClass(vue.unref(bem).m("empty"))
                },
                [..._cache[0] || (_cache[0] = [
                  vue.createElementVNode(
                    "p",
                    null,
                    "\u6682\u65E0\u6570\u636E",
                    -1
                    /* CACHED */
                  )
                ])],
                2
                /* CLASS */
              ))
            ],
            2
            /* CLASS */
          ),
          props.showFooter ? (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 0,
              class: vue.normalizeClass(vue.unref(bem).m("footer"))
            },
            [
              vue.createVNode(_component_ll_button, {
                type: "primary",
                style: { "margin-right": "16px" },
                onClick: handleAdvancedFilterConfirm
              }, {
                default: vue.withCtx(() => [..._cache[1] || (_cache[1] = [
                  vue.createTextVNode(
                    " \u786E\u5B9A ",
                    -1
                    /* CACHED */
                  )
                ])]),
                _: 1
                /* STABLE */
              }),
              vue.createVNode(_component_ll_button, { onClick: handleClose }, {
                default: vue.withCtx(() => [..._cache[2] || (_cache[2] = [
                  vue.createTextVNode(
                    "\u53D6\u6D88",
                    -1
                    /* CACHED */
                  )
                ])]),
                _: 1
                /* STABLE */
              })
            ],
            2
            /* CLASS */
          )) : vue.createCommentVNode("v-if", true)
        ]),
        _: 1
        /* STABLE */
      }, 8, ["class"]);
    };
  }
});

exports.default = _sfc_main;
//# sourceMappingURL=advanced-filtering-params.vue2.js.map
