#!/usr/bin/env bash
# Batch process existing screenshots with borders
# Usage: bb-screenshot-batch.sh <directory>

set -euo pipefail

SOURCE_DIR="${1:-.}"
OUTPUT_DIR="${SOURCE_DIR}/processed"

if [[ ! -d "$SOURCE_DIR" ]]; then
    echo "Error: Directory not found: $SOURCE_DIR"
    exit 1
fi

mkdir -p "$OUTPUT_DIR"

echo "[+] Processing screenshots in: $SOURCE_DIR"
echo "[+] Output directory: $OUTPUT_DIR"
echo ""

# Find all PNG and JPG images
IMAGES=$(find "$SOURCE_DIR" -maxdepth 1 \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" \) | sort)

if [[ -z "$IMAGES" ]]; then
    echo "[-] No images found in $SOURCE_DIR"
    exit 1
fi

COUNT=0
TOTAL=$(echo "$IMAGES" | wc -l)

while IFS= read -r IMAGE; do
    ((COUNT++))
    FILENAME=$(basename "$IMAGE")
    OUTPUT_FILE="$OUTPUT_DIR/$FILENAME"

    echo "[$COUNT/$TOTAL] Processing: $FILENAME"

    # Add professional border and shadow
    convert "$IMAGE" \
        -bordercolor '#333333' -border 2 \
        -bordercolor white -border 10 \
        -bordercolor '#333333' -border 2 \
        \( +clone -background black -shadow 80x5+5+5 \) \
        +swap -background white -layers merge +repage \
        "$OUTPUT_FILE"

done <<< "$IMAGES"

echo ""
echo "[✓] Processed $COUNT images"
echo "[✓] Output: $OUTPUT_DIR"
