"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Signout = void 0;
var _dataSources = require("@mirai/data-sources");
var _locale = require("@mirai/locale");
var _services = require("@mirai/services");
var _ui = require("@mirai/ui");
var _react = _interopRequireWildcard(require("react"));
var _Settings = require("./Settings.l10n");
var style = _interopRequireWildcard(require("./Settings.module.css"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
const Signout = () => {
  const {
    value: {
      club = {},
      hotel: {
        url
      } = {}
    }
  } = (0, _dataSources.useStore)();
  const {
    translate
  } = (0, _locale.useLocale)();
  const [busy, setBusy] = (0, _react.useState)(false);
  const [modal, setModal] = (0, _react.useState)(false);
  const [response, setResponse] = (0, _react.useState)();
  const [responseError, setResponseError] = (0, _react.useState)();
  const handleSubmit = async () => {
    setBusy(true);
    setResponseError(undefined);
    const response = await _services.ServiceUser.signout().catch(error => {
      setResponseError(error);
    });
    setResponse(response);
    setBusy(false);
  };
  const handleClose = () => {
    if (!response) return setModal(false);
    window.location.href = url;
  };
  const handleOpen = () => {
    setModal(true);
  };
  return /*#__PURE__*/_react.default.createElement(_ui.View, {
    className: style.box
  }, /*#__PURE__*/_react.default.createElement(_ui.Text, {
    bold: true,
    headline: true
  }, translate(_Settings.L10N.TITLE_SIGNOUT, {
    club: club.name
  })), /*#__PURE__*/_react.default.createElement(_ui.Text, null, translate(_Settings.L10N.DESCRIPTION_SIGNOUT)), /*#__PURE__*/_react.default.createElement(_ui.Button, {
    secondary: true,
    wide: true,
    onPress: handleOpen,
    testId: "button-delete-account"
  }, translate(_Settings.L10N.BUTTON_SIGNOUT)), /*#__PURE__*/_react.default.createElement(_ui.Modal, {
    portal: true,
    title: translate(_Settings.L10N.BUTTON_SIGNOUT),
    visible: modal,
    onClose: handleClose
  }, /*#__PURE__*/_react.default.createElement(_ui.View, {
    className: style.modal
  }, !response && /*#__PURE__*/_react.default.createElement(_ui.Text, null, translate(_Settings.L10N.DESCRIPTION_SIGNOUT_MODAL)), (response || responseError) && /*#__PURE__*/_react.default.createElement(_ui.Notification, {
    large: !!response,
    error: !!responseError,
    success: !!response,
    className: style.notification
  }, translate(responseError ? _Settings.L10N.ERROR : _Settings.L10N.SUCCESS_SIGNOUT), response && /*#__PURE__*/_react.default.createElement(_ui.Text, {
    small: true,
    className: style.description
  }, translate(_Settings.L10N.DESCRIPTION_SIGNOUT_MODAL_SUCCESS))), !response ? /*#__PURE__*/_react.default.createElement(_ui.View, {
    wide: true,
    className: style.buttons
  }, /*#__PURE__*/_react.default.createElement(_ui.Button, {
    busy: busy,
    wide: true,
    onPress: handleSubmit
  }, translate(_Settings.L10N.CTA_SIGNOUT)), /*#__PURE__*/_react.default.createElement(_ui.Button, {
    disabled: busy,
    transparent: true,
    wide: true,
    onPress: handleClose,
    testId: "button-delete-close"
  }, translate(_Settings.L10N.ACTION_SIGNOUT_CANCEL))) : null)));
};
exports.Signout = Signout;
Signout.displayName = 'Mirai:Core:Profile:Signout';
Signout.propTypes = {};
//# sourceMappingURL=Settings.Signout.js.map