/**
 * ldesign v0.2.3
 * (c) 2022年9月24日 swimly
 * @license MIT
 */

import { Icon } from '@ldesign/icons-vue';
import { Loading } from '../loading/index.js';
import props from './props.js';
import { renderContent, renderLNodeJSX } from '../../utils/render-node.js';
import Ripple from '../../utils/ripple.js';
import { getKeepAnimationMixins, getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../../utils/mixins.js';
import '../loading/loading.js';
import '../loading/icon/gradient.js';
import 'vue';
import '../../_chunks/dep-1dd6d50e.js';
import '../../_chunks/dep-1aed710a.js';
import '../../_chunks/dep-d640115b.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../utils/easing.js';
import '../../utils/transfer-dom.js';
import '../loading/props.js';
import '../../utils/with-install.js';
import 'lodash';
import '../loading/plugin.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-b1584b65.js';

const keepAnimationMixins = getKeepAnimationMixins();
const classPrefixMixins = getClassPrefixMixins("button");
var LButton = mixins(keepAnimationMixins, classPrefixMixins).extend({
  name: "LButton",
  components: {
    LLoading: Loading,
    LIcon: Icon
  },
  props: { ...props
  },
  directives: {
    ripple: Ripple
  },

  render(h) {
    const {
      componentName: NAME,
      commonStatusClassName: STATUS,
      commonSizeClassName: SIZE
    } = this;
    let buttonContent = renderContent(this, "default", "content");
    const iconNode = typeof this.icon === "string" && this.icon ? h("l-icon", {
      "attrs": {
        "name": this.icon
      }
    }) : renderLNodeJSX(this, "icon");
    const icon = this.loading ? h("l-loading", {
      "attrs": {
        "inheritColor": true
      }
    }) : iconNode;
    const disabled = this.disabled || this.loading;
    let {
      theme
    } = this;

    if (!this.theme) {
      if (this.variant === "base") {
        theme = "primary";
      } else {
        theme = "default";
      }
    }

    const buttonClass = [`${NAME}`, SIZE[this.size], `${NAME}--variant-${this.variant}`, `${NAME}--theme-${theme}`, {
      [STATUS.disabled]: this.disabled,
      [STATUS.loading]: this.loading,
      [`${NAME}--shape-${this.shape}`]: this.shape !== "rectangle",
      [`${NAME}--ghost`]: this.ghost,
      [SIZE.block]: this.block
    }];
    buttonContent = buttonContent ? h("span", {
      "class": `${NAME}__text`
    }, [buttonContent]) : "";

    if (icon) {
      buttonContent = [icon, buttonContent];
    }

    const on = { ...this.$listeners
    };

    if (typeof this.onClick === "function") {
      on.click = this.onClick;
    }

    const buttonAttrs = {
      type: this.type,
      disabled,
      href: this.href
    };

    const renderTag = () => {
      if (!this.tag && this.href) return "a";
      return this.tag || "button";
    };

    return h(renderTag(), {
      class: buttonClass,
      attrs: buttonAttrs,
      on,
      directives: [{
        name: "ripple",
        value: this.keepAnimation.ripple
      }]
    }, [buttonContent]);
  }

});

export { LButton as default };
//# sourceMappingURL=button.js.map
