"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

require("core-js/modules/web.dom.iterable");

var _react = _interopRequireWildcard(require("react"));

var _accountSetupFinishPane = _interopRequireDefault(require("./account-setup-finish-pane"));

var _notificationPrefsPane = _interopRequireDefault(require("./notification-prefs-pane"));

var _favoritePlacesList = _interopRequireDefault(require("./places/favorite-places-list"));

var _sequentialPaneDisplay = _interopRequireDefault(require("./sequential-pane-display"));

var _termsOfUsePane = _interopRequireDefault(require("./terms-of-use-pane"));

var _verifyEmailPane = _interopRequireDefault(require("./verify-email-pane"));

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

function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

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; }

/**
 * This component is the new account wizard.
 */
class NewAccountWizard extends _react.Component {
  constructor(...args) {
    super(...args);

    _defineProperty(this, "_handleCreateNewUser", () => {
      const {
        onCreate,
        // provided by UserAccountScreen
        values: userData // provided by Formik

      } = this.props; // Create a user record only if an id is not assigned.

      if (!userData.id) {
        onCreate(userData);
      }
    });
  }

  render() {
    // The props include Formik props that provide access to the current user data (stored in props.values)
    // and to its own blur/change/submit event handlers that automate the state.
    // We forward the props to each pane so that their individual controls
    // can be wired to be managed by Formik.
    const props = this.props;
    const {
      activePaneId,
      values: userData
    } = props;
    const {
      hasConsentedToTerms,
      notificationChannel = 'email'
    } = userData;
    const paneSequence = {
      // Verify will redirect according to email verification state
      // and thus doesn't carry a nextId.
      verify: {
        hideNavigation: true,
        pane: _verifyEmailPane.default,
        props,
        title: 'Verify your email address'
      },
      // eslint-disable-next-line sort-keys
      terms: {
        disableNext: !hasConsentedToTerms,
        nextId: 'notifications',
        onNext: this._handleCreateNewUser,
        pane: _termsOfUsePane.default,
        props,
        title: 'Create a new account'
      },
      // eslint-disable-next-line sort-keys
      notifications: {
        disableNext: notificationChannel === 'sms' && !userData.phoneNumber,
        nextId: 'places',
        pane: _notificationPrefsPane.default,
        prevId: 'terms',
        props,
        title: 'Notification preferences'
      },
      places: {
        nextId: 'finish',
        pane: _favoritePlacesList.default,
        prevId: 'notifications',
        props,
        title: 'Add your locations'
      },
      // eslint-disable-next-line sort-keys
      finish: {
        pane: _accountSetupFinishPane.default,
        prevId: 'places',
        props,
        title: 'Account setup complete!'
      }
    };
    return /*#__PURE__*/_react.default.createElement(_sequentialPaneDisplay.default, {
      activePaneId: activePaneId,
      paneSequence: paneSequence
    });
  }

}

var _default = NewAccountWizard;
exports.default = _default;
module.exports = exports.default;

//# sourceMappingURL=new-account-wizard.js