"use strict";

exports.__esModule = true;
exports.Button = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styled = require("./styled");
var _icon = require("../icon");
var _components = require("../icon/components");
var _flex = _interopRequireDefault(require("../templates/flex"));
var _excluded = ["label", "icon", "flavour", "isLoading", "loadingLabel", "onClick", "textTransform", "iconColor", "iconSize", "iconWidth", "iconHeight", "children"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
var Button = exports.Button = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var label = _ref.label,
    _ref$icon = _ref.icon,
    icon = _ref$icon === void 0 ? null : _ref$icon,
    flavour = _ref.flavour,
    isLoading = _ref.isLoading,
    loadingLabel = _ref.loadingLabel,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    _ref$textTransform = _ref.textTransform,
    textTransform = _ref$textTransform === void 0 ? "firstLetter" : _ref$textTransform,
    iconColor = _ref.iconColor,
    iconSize = _ref.iconSize,
    iconWidth = _ref.iconWidth,
    iconHeight = _ref.iconHeight,
    _ref$children = _ref.children,
    children = _ref$children === void 0 ? label : _ref$children,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  return /*#__PURE__*/_react["default"].createElement(_styled.StyledButton, _extends({
    flavour: flavour,
    textTransform: textTransform,
    hasIcon: !!icon || isLoading,
    onClick: isLoading ? undefined : onClick,
    ref: ref,
    iconColor: iconColor,
    iconWidth: iconWidth,
    iconHeight: iconHeight
  }, rest), isLoading && /*#__PURE__*/_react["default"].createElement(_components.LoaderIcon, {
    className: "button-icon"
  }), icon && !isLoading && /*#__PURE__*/_react["default"].createElement(_flex["default"], {
    justifyContent: "center",
    alignItems: "center",
    width: "auto",
    height: "100%"
  }, /*#__PURE__*/_react["default"].createElement(_icon.Icon, {
    size: iconSize,
    className: "button-icon",
    title: icon,
    name: icon,
    width: iconWidth,
    height: iconHeight
  })), !!children && /*#__PURE__*/_react["default"].createElement("span", null, isLoading && loadingLabel || children));
});