/**
 * tdesign v0.32.0
 * (c) 2021 tdesign
 * @license MIT
 */

import { h as helper } from '../../_chunks/dep-42d5c87e.js';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import isFunction from 'lodash/isFunction';
import { ChevronDownIcon } from 'tdesign-icons-vue';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins from '../../config-provider/config-receiver.js';
import { prefix } from '../../config.js';
import { Tooltip } from '../../tooltip/index.js';
import 'vue';
import '../../config-provider/zh_CN_config.js';
import '../../config-provider/type.js';
import '../../tooltip/tooltip.js';
import '../../tooltip/props.js';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@babel/runtime/helpers/typeof';
import '@popperjs/core';
import '../../_chunks/dep-1db5c91c.js';
import '../../utils/classnames.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/render-tnode.js';
import '../../utils/set-style.js';
import '../../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import './style/index.js';
import '../../tooltip/type.js';

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 tooltips = {
  asc: "\u70B9\u51FB\u5347\u5E8F",
  desc: "\u70B9\u51FB\u964D\u5E8F",
  undefined: "\u70B9\u51FB\u53D6\u6D88\u6392\u5E8F"
};
var SorterButton = mixins(getConfigReceiverMixins("table")).extend({
  name: "".concat(prefix, "-sorter-button"),
  props: {
    sortType: {
      type: String,
      "default": null
    },
    sortOrder: {
      type: String,
      "default": function _default() {
        return "";
      }
    },
    nextSortOrder: {
      type: String,
      required: false
    }
  },
  computed: {
    allowSortTypes: function allowSortTypes() {
      return this.sortType === "all" ? ["asc", "desc"] : [this.sortType];
    }
  },
  methods: {
    getSortIcon: function getSortIcon(direction, className) {
      var h = this.$createElement;
      var icon = isFunction(this.global.sortIcon) ? this.global.sortIcon(this.$createElement) : h(ChevronDownIcon, {
        "attrs": {
          "size": "16px"
        }
      });
      var style = {
        left: "0px"
      };

      if (direction === "asc") {
        style = _objectSpread({
          transform: "rotate(-180deg)",
          top: "-1px"
        }, style);
      } else {
        style.bottom = "-1px";
      }

      var sortClassName = ["".concat(prefix, "-table__sort-icon"), className, "".concat(prefix, "-table-sort-").concat(direction)];
      return h("span", {
        "style": style,
        "class": sortClassName
      }, [icon]);
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var $listeners = this.$listeners,
        allowSortTypes = this.allowSortTypes,
        sortOrder = this.sortOrder,
        nextSortOrder = this.nextSortOrder;
    var buttonProps = {
      on: _objectSpread({}, $listeners),
      "class": allowSortTypes.length > 1 ? "".concat(prefix, "-table__double-icons") : ""
    };
    var tips = tooltips[nextSortOrder];
    var sortButton = allowSortTypes.map(function (direction) {
      var className = direction === sortOrder ? "".concat(prefix, "-table__sort-icon--active") : "".concat(prefix, "-icon-sort--default");
      return _this.getSortIcon(direction, className);
    });
    return h("div", helper([{
      "class": "".concat(prefix, "-table__cell--sort-trigger")
    }, buttonProps]), [tips ? h(Tooltip, {
      "style": "line-height: 0px;position:relative;",
      "attrs": {
        "content": tips,
        "showArrow": false
      }
    }, [sortButton]) : sortButton]);
  }
});

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