/**
 * tdesign v0.41.7
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var helper = require('../_chunks/dep-99705d51.js');
var _typeof = require('@babel/runtime/helpers/typeof');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var tdesignIconsVue = require('tdesign-icons-vue');
var isEmpty = require('lodash/isEmpty');
var popup_index = require('../popup/index.js');
var checkbox_index = require('../checkbox/index.js');
var radio_index = require('../radio/index.js');
var input_index = require('../input/index.js');
var button_index = require('../button/index.js');
var hooks_tnode = require('../hooks/tnode.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('../popup/popup.js');
require('vue');
require('@popperjs/core');
require('../config.js');
require('../utils/classnames.js');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../_common/js/utils/set-style.js');
require('../popup/props.js');
require('../popup/container.js');
require('../utils/map-props.js');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../checkbox/group.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/intersection');
require('../checkbox/checkbox.js');
require('../checkbox/props.js');
require('../utils/event.js');
require('../checkbox/checkbox-group-props.js');
require('../radio/radio.js');
require('../radio/props.js');
require('../radio/group.js');
require('lodash/isNumber');
require('../radio/radio-group-props.js');
require('../radio/radio-button.js');
require('../input/addon.js');
require('../input/input.js');
require('lodash/kebabCase');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../utils/mixins.js');
require('../input/props.js');
require('../input/input-group.js');
require('../button/button.js');
require('../loading/index.js');
require('../loading/loading.js');
require('../loading/icon/gradient.js');
require('../_common/js/loading/circle-adapter.js');
require('../_common/js/utils/helper.js');
require('../utils/transfer-dom.js');
require('../loading/props.js');
require('../loading/plugin.js');
require('../button/props.js');
require('../utils/ripple.js');
require('lodash/isFunction');
require('../hooks/render-tnode.js');
require('lodash/isObject');
require('lodash/cloneDeep');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof);
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);

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__default["default"](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 = VueCompositionAPI.defineComponent({
  name: "TableFilterController",
  props: {
    column: Object,
    tFilterValue: Object,
    innerFilterValue: Object,
    tableFilterClasses: Object,
    isFocusClass: String,
    primaryTableElement: {}
  },
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var triggerElementRef = VueCompositionAPI.ref(null);
    var renderTNode = hooks_tnode.useTNodeDefault();

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

    var filterPopupVisible = VueCompositionAPI.ref(false);

    var onFilterPopupVisibleChange = function onFilterPopupVisibleChange(visible) {
      filterPopupVisible.value = visible;
      emit("visible-change", 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: radio_index.RadioGroup,
        multiple: checkbox_index.CheckboxGroup,
        input: input_index.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 filterComponentProps = _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") {
        filterComponentProps.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.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__default["default"](b) === "object" && "attrs" in b ? b.attrs : {};
        return h2(v, {
          props: _objectSpread(_objectSpread({}, filterComponentProps), tProps),
          on: on
        });
      }) : h(component, helper.helper([{
        "attrs": {
          "value": (_this$innerFilterValu2 = _this.innerFilterValue) === null || _this$innerFilterValu2 === void 0 ? void 0 : _this$innerFilterValu2[column2.colKey]
        }
      }, {
        "props": _objectSpread({}, filterComponentProps)
      }, {}, {
        "on": _objectSpread({}, on)
      }]))]);
    };

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

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

            _this.filterPopupVisible = false;
          }
        }
      }, [_this.global.confirmText])]);
    };

    var column = this.column;
    if (!column.filter || column.filter && !Object.keys(column.filter).length) return null;
    var defaultFilterIcon = this.t(this.global.filterIcon) || h(tdesignIconsVue.FilterIcon);
    return h(popup_index.Popup, helper.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__default["default"]({}, this.isFocusClass, !isEmpty__default["default"]((_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)])]);
  }
});

exports["default"] = TableFilterController;
//# sourceMappingURL=filter-controller.js.map
