/* eslint-disable @typescript-eslint/no-explicit-any */
const propertiesSymbol = Symbol('properties');
/**
 * Reactive decorator that calls the `render()` function when the value of the property change.
 */
export default function reactive() {
    return (target, context) => {
        const { kind } = context;
        if (kind === 'accessor') {
            const accessorTarget = target;
            return {
                set(value) {
                    let map = Reflect.get(accessorTarget, propertiesSymbol);
                    if (!map) {
                        map = {};
                        Reflect.set(accessorTarget, propertiesSymbol, map);
                    }
                    if (map[context.name] === context.name) {
                        return;
                    }
                    if (value === undefined) {
                        // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
                        delete map[context.name];
                    }
                    else {
                        map[context.name] = value;
                    }
                    if (typeof this.render === 'function') {
                        this.render();
                    }
                },
                get() {
                    const map = Reflect.get(accessorTarget, propertiesSymbol) || {};
                    return map[context.name];
                },
            };
        }
        else if (kind === 'setter') {
            const { name } = context;
            return function (value) {
                const oldValue = this[name];
                if (value === oldValue) {
                    return;
                }
                ;
                target.call(this, value);
                if (typeof this.render === 'function') {
                    this.render();
                }
            };
        }
        throw new Error(`Unsupported decorator location: ${kind}`);
    };
}
//# sourceMappingURL=reactive.js.map