/* @oracle/oraclejet-preact: undefined */
'use strict';

require('./VisBusyStateContext-223f53dd.js');
var useVisBusyStateContext = require('./useVisBusyStateContext-090a1870.js');
var hooks = require('preact/hooks');

/**
 * @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
 */
/**
 * Provides way to add and resolve a busy state.
 */
function useVisAddBusyState(description) {
    const { addBusyState } = useVisBusyStateContext.useVisBusyStateContext();
    const resolverRef = hooks.useRef();
    const onBusyEnd = hooks.useCallback(() => {
        resolverRef.current?.();
        resolverRef.current = undefined;
    }, []);
    const onBusyStart = hooks.useCallback(() => {
        // Resolve previous busy state if any
        onBusyEnd();
        resolverRef.current = addBusyState(description);
    }, [description, onBusyEnd, addBusyState]);
    // Resolve any pending busy state on unmount
    hooks.useLayoutEffect(() => onBusyEnd(), [onBusyEnd]);
    return {
        onBusyStart,
        onBusyEnd
    };
}

exports.useVisAddBusyState = useVisAddBusyState;
//# sourceMappingURL=useVisAddBusyState-1564f647.js.map
