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

'use strict';

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

var helper = require('../../_chunks/dep-44e6bdf6.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var isFunction = require('lodash/isFunction');
var tdesignIconsVue = require('tdesign-icons-vue');
var utils_mixins = require('../../utils/mixins.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var config = require('../../config.js');
var tooltip_index = require('../../tooltip/index.js');
require('vue');
require('../../config-provider/zh_CN_config.js');
require('../../tooltip/tooltip.js');
require('../../tooltip/props.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../../_chunks/dep-939cdc39.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/set-style.js');
require('../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../utils/withInstall.js');
require('lodash/capitalize');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isFunction__default = /*#__PURE__*/_interopDefaultLegacy(isFunction);

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 tooltips = {
  asc: "\u70B9\u51FB\u5347\u5E8F",
  desc: "\u70B9\u51FB\u964D\u5E8F",
  undefined: "\u70B9\u51FB\u53D6\u6D88\u6392\u5E8F"
};
var SorterButton = utils_mixins["default"](configProvider_configReceiver["default"]("table")).extend({
  name: "".concat(config.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__default["default"](this.global.sortIcon) ? this.global.sortIcon(this.$createElement) : h(tdesignIconsVue.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(config.prefix, "-table__sort-icon"), className, "".concat(config.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(config.prefix, "-table__double-icons") : ""
    };
    var tips = tooltips[nextSortOrder];
    var sortButton = allowSortTypes.map(function (direction) {
      var className = direction === sortOrder ? "".concat(config.prefix, "-table__sort-icon--active") : "".concat(config.prefix, "-icon-sort--default");
      return _this.getSortIcon(direction, className);
    });
    return h("div", helper.helper([{
      "class": "".concat(config.prefix, "-table__cell--sort-trigger")
    }, buttonProps]), [tips ? h(tooltip_index.Tooltip, {
      "style": "line-height: 0px;position:relative;",
      "attrs": {
        "content": tips,
        "showArrow": false
      }
    }, [sortButton]) : sortButton]);
  }
});

exports["default"] = SorterButton;
//# sourceMappingURL=sorter-button.js.map
