"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ArrayFieldRenderer = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const uikit_1 = require("@gravity-ui/uikit");
const FormContext_1 = require("../../hooks/FormContext.js");
const cn_1 = require("../../utils/cn.js");
const AddPropertyButton_1 = require("../AddPropertyButton/AddPropertyButton.js");
const ConfigRow_1 = require("../ConfigRow/ConfigRow.js");
const SectionHeader_1 = require("../SectionHeader/SectionHeader.js");
const b = (0, cn_1.formBuilderCn)('array-field-renderer');
const ArrayFieldRenderer = ({ field, fieldName: _fieldName, inputTypeMenuItems, renderNestedField, }) => {
    const { addObjectProperty, updateField } = (0, FormContext_1.useFormContext)();
    return ((0, jsx_runtime_1.jsxs)("div", { className: b('config'), children: [(0, jsx_runtime_1.jsxs)("div", { className: b('config-row'), children: [(0, jsx_runtime_1.jsx)(uikit_1.Text, { variant: "body-2", children: "Array Type:" }), (0, jsx_runtime_1.jsx)(uikit_1.DropdownMenu, { items: [
                            {
                                action: () => updateField(field.id, { arrayType: 'text' }),
                                text: 'Text',
                            },
                            {
                                action: () => updateField(field.id, { arrayType: 'object' }),
                                text: 'Object',
                            },
                        ], renderSwitcher: (props) => ((0, jsx_runtime_1.jsx)(uikit_1.Button, { ...props, view: "normal", size: "s", children: field.arrayType === 'object' ? 'Object' : 'Text' })) })] }), (0, jsx_runtime_1.jsx)(ConfigRow_1.ConfigRow, { label: "Button Text", value: field.buttonText, onUpdate: (value) => updateField(field.id, { buttonText: value }) }), field.arrayType === 'object' && ((0, jsx_runtime_1.jsxs)("div", { className: b('nested-fields'), children: [(0, jsx_runtime_1.jsx)(SectionHeader_1.SectionHeader, { title: "Properties:" }), field?.properties?.map((property, index) => renderNestedField(property, index, field.id)), (0, jsx_runtime_1.jsx)(AddPropertyButton_1.AddPropertyButton, { inputTypeMenuItems: inputTypeMenuItems, onAdd: (type) => addObjectProperty(field.id, type) })] }))] }));
};
exports.ArrayFieldRenderer = ArrayFieldRenderer;
//# sourceMappingURL=ArrayFieldRenderer.js.map
