import { LRUCache } from 'lru-cache';
import { a as StorageElementType } from './StorageElementType-DkJ394kq.cjs';
export { S as StorageObjectType } from './StorageElementType-DkJ394kq.cjs';
export { S as StoredClassModel } from './StoredClassModel-LtyakzOw.cjs';
import { C as CachedMap } from './CachedMap-DZLvJAnA.cjs';

interface StorageExternalStoreHandler {
    /**
     * Triggered when {@link StorageManagerStatic.setVariable} is called.
     * The key is provided without any storage prefix.
     */
    onSetVariable?: (key: string, value: StorageElementType) => void;
    /**
     * Triggered when a temp variable is removed by {@link StorageManagerStatic.clearOldTempVariables}.
     * The key is provided without any storage prefix.
     */
    onClearOldTempVariable?: (key: string) => void;
    /**
     * Triggered when {@link StorageManagerStatic.removeVariable} is called.
     * The key is provided without any storage prefix.
     */
    onRemoveVariable?: (key: string) => void;
}

interface StorageGameStateItem<T = StorageElementType> {
    key: string;
    value: T;
}
/**
 * Interface exported storage data
 */
type StorageGameState = {
    /**
     * @deprecated
     */
    base?: StorageGameStateItem[];
    /**
     * @deprecated
     */
    temp?: StorageGameStateItem[];
    tempDeadlines: StorageGameStateItem<number>[];
    /**
     * @deprecated
     */
    flags?: string[];
    main: StorageGameStateItem[];
};

interface StorageManagerInterface {
    /**
     * The internal storage. **Do not modify this directly.**
     *
     * ATTENTION: If you edit this directly, the {@link cache} will not be updated.
     *
     * You can use Keyv with Pixi’VN by creating a new instance of Keyv and passing the storage object as a parameter.
     * ```ts
     * import { storage } from '@drincs/pixi-vn'
     * import Keyv from 'keyv';
     *
     * const keyvStorage = new Keyv({ store: storage.base });
     *
     * keyvStorage.get<string>("myValue").then((value) => {
     *     console.log(value);
     * });
     * ```
     */
    readonly base: Map<string, StorageElementType>;
    /**
     * The internal cache. **Do not modify this directly.**
     */
    readonly cache: LRUCache<string, any, unknown>;
    /**
     * Set the starting storage. The starting storage that will be used when the game starts.
     * **If variables are defined inside it, they can be edited during the game, but if you {@link delete} them, they will be restored to the starting storage.**
     * By default, the starting storage is empty.
     */
    set default(value: {
        [key: string]: StorageElementType;
    });
    /**
     * Set a variable in the storage
     * @param key The key of the variable
     * @param value The value of the variable. If undefined, the variable will be removed
     * @returns
     */
    set(key: string, value: StorageElementType): void;
    /**
     * Get a variable from the storage. If the variable is a temporary variable, it will return the temporary variable
     * @param key The key of the variable
     * @returns The value of the variable. If the variable does not exist, it will return undefined
     */
    get<T = StorageElementType>(key: string): T | undefined;
    /**
     * Remove a variable from the storage
     * @param key The key of the variable
     * @returns
     */
    remove(key: string): void;
    /**
     * Set a variable in the temporary storage. The lifespan of the variable is the number of opened labels.
     * To get the temporary variable, use {@link get}
     * @param key The key of the temporary variable
     * @param value The value of the temporary variable. If undefined, the variable will be removed
     * @returns
     */
    setTempVariable(key: string, value: StorageElementType): void;
    /**
     * Remove a temporary variable
     * @param key The key of the temporary variable
     */
    removeTempVariable(key: string): void;
    /**
     * Set a flag to true or false.
     * @param key The name of the flag
     * @param value The value of the flag.
     */
    setFlag(key: string, value: boolean): void;
    /**
     * Get the value of a flag
     * @param key The name of the flag
     * @returns The value of the flag
     */
    getFlag(key: string): boolean;
    /**
     * Configure the handler used to mirror game storage changes into an external reactive store.
     * Call this at any time to start/stop mirroring.
     * @param value The handler to set. If undefined, the handler will be removed.
     * @example
     * ```typescript
     * import { Store } from '@tanstack/store'
     *
     * // Create a TanStack store that mirrors the game storage variables
     * const gameStore = new Store<Record<string, unknown>>({})
     *
     * storage.setStorageHandler({
     *     onSetVariable: (key, value) => {
     *         gameStore.setState((state) => ({ ...state, [key]: value }))
     *     },
     *     onRemoveVariable: (key) => {
     *         gameStore.setState((state) => {
     *             const next = { ...state }
     *             delete next[key]
     *             return next
     *         })
     *     },
     *     onClearOldTempVariable: (key) => {
     *         gameStore.setState((state) => {
     *             const next = { ...state }
     *             delete next[key]
     *             return next
     *         })
     *     },
     * })
     * ```
     */
    setStorageHandler(value?: StorageExternalStoreHandler): void;
    /**
     * Clear the storage and the oidsUsed
     * @returns
     */
    clear(): void;
    /**
     * Export the storage to an object
     * @returns The object
     */
    export(): StorageGameState;
    /**
     * Restore the storage from an object
     * @param data The object
     */
    restore(data: StorageGameState): void;
}

declare namespace StorageManagerStatic {
    const storage: CachedMap<string, any>;
    const defaultStorage: CachedMap<string, any>;
    const tempStorageDeadlines: Map<string, number>;
    function clearOldTempVariables(openedLabelsNumber: number): void;
    function setExternalStoreHandler(handler?: StorageExternalStoreHandler): void;
    function setVariable(prefix: string, key: string, value: StorageElementType): void;
    function getVariable<T = StorageElementType>(prefix: string, key: string): T | undefined;
    function removeVariable(prefix: string, key: string): void;
    function setFlag(key: string, value: boolean): void;
    function getFlag(key: string): boolean;
}

declare const storage: StorageManagerInterface;

export { StorageElementType, type StorageExternalStoreHandler, type StorageGameState, type StorageManagerInterface, StorageManagerStatic, storage };
