/* @oracle/oraclejet-preact: undefined */
/**
 * @license
 * Copyright (c) %FIRST_YEAR% %CURRENT_YEAR%, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 * @ignore
 */
/**
 * Mocks the `pageX`, `pageY`, `offsetX`, and `offsetY` properties on the `MouseEvent.prototype`
 * for testing purposes (e.g. for when using userEvent.pointer)
 * See workaround in https://github.com/testing-library/user-event/issues/1037#issuecomment-1576780336
 * that this is based on.
 *
 * This function saves the original property descriptors, then redefines `pageX`, `pageY`, `offsetX`, and `offsetY`
 * to return the values of `clientX` and `clientY`. This allows tests to interact with these properties.
 * This function should be called in beforeEach of tests.
 *
 * @returns An object containing the original property descriptors, which should
 *          be used later to restore the original behavior.
 */
function mockMouseEventPageXYOffsetXY() {
    const originalPageXDescriptor = Object.getOwnPropertyDescriptor(MouseEvent.prototype, 'pageX');
    const originalPageYDescriptor = Object.getOwnPropertyDescriptor(MouseEvent.prototype, 'pageY');
    const originalOffsetXDescriptor = Object.getOwnPropertyDescriptor(MouseEvent.prototype, 'offsetX');
    const originalOffsetYDescriptor = Object.getOwnPropertyDescriptor(MouseEvent.prototype, 'offsetY');
    Object.defineProperties(MouseEvent.prototype, {
        pageX: {
            configurable: true,
            get() {
                return this.clientX;
            }
        },
        pageY: {
            configurable: true,
            get() {
                return this.clientY;
            }
        },
        offsetX: {
            configurable: true,
            get() {
                return this.clientX;
            }
        },
        offsetY: {
            configurable: true,
            get() {
                return this.clientY;
            }
        }
    });
    return {
        originalPageXDescriptor,
        originalPageYDescriptor,
        originalOffsetXDescriptor,
        originalOffsetYDescriptor
    };
}
/**
 * Restores the original `pageX`, `pageY`, `offsetX`, and `offsetY` property descriptors on the `MouseEvent.prototype`.
 *
 * This function should be called afterEach of tests to ensure that the `MouseEvent.prototype` is returned to its
 * original state.
 *
 * @param descriptors The output of mockMouseEventPageXYOffsetXY
 */
function restoreMouseEventPageXYOffsetXY(descriptors) {
    const { originalPageXDescriptor, originalPageYDescriptor, originalOffsetXDescriptor, originalOffsetYDescriptor } = descriptors;
    if (originalPageXDescriptor) {
        Object.defineProperty(MouseEvent.prototype, 'pageX', originalPageXDescriptor);
    }
    if (originalPageYDescriptor) {
        Object.defineProperty(MouseEvent.prototype, 'pageY', originalPageYDescriptor);
    }
    if (originalOffsetXDescriptor) {
        Object.defineProperty(MouseEvent.prototype, 'offsetX', originalOffsetXDescriptor);
    }
    if (originalOffsetYDescriptor) {
        Object.defineProperty(MouseEvent.prototype, 'offsetY', originalOffsetYDescriptor);
    }
}

export { mockMouseEventPageXYOffsetXY as m, restoreMouseEventPageXYOffsetXY as r };
//# sourceMappingURL=eventUtils-447f1bf1.js.map
