"use client";

import type { ExportedMessageRepository } from "@assistant-ui/core";
import { createContext, useContext } from "react";

type ClawSessionReplayContextValue = {
	replaySession: (
		sessionId: string,
		repository: ExportedMessageRepository,
	) => void;
};

const ClawSessionReplayContext =
	createContext<ClawSessionReplayContextValue | null>(null);

export const ClawSessionReplayProvider = ClawSessionReplayContext.Provider;

export function useClawSessionReplay() {
	const value = useContext(ClawSessionReplayContext);
	if (!value) {
		throw new Error(
			"useClawSessionReplay must be used within ClawSessionReplayProvider",
		);
	}
	return value;
}
