#!/usr/bin/env -S bash

WALLPAPER_DIR="$HOME/images/wallpapers"
THEME=$(darkman get)
FLAGS=()

if [ ! -d "$WALLPAPER_DIR" ]; then
  echo "Wallpaper directory does not exist: $WALLPAPER_DIR"
  exit 1
fi

if [[ "$THEME" == "light" ]]; then
	FLAGS+=("-l")
fi

WALLPAPER=$(find "$WALLPAPER_DIR" -type f \( -iname "*.jpg" -o -iname "*.png" -o -iname "*.jpeg" \) | shuf -n 1)

swww img "$WALLPAPER" \
	--transition-type random \
	--transition-duration 0.8 \
	--transition-fps 60

if command -v "wal" &> /dev/null; then
	wal -i "$WALLPAPER" -n ${FLAGS[@]}
	cp ~/.cache/wal/colors.scss ~/.config/ags/styles/colors.scss
fi

if command -v "pywalfox" &> /dev/null; then
	pywalfox $THEME
	pywalfox update
fi