#!/bin/bash

APPDIR="/usr/share/kanshi-manager"

source "$APPDIR/config.sh"
source "$APPDIR/profiles.sh"
source "$APPDIR/ui.sh"

check_config

while true; do

ACTION=$(main_menu | cut -d'|' -f1)

case "$ACTION" in

    "Manage Profiles")
        PROFILE=$(select_profile)
	echo "SELECTED PROFILE=[$PROFILE]" > /tmp/profile-debug.txt
        if [ -n "$PROFILE" ]; then

            show_profile "$PROFILE" | yad \
                --text-info \
                --title="Profile: $PROFILE" \
                --width=600 \
                --height=400

            yad --question \
                --title="Apply Profile" \
                --text="Apply profile '$PROFILE'?"

            if [ $? -eq 0 ]; then
                activate_profile "$PROFILE"
                message "Profile applied: $PROFILE"
            fi

        fi
        ;;

    "Current View")
        current_view
    ;;

    "Reset Config")
      if reset_config; then
        message "Configuration restored."
      else
        error "No backup configuration found."
      fi
    ;;

    "Reload kanshi")
        reload_kanshi
        message "kanshi reloaded."
        ;;

    "Quit")
        exit 0
        ;;

esac

done
