"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.ConfirmPage = void 0;

var _taggedTemplateLiteralLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteralLoose"));

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

var _styledComponents = _interopRequireDefault(require("styled-components"));

var _lib = require("@sentecacommerce-theme/lib");

var _Common = require("../Common");

var _templateObject, _templateObject2, _templateObject3;

var ConfirmPage = function ConfirmPage(_ref) {
  var labels = _ref.labels;

  var _useConfigState = (0, _lib.useConfigState)(),
      views = _useConfigState.views;

  var _useIsAuthenticated = (0, _lib.useIsAuthenticated)(),
      isAuthenticated = _useIsAuthenticated.isAuthenticated,
      isAuthLoading = _useIsAuthenticated.isLoading;

  var _useUIFunctions = (0, _lib.useUIFunctions)(),
      enqueueView = _useUIFunctions.enqueueView;

  var _useBoolean = (0, _lib.useBoolean)(),
      isSuccess = _useBoolean[0],
      setIsSuccess = _useBoolean[1];

  _react["default"].useEffect(function () {
    if (isAuthLoading || isAuthenticated) return;

    if (!isAuthenticated) {
      enqueueView(views.auth);
    }
  }, [isAuthLoading, isAuthenticated]);

  var _useConfirmSubscripti = (0, _lib.useConfirmSubscription)({
    onSuccess: function onSuccess() {
      setIsSuccess.on();
    }
  }),
      isLoading = _useConfirmSubscripti.isLoading,
      isError = _useConfirmSubscripti.isError;

  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(Container, null, /*#__PURE__*/_react["default"].createElement(Row, null, /*#__PURE__*/_react["default"].createElement(Col, null, isLoading && /*#__PURE__*/_react["default"].createElement(_Common.Spinner, null), isError && /*#__PURE__*/_react["default"].createElement("h4", null, labels.somethingWentWrong), !isLoading && !isError && /*#__PURE__*/_react["default"].createElement("h4", null, labels.success)))));
};

exports.ConfirmPage = ConfirmPage;

var Container = _styledComponents["default"].div.attrs({
  className: 'container mt-5 mb-5'
})(_templateObject || (_templateObject = (0, _taggedTemplateLiteralLoose2["default"])(["\n  @media (min-width: ", ") {\n    min-height: 30rem;\n  }\n"])), function (_ref2) {
  var theme = _ref2.theme;
  return theme.breakpoints.lg.min;
});

var Row = _styledComponents["default"].div.attrs({
  className: 'row d-flex flex-column'
})(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteralLoose2["default"])(["\n  text-align: center;\n"])));

var Col = _styledComponents["default"].div.attrs({
  className: 'col-12'
})(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteralLoose2["default"])([""])));
//# sourceMappingURL=confirmPage.component.js.map