import { useBulkImportContext } from "../contexts/bulk-import-context.js";
import { useSidePanelContext } from "../contexts/side-panel-context.js";
import { Toast } from "./toast.js";

export function BulkImportToasts() {
	const { state, reset } = useBulkImportContext();
	const { bulkImportMode, isRightPanelCollapsed } = useSidePanelContext();
	const visible = !bulkImportMode || isRightPanelCollapsed;

	if (!visible) return null;

	if (state.status === "loading") {
		return (
			<Toast
				message={`Loading sources... ${state.completed + state.failed}/${state.total}`}
				progress={
					state.total > 0 ? (state.completed + state.failed) / state.total : 0
				}
				onDismiss={() => {}}
			/>
		);
	}

	if (state.status === "complete") {
		return (
			<Toast
				message="All sources loaded"
				onDismiss={reset}
				autoDismissMs={3000}
			/>
		);
	}

	if (state.status === "partial-failure") {
		return (
			<Toast
				message={`Loaded ${state.completed}/${state.total} sources (${state.failed} failed)`}
				onDismiss={reset}
			/>
		);
	}

	return null;
}
