import { __awaiter, __generator } from "tslib";
export var createObjectLoader = function (registerArticle) {
    var objectLoader = {
        capabilities: {
            nodeUpdates: true,
        },
        createContext: function () { return ({}); },
        getComponentState: function (component) { return ({
            Transform: component.transform,
            Material: component.material,
            MaterialCategory: component.materialCategory,
            Geometry: component.geometry,
            GeometryParameters: component.geometryParameters,
        }); },
        createComponent: function (componentId, parent, options, context) {
            var component = {
                componentId: componentId,
                parentId: parent.componentId,
                children: [],
                position: undefined,
                rotation: undefined,
                scale: undefined,
                size: { x: 0, y: 0, z: 0 },
                visible: true,
                data: {
                    geometryStatus: "default",
                },
                selectionMode: "Parent",
            };
            parent.children.push(component);
            registerArticle(component);
            return component;
        },
        setComponentData: function (component, igxcObject) {
            if (igxcObject.Categories) {
                if (typeof igxcObject.Categories === "string") {
                    component.data.categories = igxcObject.Categories.split(",");
                }
                else if (igxcObject.Categories instanceof Array) {
                    component.data.categories = igxcObject.Categories;
                }
            }
        },
        setComponentTransform: function (component, transform) {
            component.transform = transform;
        },
        setComponentGeometry: function (component, object) { return __awaiter(void 0, void 0, void 0, function () {
            return __generator(this, function (_a) {
                if (object.GeometryParameters) {
                    component.geometryParameters = object.GeometryParameters;
                }
                else if (object.Geometry) {
                    component.geometry = object.Geometry;
                }
                return [2 /*return*/];
            });
        }); },
        setComponentMaterials: function (component, _a) {
            var material = _a.material;
            return __awaiter(void 0, void 0, void 0, function () {
                return __generator(this, function (_b) {
                    component.material = material;
                    return [2 /*return*/];
                });
            });
        },
    };
    return objectLoader;
};
