import { Context } from "../core/context.js";
export type TaskSource = (() => unknown) | Promise<unknown> | null | undefined;
export interface TasksOptions {
    /**
     * If true, focus is restored on the last active element when there are no more pending tasks in this instance.
     *
     * By default, this is inherited from the parent or true of there is none.
     */
    restoreFocus?: boolean;
}
/**
 * Represents a set of pending tasks in a specific context.
 *
 * This is meant to be used for preventing concurrent user interaction in a specific context.
 */
export declare class Tasks {
    #private;
    /**
     * Create a new tasks instance with the specified parent.
     *
     * @param parent The parent to use. Default is no parent.
     */
    constructor(parent?: Tasks, options?: TasksOptions);
    /**
     * The parent instance or undefined if there is none.
     */
    get parent(): Tasks | undefined;
    /**
     * True if this instance has any pending tasks.
     *
     * @example
     * ```tsx
     * <div inert={() => tasks.selfPending}>...</div>
     * ```
     */
    get selfPending(): boolean;
    /**
     * True if this instance or any of it's parents has any pending tasks.
     *
     * @example
     * ```tsx
     * <button disabled={() => tasks.pending}>...</button>
     * ```
     */
    get pending(): boolean;
    /**
     * Pretend, that there is a pending task until the current lifecycle is disposed.
     */
    setPending(): void;
    /**
     * Wait for an async function or a promise.
     *
     * @param source The async function or promise to wait for.
     */
    waitFor(source: TaskSource): void;
    /**
     * Create a new tasks instance using the current instance as parent.
     */
    static fork(options?: TasksOptions): Tasks;
}
/**
 * Context for the current {@link Tasks} instance.
 */
export declare const TASKS: Context<Tasks | undefined>;
/**
 * Check if there are any pending tasks in the current tasks instance.
 *
 * This can be used in conjuction with {@link waitFor} to indicate if there are any pending tasks.
 *
 * This is meant to be used for preventing concurrent user interaction in a specific context.
 *
 * @example
 * ```tsx
 * <div inert={isSelfPending}>...</div>
 * ```
 */
export declare function isSelfPending(): boolean;
/**
 * Check if there are any pending tasks in the current tasks instance or any of it's parents.
 *
 * This can be used in conjunction with {@link waitFor} to disable inputs and buttons while there are any pending tasks.
 *
 * This is meant to be used for preventing concurrent user interaction in a specific context.
 *
 * @example
 * ```tsx
 * <button disabled={isPending}>...</button>
 * ```
 */
export declare function isPending(): boolean;
/**
 * Pretend, that there is a pending task in the current tasks instance until the current lifecycle is disposed.
 *
 * This is meant to be used for preventing concurrent user interaction in a specific context.
 *
 * @example
 * ```tsx
 * import { TASKS, Tasks, capture, setPending, isPending } from "rvx";
 *
 * TASKS.inject(new Tasks(), () => {
 *   isPending(); // => false
 *   const stop = capture(setPending);
 *   isPending(); // => true
 *   stop();
 *   isPending(); // => false
 * });
 * ```
 */
export declare function setPending(): void;
/**
 * Use the current tasks instance to wait for an async function or promise.
 *
 * This is meant to be used for preventing concurrent user interaction in a specific context.
 *
 * @param source The async function or promise to wait for.
 */
export declare function waitFor(source: TaskSource): void;
