#!/usr/bin/env python3
"""Blur client names - v3 with better region detection."""

from PIL import Image, ImageFilter
import os

input_path = "/Users/assafdagan/.clawdbot/media/inbound/f01c84e1-5f12-4bcf-bfb8-257edba844eb.jpg"
output_path = "/Users/assafdagan/clawd/output/blurred-status-v3.jpg"

img = Image.open(input_path)
w, h = img.size
print(f"Image size: {w}x{h}")

# The image is 986x1600. Let me estimate line heights.
# Typical line height appears to be about 45-50px
# Headers are around 40-45px tall
# First content starts around y=75

# Client names to blur with more generous regions:
blur_regions = [
    # "*Phat Foods:* Week 1..." - first bullet under Active Projects  
    # Starts around y=120, "Phat Foods" is at x=30-220
    (25, 115, 235, 165),
    
    # "remaining)" continuation - blur it too
    (25, 155, 180, 200),
    
    # "*Spoken:* Dovi remarks..." second bullet
    (25, 195, 620, 245),
    
    # "*General:* SparkBeyond, White Space, Finally Foods"
    (160, 235, 720, 295),
    
    # "*1. Phat Foods Deadline Approaching*" - full header
    (0, 390, 620, 445),
    
    # "*2. Spoken Project (Dovi Remarks)*" header  
    (0, 545, 650, 600),
    
    # "1. *Phat Foods check-in*" in Tomorrow's Priorities
    (25, 1020, 400, 1085),
    
    # "2. *Complete Dovi review*"
    (25, 1085, 420, 1150),
]

result = img.copy()

for i, (x1, y1, x2, y2) in enumerate(blur_regions):
    x1 = max(0, x1)
    y1 = max(0, y1)
    x2 = min(w, x2)
    y2 = min(h, y2)
    
    cropped = img.crop((x1, y1, x2, y2))
    blurred = cropped.filter(ImageFilter.GaussianBlur(radius=30))
    result.paste(blurred, (x1, y1))
    print(f"Blurred region {i+1}: ({x1},{y1}) to ({x2},{y2})")

os.makedirs(os.path.dirname(output_path), exist_ok=True)
result.save(output_path, quality=95)
print(f"\nSaved: {output_path}")
