"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SettingsSection = exports.isSettingsValid = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const FormLayout_1 = tslib_1.__importStar(require("../../../../components/FormLayout"));
const AdaptableInput_1 = tslib_1.__importDefault(require("../../../Components/AdaptableInput"));
const isSettingsValid = (chartDefinition, api) => {
    if (!chartDefinition.Name) {
        return 'Name is mandatory';
    }
    const allChartDefinitions = api.chartingApi.getExternalChartDefinitions();
    if (allChartDefinitions.some((chartDefinitionLoopItem) => chartDefinitionLoopItem.Uuid !== chartDefinition.Uuid &&
        chartDefinitionLoopItem.Name === chartDefinition.Name)) {
        return 'There is already a chart with this name';
    }
    return true;
};
exports.isSettingsValid = isSettingsValid;
const SettingsSection = (props) => {
    return (react_1.default.createElement(FormLayout_1.default, null,
        react_1.default.createElement(FormLayout_1.FormRow, { label: "Name" },
            react_1.default.createElement(AdaptableInput_1.default, { value: props.chartDefinition.Name, onChange: (e) => props.onChange({
                    ...props.chartDefinition,
                    Name: e.target.value,
                }) }))));
};
exports.SettingsSection = SettingsSection;
