"use strict";

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

var _styledBase = require("@emotion/styled-base");

var _styledBase2 = _interopRequireDefault(_styledBase);

var _react = require("react");

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(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 = exports.SkeletonStyledComponent = (
/*#__PURE__*/
0, _styledBase2["default"])("button", {
  target: "e1111t2i0",
  label: "SkeletonStyledComponent"
})(process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jb21wb25lbnRzL0J1dHRvbi9CdXR0b24uU2tlbGV0b24uanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBTXVEIiwiZmlsZSI6Ii4uLy4uLy4uL3NyYy9jb21wb25lbnRzL0J1dHRvbi9CdXR0b24uU2tlbGV0b24uanMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgUmVhY3QsIHsgRnJhZ21lbnQgfSBmcm9tIFwicmVhY3RcIlxuaW1wb3J0IFByb3BUeXBlcyBmcm9tIFwicHJvcC10eXBlc1wiXG5pbXBvcnQgc3R5bGVkIGZyb20gXCJAZW1vdGlvbi9zdHlsZWRcIlxuaW1wb3J0IHsgTWRSZWZyZXNoIH0gZnJvbSBcInJlYWN0LWljb25zL21kXCJcbmltcG9ydCB7IExpbmsgfSBmcm9tIFwiZ2F0c2J5XCJcblxuZXhwb3J0IGNvbnN0IFNrZWxldG9uU3R5bGVkQ29tcG9uZW50ID0gc3R5bGVkKGBidXR0b25gKWBgXG5cbmV4cG9ydCBjb25zdCBidXR0b25Qcm9wVHlwZXMgPSB7XG4gIGRpc2FibGVkOiBQcm9wVHlwZXMuYm9vbCxcbiAgbG9hZGluZzogUHJvcFR5cGVzLmJvb2wsXG4gIGxvYWRpbmdMYWJlbDogUHJvcFR5cGVzLnN0cmluZyxcbiAgaHJlZjogUHJvcFR5cGVzLnN0cmluZyxcbiAgc2l6ZTogUHJvcFR5cGVzLnN0cmluZyxcbiAgdG86IFByb3BUeXBlcy5zdHJpb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AgICAgIDxDb21wb25lbnRBc0ludGVybmFsTGluayB0bz17dG99IHsuLi5yZXN0fT5cbiAgICAgICAge2NoaWxkcmVufVxuICAgICAgPC9Db21wb25lbnRBc0ludGVybmFsTGluaz5cbiAgICApXG4gIH1cblxuICByZXR1cm4gKFxuICAgIDxTdHlsZWRDb21wb25lbnQgZGlzYWJsZWQ9e2Rpc2FibGVkfSBzaG93TG9hZGluZz17bG9hZGluZ30gey4uLnJlc3R9PlxuICAgICAge2xvYWRpbmcgPyAoXG4gICAgICAgIDxGcmFnbWVudD5cbiAgICAgICAgICB7bG9hZGluZ0xhYmVsfSA8TWRSZWZyZXNoIC8+XG4gICAgICAgIDwvRnJhZ21lbnQ+XG4gICAgICApIDogKFxuICAgICAgICBjaGlsZHJlblxuICAgICAgKX1cbiAgICA8L1N0eWxlZENvbXBvbmVudD5cbiAgKVxufVxuXG5CdXR0b25Ta2VsZXRvbi5wcm9wVHlwZXMgPSBidXR0b25Ta2VsZXRvblByb3BUeXBlc1xuQnV0dG9uU2tlbGV0b24uZGVmYXVsdFByb3BzID0gYnV0dG9uU2tlbGV0b25EZWZhdWx0UHJvcFR5cGVzXG5cbmV4cG9ydCBkZWZhdWx0IEJ1dHRvblNrZWxldG9uXG4iXX0= */");
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",
      label: "ComponentAsExternalLink"
    });
    return _react2["default"].createElement(ComponentAsExternalLink, Object.assign({
      href: href
    }, rest), children);
  }

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

  return _react2["default"].createElement(StyledComponent, Object.assign({
    disabled: disabled,
    showLoading: 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;