/**
 * ldesign v0.3.13
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var tooltip_index = require('../tooltip/index.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_tnode = require('../hooks/tnode.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
require('../utils/withInstall.js');
require('../tooltip/tooltip.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/isFunction');
require('lodash/omit');
require('../popup/props.js');
require('../popup/index.js');
require('../popup/popup.js');
require('@popperjs/core');
require('lodash/isString');
require('lodash/isObject');
require('../hooks/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-f4db2590.js');
require('dayjs');
require('../utils/dom.js');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../_common/js/utils/set-style.js');
require('../hooks/useVModel.js');
require('../popup/container.js');
require('@babel/runtime/helpers/toConsumableArray');
require('lodash/isUndefined');
require('../hooks/useResizeObserver.js');
require('../tooltip/util.js');
require('../tooltip/props.js');

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

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

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var SorterButton = vue.defineComponent({
  name: "TSorterButton",
  props: {
    sortType: {
      type: String,
      "default": "all"
    },
    sortOrder: {
      type: String,
      "default": function _default() {
        return "";
      }
    },
    sortIcon: Function,
    tooltipProps: Object,
    hideSortTips: Boolean
  },
  emits: ["sort-icon-click"],
  setup: function setup(props, context) {
    var _useClassName = table_hooks_useClassName["default"](),
      tableSortClasses = _useClassName.tableSortClasses,
      negativeRotate180 = _useClassName.negativeRotate180;
    var renderTNode = hooks_tnode.useTNodeDefault();
    var _useConfig = configProvider_useConfig.useConfig("table"),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        ChevronDownIcon: iconsVueNext.ChevronDownIcon
      }),
      ChevronDownIcon = _useGlobalIcon.ChevronDownIcon;
    var allowSortTypes = vue.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,
      globalConfig: globalConfig,
      ChevronDownIcon: ChevronDownIcon,
      tableSortClasses: tableSortClasses,
      negativeRotate180: negativeRotate180,
      allowSortTypes: allowSortTypes,
      onSortIconClick: onSortIconClick,
      renderTNode: renderTNode
    };
  },
  methods: {
    getSortIcon: function getSortIcon(direction, activeClass) {
      var _this = this;
      var ChevronDownIcon = this.ChevronDownIcon;
      var defaultIcon = this.t(this.globalConfig.sortIcon) || vue.createVNode(ChevronDownIcon, null, null);
      var icon = this.renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, this.tableSortClasses.sortIcon, this.tableSortClasses.iconDirection[direction], _defineProperty__default["default"]({}, this.negativeRotate180, direction === "asc")];
      return vue.createVNode("span", {
        "class": sortClassName,
        "onClick": function onClick(e) {
          return _this.onSortIconClick(e, direction);
        }
      }, [icon]);
    }
  },
  render: function render() {
    var _this2 = this;
    var tableSortClasses = this.tableSortClasses;
    var classes = [tableSortClasses.trigger, _defineProperty__default["default"]({}, tableSortClasses.doubleIcon, this.allowSortTypes.length > 1)];
    var tooltips = {
      asc: this.globalConfig.sortAscendingOperationText,
      desc: this.globalConfig.sortDescendingOperationText
    };
    var sortButton = this.allowSortTypes.map(function (direction) {
      var _slot;
      var _this2$hideSortTips;
      var activeClass = direction === _this2.sortOrder ? tableSortClasses.iconActive : tableSortClasses.iconDefault;
      var cancelTips = _this2.globalConfig.sortCancelOperationText;
      var tips = direction === _this2.sortOrder ? cancelTips : tooltips[direction];
      if ((_this2$hideSortTips = _this2.hideSortTips) !== null && _this2$hideSortTips !== void 0 ? _this2$hideSortTips : _this2.globalConfig.hideSortTips) return _this2.getSortIcon(direction, activeClass);
      return vue.createVNode(tooltip_index.Tooltip, vue.mergeProps({
        "content": tips,
        "placement": "right"
      }, _this2.tooltipProps, {
        "showArrow": false,
        "class": _this2.tableSortClasses.iconDirection[direction]
      }), _isSlot(_slot = _this2.getSortIcon(direction, activeClass)) ? _slot : {
        "default": function _default() {
          return [_slot];
        }
      });
    });
    return vue.createVNode("div", {
      "class": classes
    }, [sortButton]);
  }
});

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