"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const Vue = require("vue");
const useRoute = require("../composables/use-route.js");
const index = require("../icon/index.js");
const index$1 = require("../loading/index.js");
const constant = require("../utils/constant.js");
const dom = require("../utils/dom.js");
const create = require("../utils/create.js");
const basic = require("../utils/basic.js");
const props = require("../utils/props.js");
const [name, bem] = create.createNamespace("button");
const buttonProps = basic.extend({}, useRoute.routeProps, {
  tag: props.makeStringProp("button"),
  text: String,
  icon: String,
  type: props.makeStringProp("default"),
  size: props.makeStringProp("normal"),
  color: String,
  block: Boolean,
  plain: Boolean,
  round: Boolean,
  square: Boolean,
  loading: Boolean,
  hairline: Boolean,
  disabled: Boolean,
  iconPrefix: String,
  nativeType: props.makeStringProp("button"),
  loadingSize: props.numericProp,
  loadingText: String,
  loadingType: String,
  iconPosition: props.makeStringProp("left")
});
var stdin_default = Vue.defineComponent({
  name,
  props: buttonProps,
  emits: ["click"],
  setup(props2, {
    emit,
    slots
  }) {
    const route = useRoute.useRoute();
    const renderLoadingIcon = () => {
      if (slots.loading) {
        return slots.loading();
      }
      return Vue.createVNode(index$1.Loading, {
        "size": props2.loadingSize,
        "type": props2.loadingType,
        "class": bem("loading")
      }, null);
    };
    const renderIcon = () => {
      if (props2.loading) {
        return renderLoadingIcon();
      }
      if (slots.icon) {
        return Vue.createVNode("div", {
          "class": bem("icon")
        }, [slots.icon()]);
      }
      if (props2.icon) {
        return Vue.createVNode(index.Icon, {
          "name": props2.icon,
          "class": bem("icon"),
          "classPrefix": props2.iconPrefix
        }, null);
      }
    };
    const renderText = () => {
      let text;
      if (props2.loading) {
        text = props2.loadingText;
      } else {
        text = slots.default ? slots.default() : props2.text;
      }
      if (text) {
        return Vue.createVNode("span", {
          "class": bem("text")
        }, [text]);
      }
    };
    const getStyle = () => {
      const {
        color,
        plain
      } = props2;
      if (color) {
        const style = {
          color: plain ? color : "white"
        };
        if (!plain) {
          style.background = color;
        }
        if (color.includes("gradient")) {
          style.border = 0;
        } else {
          style.borderColor = color;
        }
        return style;
      }
    };
    const onClick = (event) => {
      if (props2.loading) {
        dom.preventDefault(event);
      } else if (!props2.disabled) {
        emit("click", event);
        route();
      }
    };
    return () => {
      const {
        tag,
        type,
        size,
        block,
        round,
        plain,
        square,
        loading,
        disabled,
        hairline,
        nativeType,
        iconPosition
      } = props2;
      const classes = [bem([type, size, {
        plain,
        block,
        round,
        square,
        loading,
        disabled,
        hairline
      }]), {
        [constant.BORDER_SURROUND]: hairline
      }];
      return Vue.createVNode(tag, {
        "type": nativeType,
        "class": classes,
        "style": getStyle(),
        "disabled": disabled,
        "onClick": onClick
      }, {
        default: () => [Vue.createVNode("div", {
          "class": bem("content")
        }, [iconPosition === "left" && renderIcon(), renderText(), iconPosition === "right" && renderIcon()])]
      });
    };
  }
});
exports.buttonProps = buttonProps;
exports.default = stdin_default;
