/**
 * ldesign v0.4.2
 * (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/isObject');
require('lodash/isString');
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-7f0559c3.js');
require('dayjs');
require('../hooks/useVModel.js');
require('lodash/kebabCase');
require('../utils/dom.js');
require('../utils/easing.js');
require('../_common/js/utils/set-style.js');
require('../popup/container.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../hooks/useResizeObserver.js');
require('lodash/camelCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
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"
      });
    };
    var getSortIcon = function getSortIcon(direction, activeClass) {
      var defaultIcon = t(globalConfig.value.sortIcon) || vue.createVNode(ChevronDownIcon, null, null);
      var icon = renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, tableSortClasses.sortIcon, tableSortClasses.iconDirection[direction], _defineProperty__default["default"]({}, negativeRotate180, direction === "asc")];
      return vue.createVNode("span", {
        "class": sortClassName,
        "onClick": function onClick(e) {
          return onSortIconClick(e, direction);
        }
      }, [icon]);
    };
    return {
      t: t,
      globalConfig: globalConfig,
      tableSortClasses: tableSortClasses,
      negativeRotate180: negativeRotate180,
      allowSortTypes: allowSortTypes,
      getSortIcon: getSortIcon
    };
  },
  render: function render() {
    var _this = 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 _this$hideSortTips;
      var activeClass = direction === _this.sortOrder ? tableSortClasses.iconActive : tableSortClasses.iconDefault;
      var cancelTips = _this.globalConfig.sortCancelOperationText;
      var tips = direction === _this.sortOrder ? cancelTips : tooltips[direction];
      if ((_this$hideSortTips = _this.hideSortTips) !== null && _this$hideSortTips !== void 0 ? _this$hideSortTips : _this.globalConfig.hideSortTips) return _this.getSortIcon(direction, activeClass);
      return vue.createVNode(tooltip_index.Tooltip, vue.mergeProps({
        "content": tips,
        "placement": "right"
      }, _this.tooltipProps, {
        "showArrow": false,
        "class": _this.tableSortClasses.iconDirection[direction]
      }), _isSlot(_slot = _this.getSortIcon(direction, activeClass)) ? _slot : {
        "default": function _default() {
          return [_slot];
        }
      });
    });
    return vue.createVNode("div", {
      "class": classes
    }, [sortButton]);
  }
});

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