/**
 * Runs when observed properties change, e.g. property or state, but before the component updates. To wait for an
 * update to complete after a change occurs, use `await this.updateComplete` in the handler. To start watching after the
 * initial update/render, use `{ waitUntilFirstUpdate: true }` or `this.hasUpdated` in the handler.
 *
 * ```ts
 * @Watch('propName')
 * onPropertyChange(oldValue, newValue) {
 *     ...
 * }
 * ```
 *
 * @public
 */
export function Watch(propName, options) {
    return (protoOrDescriptor, name) => {
        const { willUpdate } = protoOrDescriptor;
        options = ({
            waitUntilFirstUpdate: false,
            ...options
        });
        protoOrDescriptor.willUpdate = function (changedProps) {
            willUpdate.call(this, changedProps);
            if (changedProps.has(propName)) {
                const oldValue = changedProps.get(propName);
                const newValue = this[propName];
                if (oldValue !== newValue) {
                    if (!options?.waitUntilFirstUpdate || this.hasUpdated) {
                        this[name].call(this, oldValue, newValue);
                    }
                }
            }
        };
    };
}
//# sourceMappingURL=WatchDecorator.js.map