#!/usr/bin/env bash

module_description() {
  printf "AGS (Aylur's Gtk Shell) - Widget system for Hyprland\n"
}

module_required() { return 0; }
module_should_skip() {
  command -v ags >/dev/null 2>&1
}

module_main() {
  log_section "AGS Installation"

  if command -v ags >/dev/null 2>&1; then
    tui_success "AGS already installed"
    return 0
  fi

  if ! have git; then
    tui_warn "git not available. Install ags manually after installing git."
    return 0
  fi

  tui_warn "AGS must be built from source (npm install + Go + meson)."
  tui_warn "This will first build 3 libastal libraries, then AGS itself."
  tui_warn "Total time can be 5-15 minutes depending on your system."
  printf '\n'

  if ! tui_confirm "Install AGS now?"; then
    tui_info "AGS installation skipped."
    return 0
  fi

  local deps=("libastal-io-git" "libastal-git" "libastal-4-git")
  if ! install_aur "${deps[@]}"; then
    tui_warn "Some AGS dependencies failed to build."
    if ! tui_confirm "Try to install AGS anyway?"; then
      tui_info "AGS installation aborted."
      return 0
    fi
  fi

  tui_info "Building aylurs-gtk-shell-git from AUR..."
  install_aur "aylurs-gtk-shell-git"
}
