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

import { h as helper } from '../../../chunks/helper.js';
import { defineComponent, computed } from '@vue/composition-api';
import { ChevronDownIcon } from '@ldesign/icons-vue';
import { Tooltip } from '../../tooltip/index.js';
import { useConfig } from '../../config-provider/useConfig.js';
import { useLNodeDefault } from '../../../hooks/lnode.js';
import { useGlobalIcon } from '../../../hooks/use-global-icon.js';
import useClassName from '../hooks/useClassName.js';
import '../../../chunks/_commonjsHelpers.js';
import '../../../utils/map-props.js';
import 'vue';
import '../../../utils/with-install.js';
import 'lodash';
import '../../../config.js';
import '../../tooltip/tooltip.js';
import 'lodash/isFunction';
import '../../popup/props.js';
import '../../popup/popup.js';
import '@popperjs/core';
import '../../../chunks/set-style.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../chunks/index.js';
import '../../../chunks/log.js';
import '../../../chunks/_commonjsHelpers-2e6815bd.js';
import '../../../utils/easing.js';
import '../../../utils/render-node.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/mixins.js';
import '../../popup/container.js';
import '../../tooltip/props.js';
import '../../tooltip/style/css.js';
import '../../tooltip/type.js';
import 'lodash/isEmpty';
import 'lodash/kebabCase';
import '../../../hooks/render-lnode.js';
import '../../../hooks/use-config.js';

var SorterButton = defineComponent({
  props: {
    sortType: {
      type: String,
      default: "all"
    },
    sortOrder: {
      type: String,
      default: () => ""
    },
    sortIcon: Function,
    tooltipProps: Object,
    hideSortTips: Boolean
  },
  setup(props, context) {
    const {
      tableSortClasses,
      negativeRotate180
    } = useClassName();
    const renderLNode = useLNodeDefault();
    const {
      t,
      global
    } = useConfig("table");
    const {
      ChevronDownIcon: ChevronDownIcon$1
    } = useGlobalIcon({
      ChevronDownIcon: ChevronDownIcon
    });
    const allowSortTypes = 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: ChevronDownIcon$1,
      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(Tooltip, 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]);
  }
});

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