#!/bin/bash
# ========================================================
# PortFactory POS - macOS Kiosk Thermal Print Launcher Setup
# ========================================================

echo "========================================================"
echo " Setting up PortFactory POS Kiosk Printing for macOS... "
echo "========================================================"
echo ""

DESKTOP_DIR="$HOME/Desktop"
APP_DIR="$HOME/Applications/PortFactoryPOS"
mkdir -p "$APP_DIR"

LAUNCHER_SCRIPT="$APP_DIR/launch-pos.sh"

cat << 'EOF' > "$LAUNCHER_SCRIPT"
#!/bin/bash
CHROME="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
EDGE="/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"
BRAVE="/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
USER_DATA="$HOME/Library/Application Support/PortFactoryPOS"

if [ -f "$CHROME" ]; then
    "$CHROME" --kiosk-printing --user-data-dir="$USER_DATA" --app=https://pos.portfactory.com &
elif [ -f "$EDGE" ]; then
    "$EDGE" --kiosk-printing --user-data-dir="$USER_DATA" --app=https://pos.portfactory.com &
elif [ -f "$BRAVE" ]; then
    "$BRAVE" --kiosk-printing --user-data-dir="$USER_DATA" --app=https://pos.portfactory.com &
else
    open -a "Google Chrome" "https://pos.portfactory.com"
fi
EOF

chmod +x "$LAUNCHER_SCRIPT"

# Create Desktop Shortcut .command
DESKTOP_LAUNCHER="$DESKTOP_DIR/PortFactory POS.command"

cat << 'EOF' > "$DESKTOP_LAUNCHER"
#!/bin/bash
"$HOME/Applications/PortFactoryPOS/launch-pos.sh"
EOF

chmod +x "$DESKTOP_LAUNCHER"

echo "[✓] PortFactory POS Desktop Launcher created at:"
echo "    $DESKTOP_LAUNCHER"
echo ""
echo "To start silent thermal printing, double-click 'PortFactory POS' on your Desktop!"
echo ""
read -p "Press Enter to finish..."
