import { defineComponent, ref, computed, watch, resolveComponent, createBlock, openBlock, normalizeClass, unref, withCtx, createElementVNode, createElementBlock, createCommentVNode, mergeProps, createVNode, createTextVNode } from 'vue';
import { has, cloneDeep } from 'lodash-es';
import '../../../../utils/index.mjs';
import '../../../index.mjs';
import { ALL_VALUE, filterAllValue, initValue, advancedFilteringParamsEmits, advancedFilteringParamsProps } from '../advanced-filtering.mjs';
import { createNamespace } from '../../../../utils/create-namespace.mjs';
import { LlForm } from '../../../form/index.mjs';

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

export { _sfc_main as default };
//# sourceMappingURL=advanced-filtering-params.vue2.mjs.map
