var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
/**
 * Select Signatu API and credentials for the demos
 */
import { TextField, Select, MenuItem, Button, createStyles, withStyles } from '@material-ui/core';
import { Consent, SUPPORTED_LANGUAGES } from '@signatu/consent';
import React from 'react';
import { Language } from '@signatu/common-lib';
var LS_CONSENT_CONFIG = "signatu.consentdemo.config";
var styles = function (theme) { return createStyles({
    root: {
        display: "flex", alignItems: "baseline", justifyContent: "space-between"
    }
}); };
var DemoConfig = /** @class */ (function (_super) {
    __extends(DemoConfig, _super);
    function DemoConfig(props) {
        var _this = _super.call(this, props) || this;
        _this.updateConfig = function () {
            localStorage.setItem(LS_CONSENT_CONFIG, JSON.stringify(_this.state.config));
            _this.props.onChange && _this.props.onChange(_this.state);
        };
        _this.changeLanguage = function (event) {
            _this.setState({ language: event.target.value }, _this.updateConfig);
        };
        var lsConfig = localStorage.getItem(LS_CONSENT_CONFIG);
        _this.state = {
            config: lsConfig ? JSON.parse(lsConfig) : {
                dataprocessingAPI: "https://api.signatu.com/dataprocessing/v0",
                consentAPI: "https://api.signatu.com/consent/v0",
                policyAPI: "https://api-server.production.signatu.com/api/v0"
            },
            language: 'en',
            subject: Consent.anonSubject()
        };
        _this.props.onChange && _this.props.onChange(_this.state);
        return _this;
    }
    DemoConfig.prototype.render = function () {
        var _this = this;
        var classes = this.props.classes;
        return React.createElement(React.Fragment, null,
            React.createElement("div", { className: classes.root },
                React.createElement(TextField, { style: { flex: 1 }, label: "Consent API", value: this.state.config.consentAPI, onChange: function (event) { return _this.setState({
                        config: __assign({}, _this.state.config, { consentAPI: event.target.value })
                    }); }, onBlur: this.updateConfig }),
                React.createElement(TextField, { style: { flex: 1 }, label: "DataProcessing API", value: this.state.config.dataprocessingAPI, onChange: function (event) { return _this.setState({
                        config: __assign({}, _this.state.config, { dataprocessingAPI: event.target.value })
                    }); }, onBlur: this.updateConfig }),
                React.createElement(TextField, { style: { flex: 1 }, type: "password", label: "AccessToken", value: this.state.config.accessToken, onChange: function (event) { return _this.setState({
                        config: __assign({}, _this.state.config, { accessToken: event.target.value })
                    }); }, onBlur: this.updateConfig }),
                React.createElement(TextField, { style: { flex: 1 }, label: "API Key", type: "password", value: this.state.config.apiKey, onChange: function (event) { return _this.setState({
                        config: __assign({}, _this.state.config, { apiKey: event.target.value })
                    }); }, onBlur: this.updateConfig })),
            React.createElement("br", null),
            React.createElement("div", { style: { display: "flex", alignItems: "baseline", justifyContent: "space-between" } },
                React.createElement(Select, { onChange: this.changeLanguage, value: this.state.language }, SUPPORTED_LANGUAGES.map(function (l) {
                    var lang = new Language(l);
                    return React.createElement(MenuItem, { key: lang.isoLanguage, value: lang.isoLanguage }, lang.name);
                })),
                React.createElement(Button, { variant: "outlined", onClick: function () {
                        Consent.clearAnonSubject();
                        _this.setState({ subject: Consent.anonSubject() }, _this.updateConfig);
                    } }, "New Subject ID"),
                React.createElement("div", null,
                    React.createElement("b", null, "Subject ID:"),
                    " ",
                    this.state.subject)));
    };
    return DemoConfig;
}(React.Component));
var styled = withStyles(styles)(DemoConfig);
export { styled as DemoConfig };
//# sourceMappingURL=demoConfig.js.map