#!/usr/bin/env bash
#MISE description="Display current release state: package.json version, latest git tag, number of unreleased commits, working directory cleanliness, and GH_TOKEN/GH_ACCOUNT configuration. Read-only, no side effects. Use before release to assess readiness."
set -euo pipefail

echo "═══════════════════════════════════════════════════════════"
echo "  Release Status"
echo "═══════════════════════════════════════════════════════════"

# Current version
CURRENT=$(jq -r '.version' package.json)
echo "Current version: v$CURRENT"

# Latest tag
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
echo "Latest git tag:  $LATEST_TAG"

# Commits since tag
if [[ "$LATEST_TAG" != "none" ]]; then
    COMMITS=$(git rev-list "$LATEST_TAG"..HEAD --count)
    echo "Commits since:   $COMMITS"
fi

# Working directory status
if [[ -z "$(git status --porcelain)" ]]; then
    echo "Working dir:     ✓ clean"
else
    echo "Working dir:     ✗ dirty"
    git status --short | head -5
fi

# GitHub auth (token check - no API calls to avoid process storms)
if [[ -n "${GH_TOKEN:-}" ]]; then
    echo "GitHub token:    ✓ present (${#GH_TOKEN} chars)"
    if [[ -n "${GH_ACCOUNT:-}" ]]; then
        echo "Target account:  $GH_ACCOUNT"
    fi
else
    echo "GitHub token:    ✗ not set (run: eval \"\$(mise env)\")"
fi

echo ""
