"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buttonSkeletonDefaultPropTypes = exports.buttonDefaultPropTypes = exports.buttonPropTypes = exports.SkeletonStyledComponent = undefined;

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

var _propTypes = require("prop-types");

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactEmotion = require("react-emotion");

var _reactEmotion2 = _interopRequireDefault(_reactEmotion);

var _md = require("react-icons/md");

var _gatsby = require("gatsby");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var SkeletonStyledComponent =
/*#__PURE__*/
exports.SkeletonStyledComponent = (0, _reactEmotion2["default"])("button", {
  target: "e1111t2i0"
})();
var buttonPropTypes = exports.buttonPropTypes = {
  disabled: _propTypes2["default"].bool,
  loading: _propTypes2["default"].bool,
  loadingLabel: _propTypes2["default"].string,
  href: _propTypes2["default"].string,
  size: _propTypes2["default"].string,
  to: _propTypes2["default"].string
};

var buttonSkeletonPropTypes = _objectSpread({}, buttonPropTypes, {
  StyledComponent: _propTypes2["default"].any
});

var buttonDefaultPropTypes = exports.buttonDefaultPropTypes = {
  disabled: false,
  loading: false,
  loadingLabel: "Loading",
  size: "L"
};

var buttonSkeletonDefaultPropTypes = exports.buttonSkeletonDefaultPropTypes = _objectSpread({}, buttonDefaultPropTypes, {
  StyledComponent: SkeletonStyledComponent
});

var ButtonSkeleton = function ButtonSkeleton(_ref) {
  var StyledComponent = _ref.StyledComponent,
      children = _ref.children,
      disabled = _ref.disabled,
      href = _ref.href,
      loading = _ref.loading,
      loadingLabel = _ref.loadingLabel,
      to = _ref.to,
      rest = _objectWithoutProperties(_ref, ["StyledComponent", "children", "disabled", "href", "loading", "loadingLabel", "to"]);

  if (href) {
    var ComponentAsExternalLink = StyledComponent.withComponent("a", {
      target: "e1111t2i1"
    });
    return _react2["default"].createElement(ComponentAsExternalLink, Object.assign({
      href: href
    }, rest), children);
  }

  if (to) {
    var ComponentAsInternalLink = StyledComponent.withComponent(_gatsby.Link, {
      target: "e1111t2i2"
    });
    return _react2["default"].createElement(ComponentAsInternalLink, Object.assign({
      to: to
    }, rest), children);
  }

  return _react2["default"].createElement(StyledComponent, Object.assign({
    disabled: disabled,
    loading: loading
  }, rest), loading ? _react2["default"].createElement(_react.Fragment, null, loadingLabel, " ", _react2["default"].createElement(_md.MdRefresh, null)) : children);
};

ButtonSkeleton.propTypes = buttonSkeletonPropTypes;
ButtonSkeleton.defaultProps = buttonSkeletonDefaultPropTypes;
exports["default"] = ButtonSkeleton;