"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ReportNameWizardSection = exports.isValidReportName = exports.renderReportNameSummary = void 0;
const tslib_1 = require("tslib");
const React = tslib_1.__importStar(require("react"));
const rebass_1 = require("rebass");
const ErrorBox_1 = tslib_1.__importDefault(require("../../../components/ErrorBox"));
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
const Input_1 = tslib_1.__importDefault(require("../../../components/Input"));
const Tag_1 = require("../../../components/Tag");
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const renderReportNameSummary = (report) => {
    return (React.createElement(rebass_1.Box, { fontSize: 2 },
        ' ',
        "Report Name: ",
        React.createElement(Tag_1.Tag, null, report.Name)));
};
exports.renderReportNameSummary = renderReportNameSummary;
const isValidReportName = (report, api) => {
    if (!report.Name) {
        return 'Report name cannot be empty';
    }
    const reportsWithSameNameCount = api.exportApi
        .getAllReports()
        .filter((r) => report.Name === r.Name).length;
    const hasAlreadyExistingName = report.Uuid
        ? reportsWithSameNameCount > 1
        : reportsWithSameNameCount > 0;
    return hasAlreadyExistingName ? 'A Report already exists with that name' : true;
};
exports.isValidReportName = isValidReportName;
const ReportNameWizardSection = (props) => {
    const { api, data } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    const validCheck = (0, exports.isValidReportName)(data, api);
    const ErrorMessage = validCheck === true ? null : validCheck;
    return (React.createElement(rebass_1.Box, null,
        React.createElement(FormLayout_1.default, { columns: [1, 2] },
            React.createElement(FormLayout_1.FormRow, null,
                React.createElement(rebass_1.Text, { marginRight: 2 }, "Name:"),
                React.createElement(Input_1.default, { "data-name": "export-name", width: "100%", type: "text", autoFocus: true, placeholder: "Name", value: data.Name, onChange: (e) => {
                        props.onChange({
                            ...data,
                            Name: e.target.value,
                        });
                    } })),
            React.createElement(FormLayout_1.FormRow, null,
                React.createElement(React.Fragment, null),
                ErrorMessage ? React.createElement(ErrorBox_1.default, null, ErrorMessage) : null))));
};
exports.ReportNameWizardSection = ReportNameWizardSection;
