"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportSettingsWizard = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const StringExtensions_1 = require("../../../Utilities/Extensions/StringExtensions");
const WizardPanel_1 = tslib_1.__importDefault(require("../../../components/WizardPanel"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const rebass_1 = require("rebass");
const ErrorBox_1 = tslib_1.__importDefault(require("../../../components/ErrorBox"));
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
class ReportSettingsWizard extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            ReportName: this.props.data.Name,
            ErrorMessage: null,
        };
    }
    render() {
        let validationState = StringExtensions_1.StringExtensions.IsNullOrEmpty(this.state.ErrorMessage)
            ? null
            : 'error';
        return (React.createElement("div", { "data-name": 'report-settings' },
            React.createElement(WizardPanel_1.default, null,
                React.createElement(FormLayout_1.default, { columns: [1, 2] },
                    React.createElement(FormLayout_1.FormRow, null,
                        React.createElement(rebass_1.Text, { marginRight: 2 }, "Enter Report Name:"),
                        React.createElement(Input_1.default, { width: "100%", type: "text", placeholder: "Name", value: this.state.ReportName, onChange: (e) => this.onReportNameChanged(e) })),
                    React.createElement(FormLayout_1.FormRow, null,
                        React.createElement(React.Fragment, null),
                        this.state.ErrorMessage ? React.createElement(ErrorBox_1.default, null, this.state.ErrorMessage) : null)))));
    }
    onReportNameChanged(event) {
        let e = event.target;
        this.setState({
            ReportName: e.value,
            ErrorMessage: this.props.Reports.findIndex((x) => x.Name == e.value) > -1
                ? 'A Report already exists with that name'
                : null,
        }, () => this.props.updateGoBackState());
    }
    canNext() {
        return (StringExtensions_1.StringExtensions.IsNotNullOrEmpty(this.state.ReportName) &&
            StringExtensions_1.StringExtensions.IsNullOrEmpty(this.state.ErrorMessage));
    }
    canBack() {
        return true;
    }
    next() {
        this.props.data.Name = this.state.ReportName;
    }
    back() { }
    getIndexStepIncrement() {
        return 1;
    }
    getIndexStepDecrement() {
        return this.props.data.ReportRowScope == 'ExpressionRows' ? 1 : 2;
    }
}
exports.ReportSettingsWizard = ReportSettingsWizard;
