/* eslint-disable @typescript-eslint/no-explicit-any */
/**
 * A field setter or accessor decorator that automatically calls `requestUpdate()` when a new value is set.
 *
 * @param options Update request options.
 */
export default function state(options = {}) {
    return (target, context) => {
        const { kind } = context;
        if (kind === 'accessor') {
            const accessorTarget = target;
            return {
                set(value) {
                    const oldValue = accessorTarget.get.call(this);
                    if (value === oldValue) {
                        return;
                    }
                    accessorTarget.set.call(this, value);
                    if (this.requestUpdate) {
                        this.requestUpdate(options);
                    }
                },
                get() {
                    return accessorTarget.get.call(this);
                },
            };
        }
        else if (kind === 'setter') {
            const { name } = context;
            return function (value) {
                const oldValue = this[name];
                if (value === oldValue) {
                    return;
                }
                ;
                target.call(this, value);
                if (this.requestUpdate) {
                    this.requestUpdate(options);
                }
            };
        }
        throw new Error(`Unsupported decorator location: ${kind}`);
    };
}
//# sourceMappingURL=state.js.map