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

'use strict';

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

var helper = require('../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var tooltip_index = require('../tooltip/index.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var table_hooks_useClassName = require('./hooks/useClassName.js');
require('../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../utils/withInstall.js');
require('lodash/capitalize');
require('../tooltip/tooltip.js');
require('lodash/isFunction');
require('../popup/props.js');
require('../popup/popup.js');
require('@babel/runtime/helpers/typeof');
require('@popperjs/core');
require('../utils/dom.js');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('../utils/render-tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('../_common/js/utils/set-style.js');
require('../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../utils/event.js');
require('../popup/container.js');
require('../popup/utils.js');
require('../popup/trigger.js');
require('../tooltip/props.js');
require('lodash/isEmpty');
require('../hooks/render-tnode.js');
require('lodash/isObject');

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

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

var SorterButton = VueCompositionAPI.defineComponent({
  props: {
    sortType: {
      type: String,
      "default": "all"
    },
    sortOrder: {
      type: String,
      "default": function _default() {
        return "";
      }
    },
    sortIcon: Function,
    tooltipProps: Object,
    hideSortTips: Boolean
  },
  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,
      global = _useConfig.global;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        ChevronDownIcon: iconsVue.ChevronDownIcon
      }),
      ChevronDownIcon = _useGlobalIcon.ChevronDownIcon;
    var allowSortTypes = VueCompositionAPI.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,
      global: global,
      ChevronDownIcon: ChevronDownIcon,
      tableSortClasses: tableSortClasses,
      negativeRotate180: negativeRotate180,
      allowSortTypes: allowSortTypes,
      onSortIconClick: onSortIconClick,
      renderTNode: renderTNode
    };
  },
  methods: {
    getSortIcon: function getSortIcon(direction, activeClass) {
      var _this = this;
      var h = this.$createElement;
      var ChevronDownIcon = this.ChevronDownIcon;
      var defaultIcon = this.t(this.global.sortIcon) || h(ChevronDownIcon);
      var icon = this.renderTNode("sortIcon", defaultIcon);
      var sortClassName = [activeClass, this.tableSortClasses.sortIcon, this.tableSortClasses.iconDirection[direction], _defineProperty__default["default"]({}, this.negativeRotate180, direction === "asc")];
      return h("span", {
        "class": sortClassName,
        "on": {
          "click": function click(e) {
            return _this.onSortIconClick(e, direction);
          }
        }
      }, [icon]);
    }
  },
  render: function render() {
    var _this2 = this;
    var h = arguments[0];
    var tableSortClasses = this.tableSortClasses;
    var classes = [tableSortClasses.trigger, _defineProperty__default["default"]({}, tableSortClasses.doubleIcon, this.allowSortTypes.length > 1)];
    var tooltips = {
      asc: this.global.sortAscendingOperationText,
      desc: this.global.sortDescendingOperationText
    };
    var sortButton = this.allowSortTypes.map(function (direction) {
      var _this2$hideSortTips;
      var activeClass = direction === _this2.sortOrder ? tableSortClasses.iconActive : tableSortClasses.iconDefault;
      var cancelTips = _this2.global.sortCancelOperationText;
      var tips = direction === _this2.sortOrder ? cancelTips : tooltips[direction];
      if ((_this2$hideSortTips = _this2.hideSortTips) !== null && _this2$hideSortTips !== void 0 ? _this2$hideSortTips : _this2.global.hideSortTips) return _this2.getSortIcon(direction, activeClass);
      return h(tooltip_index.Tooltip, helper.helper([{
        "attrs": {
          "content": tips,
          "placement": "right"
        }
      }, _this2.tooltipProps, {
        "attrs": {
          "showArrow": false
        },
        "class": _this2.tableSortClasses.iconDirection[direction]
      }]), [_this2.getSortIcon(direction, activeClass)]);
    });
    return h("div", {
      "class": classes
    }, [sortButton]);
  }
});

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