#!/bin/bash
set -euo pipefail

MANIFEST_URL='https://excel.jpdz.app/excel-addin/manifest.xml'
WEF_DIR="$HOME/Library/Containers/com.microsoft.Excel/Data/Documents/wef"
TARGET="$WEF_DIR/excel-agent-manifest.xml"

mkdir -p "$WEF_DIR"
curl -fsSL "$MANIFEST_URL" -o "$TARGET"

osascript -e 'tell application "Microsoft Excel" to quit' >/dev/null 2>&1 || true
open -a "Microsoft Excel"

echo "Excel Agent installed from $MANIFEST_URL"
echo ""
echo "Next steps:"
echo "1. In Excel, click Edit if the workbook is read-only."
echo "2. Open Home > Add-ins, or Insert > Add-ins."
echo "3. Choose Excel Agent. In some Excel builds it appears under Developer Add-ins."
echo ""
echo "If Excel Agent is still missing:"
echo "- Fully quit Excel with Cmd+Q and reopen it."
echo "- Confirm this file exists: $TARGET"
echo "- Clear the Office add-in cache, then run this installer again."
