"""Summarize the active scene and check external still images."""
from pathlib import Path

import bpy

scene = bpy.context.scene
render = scene.render
camera = scene.camera.name if scene.camera else "none"
lines = [
    f"Scene: {scene.name}",
    f"Active camera: {camera}",
    f"Engine: {render.engine}",
    f"Render size: {render.resolution_x} × {render.resolution_y} at {render.resolution_percentage}%",
    f"Frames {scene.frame_start}–{scene.frame_end} at {render.fps / render.fps_base:g} fps",
    f"Output path: {render.filepath}",
    "",
    "Used still-image files in this .blend (including data from other scenes)",
]
external = [
    image for image in bpy.data.images
    if image.users and image.source == "FILE" and not image.packed_files
]
for image in external:
    path = bpy.path.abspath(image.filepath, library=image.library)
    if image.filepath.startswith("//") and not (bpy.data.is_saved or image.library):
        status = "SAVE FIRST"
    else:
        status = "OK" if path and Path(path).is_file() else "MISSING"
    lines.append(f"{status} · {image.name} · {path or '(no path)'}")
if not external:
    lines.append("No unpacked still-image files to check.")
lines.append("Check sequences, tiled images, audio, linked .blend files, and the final export separately.")

report = next((text for text in bpy.data.texts if text.get("rp_handoff_report")), None)
if report is None:
    report = bpy.data.texts.new("Rough Pass Handoff Report")
    report["rp_handoff_report"] = True
report.clear()
report.write("\n".join(lines) + "\n")
print(f"Open {report.name!r} in the Text Editor.")
