import { useStore } from 'jotai/react';
import { createStore, Atom } from 'jotai/vanilla';
import { INTERNAL_Store, INTERNAL_AtomState } from 'jotai/vanilla/internals';

type DevStore = {
    get_internal_weak_map: () => {
        get: (atom: Atom<unknown>) => INTERNAL_AtomState | undefined;
    };
    get_mounted_atoms: () => Set<Atom<unknown>>;
    restore_atoms: (values: Iterable<readonly [Atom<unknown>, unknown]>) => void;
};
type StoreWithoutDevMethods = ReturnType<typeof createStore>;
type StoreWithDevMethods = INTERNAL_Store & DevStore;
type Store = StoreWithoutDevMethods | StoreWithDevMethods;
type Options = Parameters<typeof useStore>[0];
type AnyAtomValue = unknown;
type AnyAtom = Atom<AnyAtomValue>;
type AtomsValues = Map<AnyAtom, AnyAtomValue>;
type AtomsDependents = Map<AnyAtom, Set<AnyAtom>>;
type AtomsSnapshot = Readonly<{
    values: AtomsValues;
    dependents: AtomsDependents;
}>;

export type { AtomsSnapshot as A, Options as O, Store as S };
