"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ColumnVariablePicker = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const ObserveState_1 = require("../../../CommonUI/StateManagement/ObserveState");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const VariablePickerDialog_1 = require("../../../CommonUI/VariablePickerDialog");
const ColumnVariablePicker = (props) => {
    const { rule, editContext, dataDefinition, allowNew } = props;
    const onCloseDialog = () => {
        editContext.selectedColumnHeader = undefined;
    };
    return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: editContext, properties: ["selectedColumnHeader"], control: () => {
            return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: dataDefinition, properties: ["fields"], control: () => {
                    return ((0, jsx_runtime_1.jsx)(VariablePickerDialog_1.VariablePickerDialog, { selected: rule.name, data: dataDefinition, onVariableSet: (path, def) => {
                            if (def) {
                                dataDefinition.fields.push(def);
                                props.onSet(rule, def.name);
                                StateManager_1.StateManager.propertyChanged(dataDefinition, "fields");
                            }
                            else {
                                rule.name = path;
                                props.onSet(rule, path);
                            }
                            StateManager_1.StateManager.propertyChanged(rule, "name");
                            onCloseDialog();
                        }, allowNewVariable: allowNew, show: editContext.selectedColumnHeader === rule, onClose: onCloseDialog }));
                } }));
        } }));
};
exports.ColumnVariablePicker = ColumnVariablePicker;
//# sourceMappingURL=ColumnVariablePicker.js.map