import {useEffect, useMemo, useSyncExternalStore} from "react";
import type {Gallery_Case, Gallery_Frame_Mode} from "../protocol/gallery_types";
import {Gallery_Plot_Session} from "../session/gallery_plot_session";
export function use_plot_session(gallery_case: Gallery_Case, frame_mode: Gallery_Frame_Mode): [Gallery_Plot_Session, ReturnType<Gallery_Plot_Session["get_snapshot"]>] {
    const session=useMemo(()=>new Gallery_Plot_Session(gallery_case,frame_mode),[gallery_case,frame_mode]);
    const snapshot=useSyncExternalStore(session.subscribe,session.get_snapshot,session.get_snapshot);
    useEffect(()=>()=>session.dispose(),[session]);
    return [session,snapshot];
}
