import { defineComponent, resolveDirective, withDirectives, openBlock, createElementBlock, normalizeClass, unref, normalizeStyle, renderSlot, createCommentVNode, createVNode, withCtx, createBlock, resolveDynamicComponent, vShow } from 'vue';
import { ElIcon } from '../../icon/index.mjs';
import '../../../hooks/index.mjs';
import { useButton } from './use-button.mjs';
import { buttonProps, buttonEmits } from './button.mjs';
import { useButtonCustomStyle } from './button-custom.mjs';
import _export_sfc from '../../../../_virtual/plugin-vue_export-helper.mjs';
import { useNamespace } from '../../../hooks/use-namespace/index.mjs';

const _hoisted_1 = ["data-loading-type", "aria-disabled", "disabled", "autofocus", "type"];
const __default__ = defineComponent({
  name: "ElButton"
});
const _sfc_main = /* @__PURE__ */ defineComponent({
  ...__default__,
  props: buttonProps,
  emits: buttonEmits,
  setup(__props, { expose, emit }) {
    const props = __props;
    const buttonStyle = useButtonCustomStyle(props);
    const ns = useNamespace("button");
    const { _ref, _size, _type, _link, _disabled, shouldAddSpace, handleClick } = useButton(props, emit);
    expose({
      ref: _ref,
      size: _size,
      type: _type,
      disabled: _disabled,
      shouldAddSpace
    });
    return (_ctx, _cache) => {
      const _directive_http_loading = resolveDirective("http-loading");
      return withDirectives((openBlock(), createElementBlock("button", {
        ref_key: "_ref",
        ref: _ref,
        "data-loading-type": _ctx.loadingType,
        class: normalizeClass([
          unref(ns).b(),
          unref(ns).m(unref(_type)),
          unref(ns).m(unref(_size)),
          unref(ns).is("disabled", unref(_disabled)),
          unref(ns).is("border", _ctx.border),
          unref(ns).is("loading", _ctx.loading),
          unref(ns).is("plain", _ctx.plain),
          unref(ns).is("round", _ctx.round),
          unref(ns).is("circle", _ctx.circle),
          unref(ns).is("text", _ctx.text),
          unref(ns).is("link", unref(_link)),
          unref(ns).is("has-bg", _ctx.bg)
        ]),
        "aria-disabled": unref(_disabled) || _ctx.loading,
        disabled: unref(_disabled) || _ctx.loading,
        autofocus: _ctx.autofocus,
        type: _ctx.nativeType,
        style: normalizeStyle(unref(buttonStyle)),
        onClick: _cache[0] || (_cache[0] = (...args) => unref(handleClick) && unref(handleClick)(...args))
      }, [
        _ctx.$slots.loading ? renderSlot(_ctx.$slots, "loading", { key: 0 }) : createCommentVNode("v-if", true),
        withDirectives(createVNode(unref(ElIcon), {
          "data-business-loading-icon": "",
          class: normalizeClass(unref(ns).is("loading")),
          size: "16"
        }, {
          default: withCtx(() => [
            (openBlock(), createBlock(resolveDynamicComponent(_ctx.loadingIcon)))
          ]),
          _: 1
        }, 8, ["class"]), [
          [vShow, _ctx.loading && !_ctx.$slots.loading && _ctx.showLoading]
        ]),
        !_ctx.loading && (_ctx.icon || _ctx.$slots.icon) && _ctx.showLoading ? (openBlock(), createBlock(unref(ElIcon), {
          key: 1,
          size: "16"
        }, {
          default: withCtx(() => [
            _ctx.icon ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.icon), { key: 0 })) : renderSlot(_ctx.$slots, "icon", { key: 1 })
          ]),
          _: 3
        })) : createCommentVNode("v-if", true),
        _ctx.$slots.default ? (openBlock(), createElementBlock("span", {
          key: 2,
          style: normalizeStyle({
            marginLeft: _ctx.loading && !_ctx.$slots.loading || !_ctx.loading && (_ctx.icon || _ctx.$slots.icon) ? "4px" : "0"
          }),
          class: normalizeClass({ [unref(ns).em("text", "expand")]: unref(shouldAddSpace) })
        }, [
          renderSlot(_ctx.$slots, "default")
        ], 6)) : createCommentVNode("v-if", true)
      ], 14, _hoisted_1)), [
        [_directive_http_loading, _ctx.loadingGroup, _ctx.loadingType]
      ]);
    };
  }
});
var Button = /* @__PURE__ */ _export_sfc(_sfc_main, [["__file", "/home/lxj/workspace/element-plus/packages/components/button/src/button.vue"]]);

export { Button as default };
//# sourceMappingURL=button2.mjs.map
