"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SyncSkipUnderPriority = void 0;
const react_1 = require("react");
const context_1 = require("./context");
const SyncSkipUnderPriorityInstances = [];
const SyncSkipUnderPriority = ({ priority }) => {
    const sync = (0, context_1.useBridgeSync)();
    (0, react_1.useEffect)(() => {
        const instance = {
            priority,
        };
        SyncSkipUnderPriorityInstances.push(instance);
        const update = () => {
            // among all the available priorities, we set the highest
            // if there is no longer SyncSkipUnderPriority mounted, we go back to -1
            const priority = SyncSkipUnderPriorityInstances.length === 0
                ? -1
                : Math.max(...SyncSkipUnderPriorityInstances.map(i => i.priority));
            sync({
                type: "SET_SKIP_UNDER_PRIORITY",
                priority,
            });
        };
        update();
        return () => {
            const i = SyncSkipUnderPriorityInstances.indexOf(instance);
            if (i === -1)
                return;
            SyncSkipUnderPriorityInstances.splice(i, 1);
            update();
        };
    }, [sync, priority]);
    return null;
};
exports.SyncSkipUnderPriority = SyncSkipUnderPriority;
//# sourceMappingURL=SyncSkipUnderPriority.js.map