#!/usr/bin/env bash
# Render all Mermaid .mmd diagrams to high-resolution PNGs
# Usage: bash render_diagrams.sh

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
DIAGRAMS_DIR="${SCRIPT_DIR}/diagrams"
OUTPUT_DIR="${DIAGRAMS_DIR}/rendered"

mkdir -p "${OUTPUT_DIR}"

echo "Rendering Mermaid diagrams..."
for mmd_file in "${DIAGRAMS_DIR}"/*.mmd; do
    filename="$(basename "${mmd_file}" .mmd)"
    output_file="${OUTPUT_DIR}/${filename}.png"
    echo "  ${filename}.mmd -> ${filename}.png"
    mmdc -i "${mmd_file}" -o "${output_file}" -s 3 -w 2400 -b white --quiet
done

echo "Done! Rendered $(ls -1 "${OUTPUT_DIR}"/*.png 2>/dev/null | wc -l | tr -d ' ') diagrams to ${OUTPUT_DIR}/"
