'use strict';

var HoverableElement = require('./HoverableElement.js');
var index = require('../Typo/index.js');
var antd = require('antd');
var cs = require('classnames');
var React = require('react');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var cs__default = /*#__PURE__*/_interopDefault(cs);
var React__default = /*#__PURE__*/_interopDefault(React);

var __defProp = Object.defineProperty;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
  enumerable: true,
  configurable: true,
  writable: true,
  value
}) : obj[key] = value;
var __spreadValues = (a, b) => {
  for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
  if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
    if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
  }
  return a;
};
var __objRest = (source, exclude) => {
  var target = {};
  for (var prop in source) if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0) target[prop] = source[prop];
  if (source != null && __getOwnPropSymbols) for (var prop of __getOwnPropSymbols(source)) {
    if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop)) target[prop] = source[prop];
  }
  return target;
};
const ButtonStyle = "E_4100_0_7_b1wx3t3t";
const isAntdButtonTypes = type => {
  return Boolean(type && ["default", "primary", "ghost", "dashed", "link", "text"].includes(type));
};
const Button = React__default.default.forwardRef((props, ref) => {
  const _a = props,
    {
      type,
      className,
      children,
      prefixIcon,
      hoverPrefixIcon,
      suffixIcon,
      hoverSuffixIcon,
      onMouseEnter,
      onMouseLeave,
      size = "middle"
    } = _a,
    restProps = __objRest(_a, ["type", "className", "children", "prefixIcon", "hoverPrefixIcon", "suffixIcon", "hoverSuffixIcon", "onMouseEnter", "onMouseLeave", "size"]);
  const [status, setStatus] = React.useState("normal");
  const hasIcon = prefixIcon || suffixIcon;
  const hasHoverIcon = hoverPrefixIcon || hoverSuffixIcon;
  const onlyIcon = !children && (prefixIcon || suffixIcon);
  return /* @__PURE__ */React__default.default.createElement(antd.Button, __spreadValues({
    ref,
    className: cs__default.default(className, ButtonStyle, size === "large" && index.Typo.Label.l1_regular_title, size === "middle" && index.Typo.Label.l2_regular_title, size === "small" && index.Typo.Label.l3_regular_title, type && `ant-btn-${type}`, onlyIcon && "ant-btn-icon-only"),
    type: isAntdButtonTypes(type) ? type : void 0,
    onMouseEnter: e => {
      onMouseEnter == null ? void 0 : onMouseEnter(e);
      if (hasIcon && hasHoverIcon) {
        setStatus("hover");
      }
    },
    onMouseLeave: e => {
      onMouseLeave == null ? void 0 : onMouseLeave(e);
      if (hasIcon && hasHoverIcon) {
        setStatus("normal");
      }
    },
    size
  }, restProps), prefixIcon && /* @__PURE__ */React__default.default.createElement(HoverableElement, {
    icon: prefixIcon,
    hoverEle: hoverPrefixIcon,
    hover: status === "hover",
    className: !onlyIcon ? "button-prefix-icon" : ""
  }), children, suffixIcon && /* @__PURE__ */React__default.default.createElement(HoverableElement, {
    icon: suffixIcon,
    hoverEle: hoverSuffixIcon,
    hover: status === "hover",
    className: !onlyIcon ? "button-suffix-icon" : ""
  }));
});
var Button$1 = Button;

module.exports = Button$1;
