/**
 * ldesign v0.4.2
 * (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/isObject';
import 'lodash/isString';
import '../hooks/index.js';
import '../hooks/icon.js';
import '../hooks/slot.js';
import 'lodash/isArray';
import '../hooks/useCommonClassName.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 '../_chunks/dep-2e5d8948.js';
import 'dayjs';
import '../_chunks/dep-4580aabe.js';
import '../config-provider/type.js';
import '../hooks/useDefaultValue.js';
import 'lodash/kebabCase';
import '../hooks/useDestroyOnClose.js';
import '../hooks/useKeepAnimation.js';
import '../hooks/useRipple.js';
import '../utils/set-style.js';
import '../hooks/useVirtualScroll.js';
import '../hooks/useVModel.js';
import 'lodash/camelCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import '../utils/dom.js';
import '../utils/easing.js';
import '../_common/js/utils/set-style.js';
import '../popup/container.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../hooks/useResizeObserver.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"
      });
    };
    var getSortIcon = function getSortIcon(direction, activeClass) {
      var defaultIcon = t(globalConfig.value.sortIcon) || createVNode(ChevronDownIcon$1, null, null);
      var icon = renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, tableSortClasses.sortIcon, tableSortClasses.iconDirection[direction], _defineProperty({}, negativeRotate180, direction === "asc")];
      return 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({}, 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 createVNode(Tooltip, 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 createVNode("div", {
      "class": classes
    }, [sortButton]);
  }
});

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