<template>
  <button
    :class="buttonClass"
    :style="buttonStyle"
    :disabled="isDisabled || loading"
    :hover-class="bem.m('hover')"
    @click="onClick"
  >
    <view
      v-if="loading"
      :class="
        classNames(
          bem.e('loading'),
          bem.em('loading', 'with-slot', !!$slots.default),
        )
      "
    >
      <sar-loading size="inherit" color="inherit" :type="loadingType" />
    </view>
    <slot></slot>
  </button>
</template>

<script lang="ts">
import { defineComponent as _defineComponent } from "vue";
import { computed } from "vue";
import { classNames, stringifyStyle, createBem } from "../utils";
import SarLoading from "../loading/loading.vue";
import { useFormContext } from "../form/common";
import { buttonProps } from "./common";
const __default__ = {
  options: {
    virtualHost: true,
    styleIsolation: "shared"
  }
};
export default /* @__PURE__ */ _defineComponent({
  ...__default__,
  __name: "button",
  props: buttonProps,
  emits: ["click"],
  setup(__props, { expose: __expose, emit: __emit }) {
    __expose();
    const props = __props;
    const emit = __emit;
    const bem = createBem("button");
    const formContext = useFormContext();
    const isDisabled = computed(() => {
      return formContext?.disabled ?? props.disabled;
    });
    const onClick = (event) => {
      emit("click", event);
    };
    const buttonClass = computed(() => {
      return classNames(
        bem.b(),
        bem.m(props.size),
        bem.m(props.type),
        bem.m(`${props.type}-${props.theme}`),
        bem.m("round", props.round),
        bem.m("disabled", isDisabled.value),
        bem.m("loading", props.loading),
        props.rootClass
      );
    });
    const buttonStyle = computed(() => {
      return stringifyStyle(
        {
          color: props.color,
          background: props.background
        },
        props.rootStyle
      );
    });
    const __returned__ = { props, emit, bem, formContext, isDisabled, onClick, buttonClass, buttonStyle, get classNames() {
      return classNames;
    }, SarLoading };
    return __returned__;
  }
});
</script>

<style lang="scss">
@use './index.scss';
</style>