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

import { h as helper } from '../_chunks/dep-1ec74b8b.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import { ChevronDownIcon } from 'tdesign-icons-vue';
import useClassName from './hooks/useClassName.js';
import { Tooltip } from '../tooltip/index.js';
import { useConfig } from '../config-provider/useConfig.js';
import { useTNodeDefault } from '../hooks/tnode.js';
import 'lodash/cloneDeep';
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 '../tooltip/tooltip.js';
import 'vue';
import '../config.js';
import '../tooltip/props.js';
import '../popup/props.js';
import '../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
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/container.js';
import '../utils/map-props.js';
import '../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../tooltip/type.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/kebabCase';
import '../hooks/render-tnode.js';
import '../_common/js/log/index.js';
import '../_common/js/log/log.js';

var SorterButton = defineComponent({
  props: {
    sortType: {
      type: String,
      "default": "all"
    },
    sortOrder: {
      type: String,
      "default": function _default() {
        return "";
      }
    },
    sortIcon: Function,
    tooltipProps: Object
  },
  setup: function setup(props, context) {
    var _useClassName = useClassName(),
        tableSortClasses = _useClassName.tableSortClasses,
        negativeRotate180 = _useClassName.negativeRotate180;

    var renderTNode = useTNodeDefault();

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

    var allowSortTypes = computed(function () {
      return props.sortType === "all" ? ["asc", "desc"] : [props.sortType];
    });

    var onSortIconClick = function onSortIconClick(e, direction) {
      context.emit("sort-icon-click", e, {
        descending: direction === "desc"
      });
    };

    return {
      t: t,
      global: global,
      tableSortClasses: tableSortClasses,
      negativeRotate180: negativeRotate180,
      allowSortTypes: allowSortTypes,
      onSortIconClick: onSortIconClick,
      renderTNode: renderTNode
    };
  },
  methods: {
    getSortIcon: function getSortIcon(direction, activeClass) {
      var _this = this;

      var h = this.$createElement;
      var defaultIcon = this.t(this.global.sortIcon) || h(ChevronDownIcon);
      var icon = this.renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, this.tableSortClasses.sortIcon, this.tableSortClasses.iconDirection[direction], _defineProperty({}, this.negativeRotate180, direction === "asc")];
      return h("span", {
        "class": sortClassName,
        "on": {
          "click": function click(e) {
            return _this.onSortIconClick(e, direction);
          }
        }
      }, [icon]);
    }
  },
  render: function render() {
    var _this2 = this;

    var h = arguments[0];
    var tableSortClasses = this.tableSortClasses;
    var classes = [tableSortClasses.trigger, _defineProperty({}, tableSortClasses.doubleIcon, this.allowSortTypes.length > 1)];
    var tooltips = {
      asc: this.global.sortAscendingOperationText,
      desc: this.global.sortDescendingOperationText
    };
    var sortButton = this.allowSortTypes.map(function (direction) {
      var activeClass = direction === _this2.sortOrder ? tableSortClasses.iconActive : tableSortClasses.iconDefault;
      var cancelTips = _this2.global.sortCancelOperationText;
      var tips = direction === _this2.sortOrder ? cancelTips : tooltips[direction];
      return h(Tooltip, helper([{
        "attrs": {
          "content": tips,
          "placement": "right"
        }
      }, _this2.tooltipProps, {
        "attrs": {
          "showArrow": false
        },
        "class": _this2.tableSortClasses.iconDirection[direction]
      }]), [_this2.getSortIcon(direction, activeClass)]);
    });
    return h("div", {
      "class": classes
    }, [sortButton]);
  }
});

export { SorterButton as default };
//# sourceMappingURL=sorter-button.js.map
