"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.NamedQuerySettingsWizardSection = exports.renderNamedQuerySettingsSummary = exports.isValidNamedQuerySettings = void 0;
const tslib_1 = require("tslib");
// TODO: move to named query
const React = tslib_1.__importStar(require("react"));
const rebass_1 = require("rebass");
const WizardPanel_1 = tslib_1.__importDefault(require("../../../components/WizardPanel"));
const FormLayout_1 = tslib_1.__importStar(require("../../../components/FormLayout"));
const ErrorBox_1 = tslib_1.__importDefault(require("../../../components/ErrorBox"));
const OnePageAdaptableWizard_1 = require("../../Wizard/OnePageAdaptableWizard");
const AdaptableInput_1 = tslib_1.__importDefault(require("../../Components/AdaptableInput"));
const Tag_1 = require("../../../components/Tag");
const isValidNamedQuerySettings = (data, api) => {
    const validationResult = api.namedQueryApi.isValidNamedQuery(data);
    const ErrorMessage = !validationResult.valid ? validationResult.message : null;
    if (!ErrorMessage) {
        return true;
    }
    return ErrorMessage;
};
exports.isValidNamedQuerySettings = isValidNamedQuerySettings;
const renderNamedQuerySettingsSummary = (data) => {
    return (React.createElement(rebass_1.Text, { fontSize: 2 },
        "Name: ",
        React.createElement(Tag_1.Tag, null, data.Name)));
};
exports.renderNamedQuerySettingsSummary = renderNamedQuerySettingsSummary;
const NamedQuerySettingsWizardSection = (props) => {
    const { data, api } = (0, OnePageAdaptableWizard_1.useOnePageAdaptableWizardContext)();
    const valid = (0, exports.isValidNamedQuerySettings)(data, api);
    const errorMessage = valid === true ? null : valid;
    const handleColumnNameChange = (event) => {
        let e = event.target;
        props.onChange({
            ...data,
            Name: e.value,
        });
    };
    return (React.createElement(WizardPanel_1.default, { "data-name": 'named-query-settings' },
        React.createElement(FormLayout_1.default, null,
            React.createElement(FormLayout_1.FormRow, { label: "Name" },
                React.createElement(AdaptableInput_1.default, { "data-name": "query-name", value: data.Name, autoFocus: true, width: 300, type: "text", placeholder: "Enter Named Query Name", onChange: (e) => handleColumnNameChange(e) })),
            ' ',
            errorMessage ? (React.createElement(FormLayout_1.FormRow, { label: "" },
                React.createElement(ErrorBox_1.default, null, errorMessage))) : null)));
};
exports.NamedQuerySettingsWizardSection = NamedQuerySettingsWizardSection;
