#!/bin/bash

XNOMAD_SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )

xmonad_install_list_debian=(xmonad xmonad-contrib xmobar)
xmonad_install_list_arch=(xmonad xmonad-contrib xmobar)

install_xmonad()
{
	graphics_install_prompt "Xnomad Will be installed"

	cd $XNOMAD_SCRIPT_DIR

	case $OS in
	  debian)
		 install_from_list "${xmonad_install_list_debian[@]}"
		;;

	  arch)
		 install_from_list "${xmonad_install_list_arch[@]}"
		;;

	  rasberry)
		;;

	  *)
		echo "Invalid os is selectred"
		exit_abord
		;;
	esac

	if [[ -d "$USER_DOTFILE_DIR/xmobar" ]]
	then 
		graphics_comment "Xmobar config directory exists a backup will be made"
		mv $USER_DOTFILE_DIR/xmobar $USER_DOTFILE_DIR/xmobar_back
		mkdir -p $USER_DOTFILE_DIR/xmobar	
	else
		mkdir -p $USER_DOTFILE_DIR/xmobar	
	fi
	
	if [[ -d "$USER_DOTFILE_DIR/xmobar" ]]
	then
		graphics_comment "Xmonad config directory exists a backup will be made"
		mv $USER_DOTFILE_DIR/xmonad $USER_DOTFILE_DIR/xmonad_back
		mkdir -p $USER_DOTFILE_DIR/xmonad	
	else
		mkdir -p $USER_DOTFILE_DIR/xmonad	
	fi
	
	if [[ -d "/home/$USER/.xmonad" ]]
	then
		graphics_comment "Xmonad defualt config at /home/$USER/.xmonad is found and will be deleted"
		sudo rm -r /home/$USER/.xmonad/ 
	fi

	graphics_comment "You are installing for a : $PLATFORM"

	graphics_comment "Copying Xmonad Config files"
	cp $DOTFILE_DIR/xmonad/*  $USER_DOTFILE_DIR/xmonad/

	graphics_comment "Copying Xmobar Config files"
	echo "$DOTFILE_DIR/xmobar/xmobarrc_$PLATFORM.hs  $USER_DOTFILE_DIR/xmobar/xmobarrc.hs"
	cp $DOTFILE_DIR/xmobar/xmobarrc_$PLATFORM.hs  $USER_DOTFILE_DIR/xmobar/xmobarrc.hs

	echo "$DOTFILE_DIR/xmobar/ip_$OS.sh  $USER_DOTFILE_DIR/xmobar/ip.sh"
	cp $DOTFILE_DIR/xmobar/ip_$OS.sh  $USER_DOTFILE_DIR/xmobar/ip.sh

	echo "$DOTFILE_DIR/xmobar/get_kernel.sh $USER_DOTFILE_DIR/xmobar/"
	cp $DOTFILE_DIR/xmobar/get_kernel.sh $USER_DOTFILE_DIR/xmobar/
	
	echo "$DOTFILE_DIR/xmobar/battery.sh $USER_DOTFILE_DIR/xmobar/"
	cp $DOTFILE_DIR/xmobar/battery.sh $USER_DOTFILE_DIR/xmobar/
	
	xmonad --recompile

	graphics_install_prompt "Xnomad installation complete"
	cd $MAIN_DIR
}
