"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldSettings = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const uikit_1 = require("@gravity-ui/uikit");
const FormContext_1 = require("../../hooks/FormContext.js");
const fieldNames_1 = require("../../utils/fieldNames.js");
const WhenEditor_1 = require("../WhenEditor/WhenEditor.js");
const ColorInputSettings_1 = require("./fields/ColorInputSettings.js");
const OptionsSettings_1 = require("./fields/OptionsSettings.js");
const Row_1 = require("./fields/Row.js");
const SectionSettings_1 = require("./fields/SectionSettings.js");
const SwitchSettings_1 = require("./fields/SwitchSettings.js");
const TextFieldSettings_1 = require("./fields/TextFieldSettings.js");
const TextSettings_1 = require("./fields/TextSettings.js");
const FieldSettings = ({ field }) => {
    const { updateField, formFields } = (0, FormContext_1.useFormContext)();
    const availableFields = React.useMemo(() => {
        const all = Array.from((0, fieldNames_1.collectNames)(formFields));
        if (field.type === 'section' || field.type === 'text')
            return all;
        return all.filter((n) => n !== field.name);
    }, [formFields, field]);
    const whenEditorSection = ((0, jsx_runtime_1.jsx)(Row_1.Row, { label: "Visible when", children: (0, jsx_runtime_1.jsx)(WhenEditor_1.WhenEditor, { when: field.when, availableFields: availableFields, onChange: (next) => updateField(field.id, { when: next }) }) }));
    const commonRows = ((0, jsx_runtime_1.jsxs)(React.Fragment, { children: [(0, jsx_runtime_1.jsx)(Row_1.Row, { label: "Title", children: (0, jsx_runtime_1.jsx)(uikit_1.TextInput, { value: 'title' in field ? (field.title ?? '') : '', onUpdate: (value) => updateField(field.id, { title: value }), placeholder: "Label shown above the field" }) }), (0, jsx_runtime_1.jsx)(Row_1.Row, { label: "Name", children: (0, jsx_runtime_1.jsx)(uikit_1.TextInput, { value: 'name' in field ? (field.name ?? '') : '', onUpdate: (value) => updateField(field.id, { name: value }), placeholder: "Path in content object" }) })] }));
    if (field.type === 'section') {
        return ((0, jsx_runtime_1.jsx)(SectionSettings_1.SectionSettings, { field: field, updateField: updateField, whenEditorSection: whenEditorSection }));
    }
    if (field.type === 'text') {
        return ((0, jsx_runtime_1.jsx)(TextSettings_1.TextSettings, { field: field, updateField: updateField, whenEditorSection: whenEditorSection }));
    }
    if (field.type === 'textInput' || field.type === 'textArea') {
        return ((0, jsx_runtime_1.jsx)(TextFieldSettings_1.TextFieldSettings, { field: field, updateField: updateField, commonRows: commonRows, whenEditorSection: whenEditorSection }));
    }
    if (field.type === 'switch') {
        return ((0, jsx_runtime_1.jsx)(SwitchSettings_1.SwitchSettings, { field: field, updateField: updateField, commonRows: commonRows, whenEditorSection: whenEditorSection }));
    }
    if (field.type === 'colorInput') {
        return ((0, jsx_runtime_1.jsx)(ColorInputSettings_1.ColorInputSettings, { field: field, updateField: updateField, commonRows: commonRows, whenEditorSection: whenEditorSection }));
    }
    if (field.type === 'select' || field.type === 'segmentedRadioGroup') {
        return ((0, jsx_runtime_1.jsx)(OptionsSettings_1.OptionsSettings, { field: field, updateField: updateField, commonRows: commonRows, whenEditorSection: whenEditorSection }));
    }
    return null;
};
exports.FieldSettings = FieldSettings;
//# sourceMappingURL=FieldSettings.js.map
