'use strict';

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

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

"use strict";
const _hoisted_1 = ["onClick"];
var _sfc_main = /* @__PURE__ */ vue.defineComponent({
  ...{ name: "LlAdvancedFilteringTags" },
  __name: "advanced-filtering-tags",
  props: advancedFiltering.advancedFilteringProps,
  emits: advancedFiltering.advancedFilteringTagsEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emits = __emit;
    const bem = createNamespace.createNamespace("advanced-filtering-tags");
    const tags = vue.ref([]);
    const handleClean = (tag = null) => {
      const copyValue = {};
      if (tag) {
        tags.value = tags.value.filter((e) => e.key !== tag.key);
      } else {
        tags.value = [];
      }
      tags.value.map((e) => {
        copyValue[e.key] = e.value;
      });
      setData(copyValue);
    };
    const setData = (obj) => {
      emits("update:value", obj);
      emits("change", obj);
    };
    const getTags = (filterColumns, values) => {
      const arr = [];
      filterColumns.map((item) => {
        const value = advancedFiltering.filterAllValue(values[item.key], item);
        if (data.hasValue(value)) {
          let tagValue = "";
          if (item?.options) {
            let options = [];
            if (item.fieldNames) {
              options = advancedFiltering.treeDataFormat(options, item.fieldNames);
            } else {
              options = item.options;
            }
            if (Array.isArray(value)) {
              let tagArr = [];
              tagArr = value.map((val) => {
                return advancedFiltering.findLabelByValue(options, val);
              });
              tagValue = tagArr.join(",");
            } else {
              tagValue = advancedFiltering.findLabelByValue(options, value);
            }
          } else {
            tagValue = value;
          }
          if (item.type === "date-picker") {
            tagValue = dayjs(value).format(item?.format ?? "YYYY-MM-DD");
          }
          if (item.type === "time-picker") {
            tagValue = dayjs(value).format(item?.format ?? "YYYY/MM/DD hh:mm:ss");
          }
          if (item.type === "date-range") {
            tagValue = `${dayjs(value[0]).format(
              item?.format ?? "YYYY-MM-DD"
            )} - ${dayjs(value[1]).format(item?.format ?? "YYYY-MM-DD")}`;
          }
          if (item.type === "number-range") {
            tagValue = `${value[0]}${value[1] ? ` - ${value[1]}` : ""}`;
          }
          if (item.type === "time-range") {
            tagValue = `${dayjs(value[0]).format(
              item?.format ?? "YYYY/MM/DD HH:mm:ss"
            )} - ${dayjs(value[1]).format(item?.format ?? "YYYY/MM/DD HH:mm:ss")}`;
          }
          if (item.type === "switch") {
            if (lodashEs.has(item, "checkedChildren") && lodashEs.has(item, "checkedValue") && lodashEs.has(item, "unCheckedChildren") && lodashEs.has(item, "unCheckedValue")) {
              tagValue = value === item.checkedValue ? item.checkedChildren : item.unCheckedChildren;
            }
            if (lodashEs.has(item, "checkedChildren") && !lodashEs.has(item, "checkedValue")) {
              tagValue = value ? item.checkedChildren : false;
            }
          }
          if (tagValue) {
            arr.push({
              label: item.label || "",
              key: item.key,
              value,
              showValue: tagValue
            });
          }
        }
      });
      return arr;
    };
    vue.watchEffect(() => {
      tags.value = getTags(props.filterColumns, props.value);
    });
    return (_ctx, _cache) => {
      const _component_ll_icon = vue.resolveComponent("ll-icon");
      return vue.openBlock(), vue.createElementBlock(
        "div",
        {
          class: vue.normalizeClass(vue.unref(bem).b())
        },
        [
          vue.createElementVNode(
            "div",
            {
              class: vue.normalizeClass(vue.unref(bem).m("title"))
            },
            [
              _cache[1] || (_cache[1] = vue.createElementVNode(
                "p",
                null,
                "\u7B5B\u9009\u7ED3\u679C\uFF1A",
                -1
                /* CACHED */
              )),
              vue.createElementVNode("a", {
                onClick: _cache[0] || (_cache[0] = ($event) => handleClean(null))
              }, "\u6E05\u9664\u7B5B\u9009\u7ED3\u679C")
            ],
            2
            /* CLASS */
          ),
          tags.value.length > 0 ? (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 0,
              class: vue.normalizeClass(vue.unref(bem).m("box"))
            },
            [
              (vue.openBlock(true), vue.createElementBlock(
                vue.Fragment,
                null,
                vue.renderList(tags.value, (tag) => {
                  return vue.openBlock(), vue.createElementBlock(
                    "div",
                    {
                      key: tag.key,
                      class: vue.normalizeClass(vue.unref(bem).m("tag"))
                    },
                    [
                      vue.createElementVNode(
                        "span",
                        {
                          class: vue.normalizeClass(vue.unref(bem).m("label"))
                        },
                        vue.toDisplayString(tag.label) + "\uFF1A",
                        3
                        /* TEXT, CLASS */
                      ),
                      vue.createElementVNode(
                        "span",
                        {
                          class: vue.normalizeClass(vue.unref(bem).m("value"))
                        },
                        vue.toDisplayString(tag.showValue),
                        3
                        /* TEXT, CLASS */
                      ),
                      vue.createElementVNode("span", {
                        class: vue.normalizeClass(vue.unref(bem).m("close")),
                        onClick: ($event) => handleClean(tag)
                      }, [
                        vue.createVNode(_component_ll_icon, {
                          "icon-name": "icon-close2",
                          "class-name": vue.unref(bem).m("icon")
                        }, null, 8, ["class-name"])
                      ], 10, _hoisted_1)
                    ],
                    2
                    /* CLASS */
                  );
                }),
                128
                /* KEYED_FRAGMENT */
              ))
            ],
            2
            /* CLASS */
          )) : (vue.openBlock(), vue.createElementBlock(
            "div",
            {
              key: 1,
              class: vue.normalizeClass(vue.unref(bem).m("empty"))
            },
            [..._cache[2] || (_cache[2] = [
              vue.createElementVNode(
                "span",
                null,
                "\u6682\u65E0\u6570\u636E",
                -1
                /* CACHED */
              )
            ])],
            2
            /* CLASS */
          ))
        ],
        2
        /* CLASS */
      );
    };
  }
});

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