"use strict";

exports.__esModule = true;
exports.Button = void 0;
var _react = _interopRequireDefault(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", "ref"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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 (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var Button = exports.Button = function Button(_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,
    ref = _ref.ref,
    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));
};