/**
 * tdesign v0.39.1-alpha.1
 * (c) 2022 tdesign
 * @license MIT
 */

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _typeof from '@babel/runtime/helpers/typeof';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref } from '@vue/composition-api';
import { FilterIcon } from 'tdesign-icons-vue';
import isEmpty from 'lodash/isEmpty';
import { Popup } from '../popup/index.js';
import { CheckboxGroup } from '../checkbox/index.js';
import { RadioGroup } from '../radio/index.js';
import { Input } from '../input/index.js';
import { Button } from '../button/index.js';
import { useTNodeDefault } from '../hooks/tnode.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../popup/popup.js';
import 'vue';
import '@popperjs/core';
import '../config.js';
import '../utils/classnames.js';
import '../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isObject';
import '../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/camelCase';
import '../_common/js/utils/set-style.js';
import '../popup/props.js';
import '../popup/container.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../popup/type.js';
import '../checkbox/group.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/intersection';
import '../checkbox/checkbox.js';
import '../checkbox/props.js';
import '../utils/event.js';
import '../checkbox/checkbox-group-props.js';
import '../checkbox/type.js';
import '../radio/radio.js';
import '../radio/props.js';
import '../radio/group.js';
import 'lodash/isNumber';
import '../radio/radio-group-props.js';
import '../radio/radio-button.js';
import '../radio/type.js';
import '../input/addon.js';
import '../input/input.js';
import 'lodash/kebabCase';
import '../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../config-provider/type.js';
import '../utils/mixins.js';
import '../input/props.js';
import '../input/input-group.js';
import '../input/type.js';
import '../button/button.js';
import '../loading/index.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import '../_common/js/loading/circle-adapter.js';
import '../_common/js/utils/helper.js';
import '../utils/transfer-dom.js';
import '../loading/props.js';
import '../loading/type.js';
import '../loading/plugin.js';
import '../button/props.js';
import '../utils/ripple.js';
import '../button/type.js';
import 'lodash/isFunction';
import '../hooks/render-tnode.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';
import 'lodash/cloneDeep';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var TableFilterController = defineComponent({
  name: "TableFilterController",
  props: {
    column: Object,
    tFilterValue: Object,
    innerFilterValue: Object,
    tableFilterClasses: Object,
    isFocusClass: String,
    primaryTableElement: {}
  },
  setup: function setup(props) {
    var triggerElementRef = ref(null);
    var renderTNode = useTNodeDefault();

    var _useConfig = useConfig("table"),
        t = _useConfig.t,
        global = _useConfig.global;

    var filterPopupVisible = ref(false);

    var onFilterPopupVisibleChange = function onFilterPopupVisibleChange(visible) {
      filterPopupVisible.value = visible;
    };

    return {
      t: t,
      global: global,
      filterPopupVisible: filterPopupVisible,
      triggerElementRef: triggerElementRef,
      renderTNode: renderTNode,
      onFilterPopupVisibleChange: onFilterPopupVisibleChange
    };
  },
  render: function render(h) {
    var _this = this,
        _this$tFilterValue;

    var getFilterContent = function getFilterContent(h2, column2) {
      var _column2$filter, _column2$filter2, _column2$filter3, _column2$filter4, _column2$filter5, _this$innerFilterValu, _column2$filter6, _column2$filter7, _this$innerFilterValu2;

      var types = ["single", "multiple", "input"];

      if (column2.type && !types.includes(column2.filter.type)) {
        console.error("TDesign Table Error: column.filter.type must be the following: ".concat(JSON.stringify(types)));
        return;
      }

      if (column2 !== null && column2 !== void 0 && (_column2$filter = column2.filter) !== null && _column2$filter !== void 0 && _column2$filter.component && typeof (column2 === null || column2 === void 0 ? void 0 : (_column2$filter2 = column2.filter) === null || _column2$filter2 === void 0 ? void 0 : _column2$filter2.component) !== "function") {
        console.error("TDesign Table Error: column.filter.component must be a function");
        return;
      }

      var component = {
        single: RadioGroup,
        multiple: CheckboxGroup,
        input: Input
      }[column2.filter.type];
      if (!component && !(column2 !== null && column2 !== void 0 && (_column2$filter3 = column2.filter) !== null && _column2$filter3 !== void 0 && _column2$filter3.component)) return;

      var props = _objectSpread(_objectSpread({
        options: ["single", "multiple"].includes(column2.filter.type) ? (_column2$filter4 = column2.filter) === null || _column2$filter4 === void 0 ? void 0 : _column2$filter4.list : void 0
      }, ((_column2$filter5 = column2.filter) === null || _column2$filter5 === void 0 ? void 0 : _column2$filter5.props) || {}), {}, {
        value: (_this$innerFilterValu = _this.innerFilterValue) === null || _this$innerFilterValu === void 0 ? void 0 : _this$innerFilterValu[column2.colKey]
      });

      if (column2.filter.type === "single") {
        props.onChange = function (val) {
          _this.$emit("inner-filter-change", val, column2);
        };
      }

      var on = {
        change: function change(val) {
          _this.$emit("inner-filter-change", val, column2);
        }
      };
      var wrapperListeners = {};

      if (column2.filter.showConfirmAndReset) {
        wrapperListeners.click = function (e) {
          return e.stopPropagation();
        };
      }

      return h("div", helper([{
        "class": _this.tableFilterClasses.contentInner
      }, {
        "on": wrapperListeners
      }]), [column2 !== null && column2 !== void 0 && (_column2$filter6 = column2.filter) !== null && _column2$filter6 !== void 0 && _column2$filter6.component ? column2 === null || column2 === void 0 ? void 0 : (_column2$filter7 = column2.filter) === null || _column2$filter7 === void 0 ? void 0 : _column2$filter7.component(function (v, b) {
        var tProps = _typeof(b) === "object" && "attrs" in b ? b.attrs : {};
        return h2(v, {
          props: _objectSpread(_objectSpread({}, props), tProps),
          on: on
        });
      }) : h(component, helper([{
        "attrs": {
          "value": (_this$innerFilterValu2 = _this.innerFilterValue) === null || _this$innerFilterValu2 === void 0 ? void 0 : _this$innerFilterValu2[column2.colKey]
        }
      }, {
        "props": _objectSpread({}, props)
      }, {}, {
        "on": _objectSpread({}, on)
      }]))]);
    };

    var getBottomButtons = function getBottomButtons(h2, column2) {
      if (!column2.filter.showConfirmAndReset) return;
      return h("div", {
        "class": _this.tableFilterClasses.bottomButtons
      }, [h(Button, {
        "attrs": {
          "theme": "default",
          "size": "small"
        },
        "on": {
          "click": function click() {
            _this.$emit("reset", column2);

            _this.filterPopupVisible = false;
          }
        }
      }, ["\u91CD\u7F6E"]), h(Button, {
        "attrs": {
          "theme": "primary",
          "size": "small"
        },
        "on": {
          "click": function click() {
            _this.$emit("confirm", column2);

            _this.filterPopupVisible = false;
          }
        }
      }, ["\u786E\u8BA4"])]);
    };

    var column = this.column;
    if (!column.filter || column.filter && !Object.keys(column.filter).length) return null;
    var defaultFilterIcon = this.t(this.global.filterIcon) || h(FilterIcon);
    return h(Popup, helper([{
      "attrs": {
        "attach": this.primaryTableElement ? function () {
          return _this.primaryTableElement;
        } : void 0,
        "visible": this.filterPopupVisible,
        "destroyOnClose": true,
        "trigger": "click",
        "placement": "bottom",
        "showArrow": true,
        "overlayClassName": this.tableFilterClasses.popup
      }
    }, {
      "on": {
        "visible-change": function visibleChange(val) {
          return _this.onFilterPopupVisibleChange(val);
        }
      }
    }, {
      "class": [this.tableFilterClasses.icon, _defineProperty({}, this.isFocusClass, !isEmpty((_this$tFilterValue = this.tFilterValue) === null || _this$tFilterValue === void 0 ? void 0 : _this$tFilterValue[column.colKey]))],
      "attrs": {
        "content": function content() {
          return h("div", {
            "class": _this.tableFilterClasses.popupContent
          }, [getFilterContent(h, column), getBottomButtons(h, column)]);
        }
      }
    }]), [h("div", {
      "ref": "triggerElementRef"
    }, [this.renderTNode("filterIcon", defaultFilterIcon)])]);
  }
});

export { TableFilterController as default };
//# sourceMappingURL=filter-controller.js.map
