#!/bin/bash

sleep 5
screenshot_dir="$HOME/Screenshots"
timestamp=$(date +"%Y-%m-%d-%H-%M-%S")
screenshot_file="$screenshot_dir/screenshot_$timestamp.png"

# Function to select the region
select_region() {
    region=$(/usr/bin/slurp)
if [ -z "$region" ]; then
    echo "No region selected, retrying..."
    exit 1
fi
echo "$region"
}

# Function to take screenshot
take_screenshot() {
    /usr/bin/grim -g "$1" "$screenshot_file"
    ~/.local/bin/pastebin_client.sh upload "$screenshot_file" yes | /usr/bin/wl-copy
}

main() {
    while true; do
        region=$(select_region)
        if [ -n "$region" ]; then
            take_screenshot "$region"
            echo "Screenshot taken and uploaded."
            break
        else
            echo "No region selected. Try again..."
            sleep 2
        fi
    done
}

main

