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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { isVNode, defineComponent, computed, createVNode, mergeProps } from 'vue';
import { ChevronDownIcon } from '@ldesign/icons-vue-next';
import { Tooltip } from '../tooltip/index.js';
import '../hooks/useConfig.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import { useTNodeDefault } from '../hooks/tnode.js';
import useClassName from './hooks/useClassName.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../utils/withInstall.js';
import '../tooltip/tooltip.js';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isFunction';
import 'lodash/omit';
import '../popup/props.js';
import '../popup/index.js';
import '../popup/popup.js';
import '@popperjs/core';
import 'lodash/isString';
import 'lodash/isObject';
import '../utils/dom.js';
import '../_chunks/dep-512eb181.js';
import 'lodash/isArray';
import '../utils/easing.js';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../_common/js/utils/set-style.js';
import '../hooks/useVModel.js';
import '../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import 'lodash/isUndefined';
import '../hooks/useResizeObserver.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';
import '../_chunks/dep-ac28b67c.js';
import '../config-provider/type.js';
import '../popup/style';
import '../popup/type.js';
import '../tooltip/util.js';
import '../tooltip/props.js';
import '../tooltip/style';
import '../tooltip/type.js';

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var SorterButton = 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 = useClassName(),
      tableSortClasses = _useClassName.tableSortClasses,
      negativeRotate180 = _useClassName.negativeRotate180;
    var renderTNode = useTNodeDefault();
    var _useConfig = useConfig("table"),
      t = _useConfig.t,
      globalConfig = _useConfig.globalConfig;
    var _useGlobalIcon = useGlobalIcon({
        ChevronDownIcon: ChevronDownIcon
      }),
      ChevronDownIcon$1 = _useGlobalIcon.ChevronDownIcon;
    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,
      globalConfig: globalConfig,
      ChevronDownIcon: ChevronDownIcon$1,
      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) || createVNode(ChevronDownIcon, null, null);
      var icon = this.renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, this.tableSortClasses.sortIcon, this.tableSortClasses.iconDirection[direction], _defineProperty({}, this.negativeRotate180, direction === "asc")];
      return 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({}, 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 createVNode(Tooltip, 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 createVNode("div", {
      "class": classes
    }, [sortButton]);
  }
});

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