import { getStudioStage } from "@/lib/studio-canvas-stage";

/** Wait for Konva to paint after store-driven layer changes */
export function scheduleSceneThumbnailCapture(
  capture: () => void
): void {
  requestAnimationFrame(() => {
    requestAnimationFrame(capture);
  });
}

export function captureSceneThumbnailFromStage(): string | null {
  const stage = getStudioStage();
  if (!stage) return null;

  try {
    return stage.toDataURL({ pixelRatio: 0.2 });
  } catch {
    return null;
  }
}
