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

import { _ as _defineProperty } from '../_chunks/dep-eb20e23f.mjs';
import { isVNode, defineComponent, computed, createVNode, mergeProps } from 'vue';
import { ChevronDownIcon } from '@ldesign/icons-vue-next';
import { Tooltip } from '../tooltip/index.mjs';
import '../hooks/useConfig.mjs';
import { useGlobalIcon } from '../hooks/useGlobalIcon.mjs';
import { useTNodeDefault } from '../hooks/tnode.mjs';
import useClassName from './hooks/useClassName.mjs';
import { useConfig } from '../config-provider/useConfig.mjs';
import '../_chunks/dep-b4041200.mjs';
import '../utils/withInstall.mjs';
import '../tooltip/tooltip.mjs';
import '../_chunks/dep-55846619.mjs';
import '../_chunks/dep-cfcedf47.mjs';
import '../_chunks/dep-6b22dd27.mjs';
import '../_chunks/dep-a0b4a044.mjs';
import '../_chunks/dep-c959a6fb.mjs';
import '../_chunks/dep-0f0c89ff.mjs';
import '../_chunks/dep-b2af48ba.mjs';
import '../_chunks/dep-37ba476d.mjs';
import '../_chunks/dep-e3b14d70.mjs';
import '../_chunks/dep-66d6733b.mjs';
import '../_chunks/dep-be27d184.mjs';
import '../_chunks/dep-c31e1d9e.mjs';
import '../_chunks/dep-bf74f1c2.mjs';
import '../_chunks/dep-79821ff2.mjs';
import '../_chunks/dep-0bfbf721.mjs';
import '../_chunks/dep-39cc276d.mjs';
import '../_chunks/dep-8f777748.mjs';
import '../_chunks/dep-ae357f26.mjs';
import '../_chunks/dep-352691c2.mjs';
import '../_chunks/dep-2cfd5b3a.mjs';
import '../_chunks/dep-05fa17c9.mjs';
import '../_chunks/dep-a9c8a5d5.mjs';
import '../_chunks/dep-10085c61.mjs';
import '../_chunks/dep-1b058de3.mjs';
import '../_chunks/dep-c852a61a.mjs';
import '../_chunks/dep-92e7085e.mjs';
import '../_chunks/dep-44f056cd.mjs';
import '../_chunks/dep-23a0f453.mjs';
import '../_chunks/dep-7acc11cb.mjs';
import '../_chunks/dep-59c8420d.mjs';
import '../_chunks/dep-ba3c0b2e.mjs';
import '../_chunks/dep-774ac2d0.mjs';
import '../_chunks/dep-3afa94cf.mjs';
import '../popup/props.mjs';
import '../popup/index.mjs';
import '../popup/popup.mjs';
import '@popperjs/core';
import '../_chunks/dep-1cf2b129.mjs';
import '../hooks/index.mjs';
import '../hooks/icon.mjs';
import '../hooks/slot.mjs';
import '../hooks/useCommonClassName.mjs';
import '../_chunks/dep-44417261.mjs';
import '../_chunks/dep-99920870.mjs';
import '../_chunks/dep-c7e9ce16.mjs';
import '../_chunks/dep-ee57d235.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-6b4aa943.mjs';
import '../_chunks/dep-d52291a9.mjs';
import '../config-provider/type.mjs';
import '../hooks/useDefaultValue.mjs';
import '../_chunks/dep-c4e1a112.mjs';
import '../_chunks/dep-74848b92.mjs';
import '../hooks/useDestroyOnClose.mjs';
import '../hooks/useKeepAnimation.mjs';
import '../hooks/useRipple.mjs';
import '../utils/set-style.mjs';
import '../hooks/useVirtualScroll.mjs';
import '../hooks/useVModel.mjs';
import '../_chunks/dep-f6649a46.mjs';
import '../_chunks/dep-1fe0ad42.mjs';
import '../_chunks/dep-d54f2690.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-bd03960e.mjs';
import '../utils/dom.mjs';
import '../utils/easing.mjs';
import '../_common/js/utils/set-style.mjs';
import '../popup/container.mjs';
import '../_chunks/dep-e091cfd9.mjs';
import '../hooks/useResizeObserver.mjs';
import '../popup/style/css.mjs';
import '../popup/type.mjs';
import '../tooltip/util.mjs';
import '../tooltip/props.mjs';
import '../tooltip/style/css.mjs';
import '../tooltip/type.mjs';

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.mjs.map
