#!/bin/bash

set -e

if [ "$EUID" -eq 0 ]; then
  echo "Error: This script should not be run as root"
  exit 1
fi

echo -e "This will reinstall all the default Omarchy packages and reset all default configs.\nWarning: All changes to configs will be lost.\n"

if gum confirm "Are you sure you want to reinstall and lose all config changes?"; then
  echo "Reinstalling Omarchy Package"
  sudo pacman -Syu --noconfirm --needed omarchy

  echo "Reinstalling missing Omarchy packages"
  mapfile -t packages < <(grep -v '^#' "$OMARCHY_PATH/install/omarchy-base.packages" | grep -v '^$')
  sudo pacman -Syu --noconfirm --needed "${packages[@]}"

  echo "Resetting all Omarchy configs"
  cp -R /etc/skel/.config/* ~/.config/

  $(bash $OMARCHY_PATH/install/config/theme.sh)
  $(bash $OMARCHY_PATH/install/config/git.sh)

  omarchy-refresh-limine
  omarchy-refresh-plymouth
  omarchy-nvim-setup
fi
