"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertyEditorSectionStories = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const StoryData_1 = require("../StoryBook/StoryData");
const PropertyEditorSection_1 = require("./PropertyEditorSection");
const PropertyEditorExpression_1 = require("./PropertyEditorExpression");
const PropertyEditorTypeSelection_1 = require("./PropertyEditorTypeSelection");
const PropertyEditorVariableSelection_1 = require("./PropertyEditorVariableSelection");
const DataTestData_1 = require("@appglue/common/dist/Common/Data/DataTestData");
const ExpressionConfiguration_1 = require("@appglue/common/dist/Expressions/ExpressionConfiguration");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const ObserveState_1 = require("../StateManagement/ObserveState");
const datadef = (0, DataTestData_1.getFilledDataDefinition)();
class SectionData {
    editObject = {
        expression: new ExpressionConfiguration_1.ExpressionConfiguration(),
        type: new StringDataDefinition_1.StringDataDefinition(),
        field: undefined,
    };
    label = "Set Expression";
    startOpen = true;
    renderUI = () => {
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: this.editObject, control: () => {
                let resultType = null;
                if (this.editObject.field) {
                    try {
                        resultType = DataUtilities_1.DataUtilities.getFieldFromDataDefinitionByName(datadef.fields, this.editObject.field);
                    }
                    catch (e) { }
                }
                return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(PropertyEditorTypeSelection_1.PropertyEditorTypeSelection, { editObject: this.editObject, updateCallback: this.updateCallback, propertyName: "type" }), (0, jsx_runtime_1.jsx)(PropertyEditorVariableSelection_1.PropertyEditorVariableSelection, { editObject: this.editObject, updateCallback: this.updateCallback, inputDataFunction: () => datadef, propertyName: "field", expectedType: this.editObject.type, allowNew: true }), (0, jsx_runtime_1.jsx)(PropertyEditorExpression_1.PropertyEditorExpression, { editObject: this.editObject, updateCallback: () => { }, inputDataFunction: () => datadef, propertyName: "expression", resultType: resultType || this.editObject.type })] }));
            } }));
    };
    updateCallback = () => {
        console.log("");
        StateManager_1.StateManager.changed(this.editObject);
    };
}
exports.PropertyEditorSectionStories = [
    new StoryData_1.StoryNode(() => {
        const params = new SectionData();
        return ((0, jsx_runtime_1.jsx)(PropertyEditorSection_1.PropertyEditorSection, { ...params, renderUI: params.renderUI, updateCallback: params.updateCallback }));
    }, "Shared", "Property Editors", "PropertyEditorSection"),
];
//# sourceMappingURL=PropertyEditorSection-stories.js.map