#!/bin/bash

# Determine the directory where this script is located
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Target extension directory
EXT_DIR="$HOME/Library/Application Support/Adobe/CEP/extensions/com.local.photoshop.jsxpanel"

echo "Installing Nueva Print Panel..."

# Create directory if it doesn't exist
mkdir -p "$EXT_DIR"

# Extract ZXP (which is just a ZIP) directly to the extensions folder
rm -f "$EXT_DIR/jsx/"*.jsx
unzip -o "$DIR/NuevaPrintPanel.zxp" -d "$EXT_DIR" > /dev/null 2>&1

if [ $? -eq 0 ]; then
    echo "--------------------------------------------------------"
    echo "Installation Successful!"
    echo "Please restart Photoshop to see the Nueva Print Panel."
    echo "--------------------------------------------------------"
else
    echo "--------------------------------------------------------"
    echo "Installation Failed! Make sure you extracted the ZIP folder before running."
    echo "--------------------------------------------------------"
fi

# Enable PlayerDebugMode just in case for CEP extensions to load without issues
defaults write com.adobe.CSXS.9 PlayerDebugMode 1
defaults write com.adobe.CSXS.10 PlayerDebugMode 1
defaults write com.adobe.CSXS.11 PlayerDebugMode 1

echo "Press any key to close this window..."
read -n 1 -s
