+import axios from 'axios';
+import PropTypes from 'prop-types';
+import React from 'react';
+import { Button, Modal } from 'react-bootstrap';
+import { withTranslation } from 'react-i18next';
+import toastr from 'toastr';
+
+import ToggleSwitch from '../common/ToggleSwitch';
+import i18n from '../../i18n';
+
+const open = async tournament => {
+ try {
+ await axios.post(`/api/tournaments/${tournament.id}/open`);
+ toastr.success(i18n.t('tournaments.openSuccess'));
+ } catch (e) {
+ toastr.error(i18n.t('tournaments.openError'));
+ }
+};
+
+const close = async tournament => {
+ try {
+ await axios.post(`/api/tournaments/${tournament.id}/close`);
+ toastr.success(i18n.t('tournaments.closeSuccess'));
+ } catch (e) {
+ toastr.error(i18n.t('tournaments.closeError'));
+ }
+};
+
+const lock = async tournament => {
+ try {
+ await axios.post(`/api/tournaments/${tournament.id}/lock`);
+ toastr.success(i18n.t('tournaments.lockSuccess'));
+ } catch (e) {
+ toastr.error(i18n.t('tournaments.lockError'));
+ }
+};
+
+const unlock = async tournament => {
+ try {
+ await axios.post(`/api/tournaments/${tournament.id}/unlock`);
+ toastr.success(i18n.t('tournaments.unlockSuccess'));
+ } catch (e) {
+ toastr.error(i18n.t('tournaments.unlockError'));
+ }
+};
+
+const SettingsDialog = ({
+ onHide,
+ show,
+ tournament,
+}) =>
+<Modal className="settings-dialog" onHide={onHide} show={show}>
+ <Modal.Header closeButton>
+ <Modal.Title>
+ {i18n.t('tournaments.settings')}
+ </Modal.Title>
+ </Modal.Header>
+ <Modal.Body>
+ <div className="d-flex align-items-center justify-content-between mb-3">
+ <span>{i18n.t('tournaments.open')}</span>
+ <ToggleSwitch
+ onChange={({ target: { value } }) => value ? open(tournament) : close(tournament)}
+ value={tournament.accept_applications}
+ />
+ </div>
+ <div className="d-flex align-items-center justify-content-between">
+ <span>{i18n.t('tournaments.locked')}</span>
+ <ToggleSwitch
+ onChange={({ target: { value } }) => value ? lock(tournament) : unlock(tournament)}
+ value={tournament.locked}
+ />
+ </div>
+ </Modal.Body>
+ <Modal.Footer>
+ <Button onClick={onHide} variant="secondary">
+ {i18n.t('button.close')}
+ </Button>
+ </Modal.Footer>
+</Modal>;
+
+SettingsDialog.propTypes = {
+ onHide: PropTypes.func,
+ show: PropTypes.bool,
+ tournament: PropTypes.shape({
+ accept_applications: PropTypes.bool,
+ locked: PropTypes.bool,
+ }),
+};
+
+export default withTranslation()(SettingsDialog);