(function (factory) {
    if (typeof module === "object" && typeof module.exports === "object") {
        var v = factory(require, exports);
        if (v !== undefined) module.exports = v;
    }
    else if (typeof define === "function" && define.amd) {
        define(["require", "exports", "./AtomBridge"], factory);
    }
})(function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.InheritedProperty = void 0;
    const AtomBridge_1 = require("./AtomBridge");
    /**
     * Use this decorator only to watch property changes in `onPropertyChanged` method.
     * This decorator also makes enumerable property.
     *
     * Do not use this on anything except UI control
     * @param target control
     * @param key name of property
     */
    function InheritedProperty(target, key) {
        // property value
        const iVal = target[key];
        const keyName = typeof Symbol === "undefined"
            ? ("_" + key)
            : Symbol(`${key}`);
        target[keyName] = iVal;
        // property getter
        const getter = function () {
            const p = this[keyName];
            if (p !== undefined) {
                return p;
            }
            if (this.element && this.parent) {
                return this.parent[key];
            }
            return undefined;
        };
        // property setter
        const setter = function (newVal) {
            const oldValue = this[keyName];
            if (oldValue && oldValue.dispose) {
                oldValue.dispose();
            }
            this[keyName] = newVal;
            AtomBridge_1.AtomBridge.refreshInherited(this, key);
        };
        // delete property
        if (delete target[key]) {
            // create new property with getter and setter
            Object.defineProperty(target, key, {
                get: getter,
                set: setter,
                enumerable: true,
                configurable: true
            });
        }
    }
    exports.InheritedProperty = InheritedProperty;
});
//# sourceMappingURL=InheritedProperty.js.map