#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title WordPress Gallery Upload
# @raycast.mode fullOutput

# Optional parameters:
# @raycast.icon 📷
# @raycast.packageName WordPress Tools
# @raycast.description Upload a folder of images to WordPress and create a draft gallery post

# Arguments:
# @raycast.argument1 { "type": "text", "placeholder": "Subfolder name (e.g. Tamron300samples)" }
# @raycast.argument2 { "type": "text", "placeholder": "Post title (optional — uses folder name if blank)", "optional": true }

# ── SET YOUR BASE FOLDER HERE ──────────────────────────────────────
BASE_FOLDER="$HOME/Pictures/the617"
# ──────────────────────────────────────────────────────────────────

SUBFOLDER="$1"
TITLE="$2"

# If the argument looks like a full path (starts with / or ~), use it directly.
# Otherwise treat it as a subfolder name inside BASE_FOLDER.
# This means you can type just "Tamron300samples" for ~/Pictures/the617/Tamron300samples
# or override with a full path like ~/Pictures/other-folder if needed.
if [[ "$SUBFOLDER" == /* ]] || [[ "$SUBFOLDER" == ~* ]]; then
    FOLDER="${SUBFOLDER/#\~/$HOME}"
else
    FOLDER="$BASE_FOLDER/$SUBFOLDER"
fi

# Activate the virtual environment
source ~/wp-uploader-env/bin/activate

# Run the Python script, passing title only if one was provided
if [ -n "$TITLE" ]; then
    python3 -u ~/Documents/coding/wordpress/wp_gallery_upload.py "$FOLDER" --title "$TITLE"
else
    python3 -u ~/Documents/coding/wordpress/wp_gallery_upload.py "$FOLDER"
fi
