import * as React from 'react';
import { concat, mergeMap } from 'rxjs/operators';
import { overwriteSettings } from '../configuration/backend';
import { refreshConfiguration } from '../user/settings/backend';
import { SettingsFile } from './SettingsFile';
/**
 * Displays a page where the settings for a subject can be edited.
 */
export class SettingsPage extends React.PureComponent {
    constructor() {
        super(...arguments);
        this.state = {};
        this.onDidCommit = (lastID, contents) => {
            this.setState({ commitError: undefined });
            overwriteSettings(this.props.subject.id, lastID, contents)
                .pipe(mergeMap(() => refreshConfiguration().pipe(concat([null]))))
                .subscribe(() => {
                this.setState({ commitError: undefined });
                this.props.onUpdate();
            }, err => {
                this.setState({ commitError: err });
                console.error(err);
            });
        };
        this.onDidDiscard = () => {
            this.setState({ commitError: undefined });
        };
    }
    render() {
        return (React.createElement(SettingsFile, { settings: this.props.data.subjects[this.props.data.subjects.length - 1].latestSettings, jsonSchema: this.props.data.settingsJSONSchema, commitError: this.state.commitError, onDidCommit: this.onDidCommit, onDidDiscard: this.onDidDiscard, history: this.props.history, isLightTheme: this.props.isLightTheme }));
    }
}
//# sourceMappingURL=SettingsPage.js.map