"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VariablePickerStories = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const DataTestData_1 = require("@appglue/common/dist/Common/Data/DataTestData");
const VariablePicker_1 = tslib_1.__importDefault(require("./VariablePicker"));
const DataTypes_1 = require("@appglue/common/dist/Common/Data/DataTypes");
const StateManager_1 = require("@appglue/common/dist/Common/StateManager");
const ObserveState_1 = require("./StateManagement/ObserveState");
const ObjectDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/ObjectDataDefinition");
const StringDataDefinition_1 = require("@appglue/common/dist/Common/Data/Definitions/StringDataDefinition");
const DataUtilities_1 = require("@appglue/common/dist/Common/DataUtilities");
const StoryData_1 = require("./StoryBook/StoryData");
class VariablePickerParams {
    data = (0, DataTestData_1.getFilledDataDefinition)();
    selected = null;
    requiredType = DataTypes_1.DataTypes.STRING;
    allowNewVariable = undefined;
    inputProps = {};
    startOpenIfEmptyOrInvalid;
    isList;
    constructor(data) {
        if (data)
            this.data = data;
    }
    onVariableSet = (path, def) => {
        let changedProperties = ["selected"];
        if (def) {
            let data = this.data;
            if (path !== "") {
                data = DataUtilities_1.DataUtilities.getFieldFromDataDefinitionByName(this.data.fields, path);
                this.selected = `${path}.${def.name}`;
            }
            else {
                this.selected = def.name;
            }
            data.fields.push(def);
            changedProperties.push("data");
        }
        else {
            this.selected = path;
        }
        StateManager_1.StateManager.propertiesChanged(this, changedProperties);
    };
}
exports.VariablePickerStories = [
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams((0, DataTestData_1.getEmptyDataDefinition)());
        variablePickerProps.allowNewVariable = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Empty With Editable"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams((0, DataTestData_1.getEmptyDataDefinition)());
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Empty"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Not Editable"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.allowNewVariable = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Editable"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.requiredType = DataTypes_1.DataTypes.BOOLEAN;
        variablePickerProps.selected = "person.firstName";
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Invalid Type"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.requiredType = variablePickerProps.data.fields[variablePickerProps.data.fields.length - 1];
        variablePickerProps.selected = "person";
        variablePickerProps.allowNewVariable = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Object Definition Required Type"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        let children = new ObjectDataDefinition_1.ObjectDataDefinition();
        children.name = "children";
        children.list = true;
        let childFirstName = new StringDataDefinition_1.StringDataDefinition();
        childFirstName.name = "firstName";
        children.fields.push(childFirstName);
        let childLastName = new StringDataDefinition_1.StringDataDefinition();
        childLastName.name = "lastName";
        children.fields.push(childLastName);
        variablePickerProps.data.fields.push(children);
        variablePickerProps.requiredType = children;
        variablePickerProps.selected = "person";
        variablePickerProps.allowNewVariable = true;
        variablePickerProps.requiredType.list = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Object Definition With List Required Type"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.requiredType = undefined;
        variablePickerProps.allowNewVariable = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Without Required Type"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.inputProps = { size: "medium" };
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Medium Size"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.inputProps = { size: "small" };
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Small Size"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.inputProps = { size: "large" };
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Large Size"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.selected = "invalid";
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Invalid Field"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.selected = "invalid";
        variablePickerProps.startOpenIfEmptyOrInvalid = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Start Open If Empty or Invalid"),
    new StoryData_1.StoryNode(() => {
        let variablePickerProps = new VariablePickerParams();
        variablePickerProps.requiredType = undefined;
        variablePickerProps.isList = true;
        return ((0, jsx_runtime_1.jsx)(ObserveState_1.ObserveState, { listenTo: variablePickerProps, control: () => ((0, jsx_runtime_1.jsx)("div", { style: { display: "flex", flexDirection: "column", maxWidth: 250 }, children: (0, jsx_runtime_1.jsx)(VariablePicker_1.default, { ...variablePickerProps }) })) }));
    }, "Shared", "Variable Picker", "Only List"),
];
//# sourceMappingURL=VariablePicker-stories.js.map