/*eslint no-useless-constructor: 0*/
export class RegistrationData {
    constructor(example, category, name, icon, valueType, common = false, include) {
        this.example = example;
        this.category = category;
        this.name = name;
        this.icon = icon;
        this.valueType = valueType;
        this.common = common;
        this.include = include;
    }
    create() {
        let prototype = Object.getPrototypeOf(this.example);
        return new prototype.constructor();
    }
}
export class ExpressionRegistration {
    static registerExpression(example, category, name, icon, valueType, common = false, include) {
        ExpressionRegistration.registrations[name] = new RegistrationData(example, category, name, icon, valueType, common, include);
    }
    static getCategories(data) {
        let categories = [];
        for (let reg of Object.values(ExpressionRegistration.registrations)) {
            if (categories.indexOf(reg.category) === -1)
                categories.push(reg.category);
        }
        return categories;
    }
    static getExpressionByType(typeName, data) {
        for (let r of Object.values(ExpressionRegistration.registrations)) {
            if (typeName === r.name) {
                return r;
            }
        }
        return undefined;
    }
    static getExpressionsByCategory(category, data) {
        return Object.values(ExpressionRegistration.registrations).filter((value) => {
            if (value.category === category) {
                if (!value.include) {
                    return true;
                }
                else {
                    return value.include(data);
                }
            }
            return false;
        });
    }
    static getCommonExpressions(data) {
        return Object.values(ExpressionRegistration.registrations).filter((value) => {
            if (value.common) {
                if (!value.include) {
                    return true;
                }
                else {
                    return value.include(data);
                }
            }
            return false;
        });
    }
    static getExpressionByName(name) {
        return ExpressionRegistration.registrations[name];
    }
}
ExpressionRegistration.registrations = {};
export function GetExpressionFromData(data) {
    if (!data)
        return;
    let typeName = Reflect.get(data, "__type");
    if (typeName) {
        let registeredControl = ExpressionRegistration.getExpressionByName(typeName);
        let val = registeredControl === null || registeredControl === void 0 ? void 0 : registeredControl.create();
        // @ts-ignore
        let cc = val;
        cc.setStorageData(data);
        return cc;
    }
    throw new Error("Could not create expression: no type defined " + typeName);
}
export function RegisterExpression(exampleExpression, category, icon, valueType, common = false, include) {
    ExpressionRegistration.registerExpression(exampleExpression, category, exampleExpression.__type, icon, valueType, common, include);
    if (!ExpressionRegistration.getExpressionByName(exampleExpression.__type))
        throw new Error("registration failed");
}
//# sourceMappingURL=RegisterExpression.js.map