#!/bin/bash
set -euo pipefail

# Classic macOS Look Script
# Reduces Liquid Glass transparency, blur, and refraction as much as macOS allows.
# Double-click this file in Finder or run it in Terminal:
#   ./classic-macos-look.command          (interactive menu)
#   ./classic-macos-look.command --apply  (apply classic solid look)
#   ./classic-macos-look.command --revert (restore default macOS look)

OS_VERSION="$(sw_vers -productVersion 2>/dev/null || echo "unknown")"

apply_classic_look() {
  echo "Applying classic solid macOS look (detected macOS $OS_VERSION)..."

  # 1. Strip translucency/blur from menu bar, Dock, Control Center, sidebars, and windows
  defaults write com.apple.universalaccess reduceTransparency -bool true

  # 2. Add solid borders around windows, buttons, and controls
  defaults write com.apple.universalaccess increaseContrast -bool true

  # 3. Disable Liquid Glass rendering layer on macOS 26.0 (patched out in 26.1+)
  if [[ "$OS_VERSION" == "26.0" || "$OS_VERSION" == 26.0.* ]]; then
    defaults write -g com.apple.SwiftUI.DisableSolarium -bool YES
    echo "  - Applied DisableSolarium flag (supported on macOS 26.0)."
  fi

  restart_ui
  echo ""
  echo "Done! Classic solid look applied."
  echo "Tip: Log out and back in (or restart) for all apps and menus to update."
  echo "Tip: On macOS 26.1+, also check System Settings > Appearance > Liquid Glass and set it to Tinted."
}

revert_default_look() {
  echo "Reverting to default macOS appearance..."

  defaults write com.apple.universalaccess reduceTransparency -bool false
  defaults write com.apple.universalaccess increaseContrast -bool false
  defaults delete -g com.apple.SwiftUI.DisableSolarium 2>/dev/null || true

  restart_ui
  echo ""
  echo "Done! Default macOS appearance restored."
  echo "Tip: Log out and back in (or restart) for all apps and menus to update."
}

restart_ui() {
  echo "Refreshing Dock, Finder, and Menu Bar..."
  killall Dock 2>/dev/null || true
  killall Finder 2>/dev/null || true
  killall SystemUIServer 2>/dev/null || true
}

case "${1:-}" in
  --apply)
    apply_classic_look
    ;;
  --revert)
    revert_default_look
    ;;
  "")
    echo "=========================================="
    echo "  Classic macOS Look (Minimize Liquid Glass)"
    echo "=========================================="
    echo "1) Apply classic solid look"
    echo "2) Revert to default macOS look"
    echo "3) Cancel"
    echo ""
    read -r -p "Choose an option [1-3]: " choice
    case "$choice" in
      1) apply_classic_look ;;
      2) revert_default_look ;;
      *) echo "Cancelled." ;;
    esac
    ;;
  *)
    echo "Usage: $0 [--apply | --revert]"
    exit 1
    ;;
esac
