text: "use strict";
  /*
   * Copyright 2017-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
   * the License. A copy of the License is located at
   *
   *     http://aws.amazon.com/apache2.0/
   *
   * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
   * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
   * and limitations under the License.
   */
  var __extends = (this && this.__extends) || (function () {
      var extendStatics = function (d, b) {
          extendStatics = Object.setPrototypeOf ||
              ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
              function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
          return extendStatics(d, b);
      };
      return function (d, b) {
          extendStatics(d, b);
          function __() { this.constructor = d; }
          d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
      };
  })();
  var __assign = (this && this.__assign) || function () {
      __assign = Object.assign || function(t) {
          for (var s, i = 1, n = arguments.length; i < n; i++) {
              s = arguments[i];
              for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                  t[p] = s[p];
          }
          return t;
      };
      return __assign.apply(this, arguments);
  };
  function __export(m) {
      for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
  }
  var __importStar = (this && this.__importStar) || function (mod) {
      if (mod && mod.__esModule) return mod;
      var result = {};
      if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
      result["default"] = mod;
      return result;
  };
  Object.defineProperty(exports, "__esModule", { value: true });
  var React = __importStar(require("react"));
  var Authenticator_1 = require("./Authenticator");
  var Authenticator_2 = require("./Authenticator");
  exports.Authenticator = Authenticator_2.Authenticator;
  var AuthPiece_1 = require("./AuthPiece");
  exports.AuthPiece = AuthPiece_1.AuthPiece;
  var SignIn_1 = require("./SignIn");
  exports.SignIn = SignIn_1.SignIn;
  var ConfirmSignIn_1 = require("./ConfirmSignIn");
  exports.ConfirmSignIn = ConfirmSignIn_1.ConfirmSignIn;
  var SignOut_1 = require("./SignOut");
  exports.SignOut = SignOut_1.SignOut;
  var RequireNewPassword_1 = require("./RequireNewPassword");
  exports.RequireNewPassword = RequireNewPassword_1.RequireNewPassword;
  var SignUp_1 = require("./SignUp");
  exports.SignUp = SignUp_1.SignUp;
  var ConfirmSignUp_1 = require("./ConfirmSignUp");
  exports.ConfirmSignUp = ConfirmSignUp_1.ConfirmSignUp;
  var VerifyContact_1 = require("./VerifyContact");
  exports.VerifyContact = VerifyContact_1.VerifyContact;
  var ForgotPassword_1 = require("./ForgotPassword");
  exports.ForgotPassword = ForgotPassword_1.ForgotPassword;
  var Greetings_1 = require("./Greetings");
  exports.Greetings = Greetings_1.Greetings;
  var FederatedSignIn_1 = require("./FederatedSignIn");
  exports.FederatedSignIn = FederatedSignIn_1.FederatedSignIn;
  exports.FederatedButtons = FederatedSignIn_1.FederatedButtons;
  var TOTPSetup_1 = require("./TOTPSetup");
  exports.TOTPSetup = TOTPSetup_1.TOTPSetup;
  var Loading_1 = require("./Loading");
  exports.Loading = Loading_1.Loading;
  __export(require("./Provider"));
  __export(require("./common/types"));
  function withAuthenticator(Comp, includeGreetings, authenticatorComponents, federated, theme, signUpConfig) {
      if (includeGreetings === void 0) { includeGreetings = false; }
      if (authenticatorComponents === void 0) { authenticatorComponents = []; }
      if (federated === void 0) { federated = null; }
      if (theme === void 0) { theme = null; }
      if (signUpConfig === void 0) { signUpConfig = {}; }
      return /** @class */ (function (_super) {
          __extends(class_1, _super);
          function class_1(props) {
              var _this = _super.call(this, props) || this;
              _this.handleAuthStateChange = _this.handleAuthStateChange.bind(_this);
              _this.state = {
                  authState: props.authState || null,
                  authData: props.authData || null,
              };
              _this.authConfig = {};
              if (typeof includeGreetings === 'object' && includeGreetings !== null) {
                  _this.authConfig = Object.assign(_this.authConfig, includeGreetings);
              }
              else {
                  _this.authConfig = {
                      includeGreetings: includeGreetings,
                      authenticatorComponents: authenticatorComponents,
                      federated: federated,
                      theme: theme,
                      signUpConfig: signUpConfig,
                  };
              }
              return _this;
          }
          class_1.prototype.handleAuthStateChange = function (state, data) {
              this.setState({ authState: state, authData: data });
          };
          class_1.prototype.render = function () {
              var _a = this.state, authState = _a.authState, authData = _a.authData;
              if (authState === 'signedIn') {
                  return (React.createElement(React.Fragment, null,
                      this.authConfig.includeGreetings ? (React.createElement(Authenticator_1.Authenticator, __assign({}, this.props, { theme: this.authConfig.theme, federated: this.authConfig.federated || this.props.federated, hideDefault: this.authConfig.authenticatorComponents &&
                              this.authConfig.authenticatorComponents.length > 0, signUpConfig: this.authConfig.signUpConfig, usernameAttributes: this.authConfig.usernameAttributes, onStateChange: this.handleAuthStateChange, children: this.authConfig.authenticatorComponents || [] }))) : null,
                      React.createElement(Comp, __assign({}, this.props, { authState: authState, authData: authData, onStateChange: this.handleAuthStateChange }))));
              }
              return (React.createElement(Authenticator_1.Authenticator, __assign({}, this.props, { theme: this.authConfig.theme, federated: this.authConfig.federated || this.props.federated, hideDefault: this.authConfig.authenticatorComponents &&
                      this.authConfig.authenticatorComponents.length > 0, signUpConfig: this.authConfig.signUpConfig, usernameAttributes: this.authConfig.usernameAttributes, onStateChange: this.handleAuthStateChange, children: this.authConfig.authenticatorComponents || [] })));
          };
          return class_1;
      }(React.Component));
  }
  exports.withAuthenticator = withAuthenticator;
  var AuthenticatorWrapper = /** @class */ (function (_super) {
      __extends(AuthenticatorWrapper, _super);
      function AuthenticatorWrapper(props) {
          var _this = _super.call(this, props) || this;
          _this.state = { auth: 'init' };
          _this.handleAuthState = _this.handleAuthState.bind(_this);
          _this.renderChildren = _this.renderChildren.bind(_this);
          return _this;
      }
      AuthenticatorWrapper.prototype.handleAuthState = function (state, data) {
          this.setState({ auth: state, authData: data });
      };
      AuthenticatorWrapper.prototype.renderChildren = function () {
          // @ts-ignore
          return this.props.children(this.state.auth);
      };
      AuthenticatorWrapper.prototype.render = function () {
          return (React.createElement("div", null,
              React.createElement(Authenticator_1.Authenticator, __assign({}, this.props, { onStateChange: this.handleAuthState })),
              this.renderChildren()));
      };
      return AuthenticatorWrapper;
  }(React.Component));
  exports.AuthenticatorWrapper = AuthenticatorWrapper;
  //# sourceMappingURL=index.js.map