/*
 * Copyright (C) 2016-2020 Kano Computing Ltd.
 * License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
 */
/**
 * Automatically registers the type and name for a given part
 * Example:
 * ```ts
 * @part('my-part')
 * class MyPart extends Part{}
 * ```
 * @param type Type of the part
 * @param name Label for the part
 */
export function part(type) {
    return function (constructor) {
        Object.defineProperty(constructor, 'type', {
            writable: false,
            configurable: false,
            value: type,
            enumerable: false,
        });
    };
}
const componentsCache = new Map();
/**
 * Automatically register the component and bind them to the Part property
 * Example:
 * ```ts
 * class MyPart extends Part {
 *     @component(Transform)
 *     public transform : Transform;
 * }
 * ```
 * @param comp Component class for a given property
 */
export function component(comp) {
    return function (target, key) {
        if (!componentsCache.has(target)) {
            componentsCache.set(target, {});
        }
        const cachedProps = componentsCache.get(target);
        if (cachedProps) {
            cachedProps[key] = comp;
        }
        if (!target.constructor.hasOwnProperty('components')) {
            Object.defineProperty(target.constructor, 'components', {
                get: () => componentsCache.get(target),
                enumerable: true,
            });
        }
    };
}
const propertiesCache = new Map();
/**
 * Automatically register the component and bind them to the Part property
 * Example:
 * ```ts
 * class MyComponent extends Component {
 *     @property(Number)
 *     public x : number;
 * }
 * ```
 * @param comp Component class for a given property
 */
export function property(propOptions) {
    return function (target, key) {
        if (!propertiesCache.has(target)) {
            propertiesCache.set(target, {});
        }
        const cachedProps = propertiesCache.get(target);
        if (cachedProps) {
            cachedProps[key] = propOptions;
        }
        if (!target.constructor.hasOwnProperty('properties')) {
            Object.defineProperty(target.constructor, 'properties', {
                get: () => propertiesCache.get(target),
                enumerable: true,
            });
        }
    };
}
//# sourceMappingURL=decorators.js.map