/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var helper = require('../../../chunks/helper.js');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var components_tooltip_index = require('../../tooltip/index.js');
var components_configProvider_useConfig = require('../../config-provider/useConfig.js');
var hooks_lnode = require('../../../hooks/lnode.js');
var hooks_useGlobalIcon = require('../../../hooks/use-global-icon.js');
var components_table_hooks_useClassName = require('../hooks/useClassName.js');
require('../../../utils/map-props.js');
require('vue');
require('../../../utils/with-install.js');
require('lodash');
require('../../../config.js');
require('../../tooltip/tooltip.js');
require('lodash/isFunction');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../../chunks/set-style.js');
require('../../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../../chunks/log.js');
require('../../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../../utils/easing.js');
require('../../../utils/render-node.js');
require('../../../utils/helper.js');
require('lodash/camelCase');
require('../../config-provider/config-receiver.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('../../../chunks/zh_CN.js');
require('../../../utils/mixins.js');
require('../../popup/container.js');
require('../../tooltip/props.js');
require('lodash/isEmpty');
require('lodash/kebabCase');
require('../../../hooks/render-lnode.js');

var SorterButton = VueCompositionAPI.defineComponent({
  props: {
    sortType: {
      type: String,
      default: "all"
    },
    sortOrder: {
      type: String,
      default: () => ""
    },
    sortIcon: Function,
    tooltipProps: Object,
    hideSortTips: Boolean
  },
  setup(props, context) {
    const {
      tableSortClasses,
      negativeRotate180
    } = components_table_hooks_useClassName["default"]();
    const renderLNode = hooks_lnode.useLNodeDefault();
    const {
      t,
      global
    } = components_configProvider_useConfig.useConfig("table");
    const {
      ChevronDownIcon
    } = hooks_useGlobalIcon.useGlobalIcon({
      ChevronDownIcon: iconsVue.ChevronDownIcon
    });
    const allowSortTypes = VueCompositionAPI.computed(() => props.sortType === "all" ? ["asc", "desc"] : [props.sortType]);
    const onSortIconClick = (e, direction) => {
      context.emit("sort-icon-click", e, {
        descending: direction === "desc"
      });
    };
    return {
      t,
      global,
      ChevronDownIcon,
      tableSortClasses,
      negativeRotate180,
      allowSortTypes,
      onSortIconClick,
      renderLNode
    };
  },
  methods: {
    getSortIcon(direction, activeClass) {
      const h = this.$createElement;
      const {
        ChevronDownIcon
      } = this;
      const defaultIcon = this.t(this.global.sortIcon) || h(ChevronDownIcon);
      const icon = this.renderLNode("sortIcon", defaultIcon);
      const sortClassName = [activeClass, this.tableSortClasses.sortIcon, this.tableSortClasses.iconDirection[direction], {
        [this.negativeRotate180]: direction === "asc"
      }];
      return h("span", {
        "class": sortClassName,
        "on": {
          "click": e => this.onSortIconClick(e, direction)
        }
      }, [icon]);
    }
  },
  render() {
    const h = arguments[0];
    const {
      tableSortClasses
    } = this;
    const classes = [tableSortClasses.trigger, {
      [tableSortClasses.doubleIcon]: this.allowSortTypes.length > 1
    }];
    const tooltips = {
      asc: this.global.sortAscendingOperationText,
      desc: this.global.sortDescendingOperationText
    };
    const sortButton = this.allowSortTypes.map(direction => {
      const activeClass = direction === this.sortOrder ? tableSortClasses.iconActive : tableSortClasses.iconDefault;
      const cancelTips = this.global.sortCancelOperationText;
      const tips = direction === this.sortOrder ? cancelTips : tooltips[direction];
      if (this.hideSortTips ?? this.global.hideSortTips) return this.getSortIcon(direction, activeClass);
      return h(components_tooltip_index.Tooltip, helper.helper([{
        "attrs": {
          "content": tips,
          "placement": "right"
        }
      }, this.tooltipProps, {
        "attrs": {
          "showArrow": false
        },
        "class": this.tableSortClasses.iconDirection[direction]
      }]), [this.getSortIcon(direction, activeClass)]);
    });
    return h("div", {
      "class": classes
    }, [sortButton]);
  }
});

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