#!/bin/bash

# change this to your eww bin. Don't question mine
EWW_BIN="$(which eww) -c $HOME/.config/eww/carbonmonoxide"
# EWW_BIN="$HOME/Packages/eww/target/release/eww"

dashboard() {
    LOCK_FILE="$HOME/.config/eww-dashboard.lock"

    run() {
        ${EWW_BIN} open dashboard
    }

    if [[ ! -f "$LOCK_FILE" ]]; then
        touch "$LOCK_FILE"
        run && echo "ok good!"
    else
        ${EWW_BIN} close dashboard
        rm "$LOCK_FILE" && echo "closed"
    fi
}

control() {
    LOCK_FILE="$HOME/.config/eww-control.lock"

    run() {
        ${EWW_BIN} open control_panel
    }

    if [[ ! -f "$LOCK_FILE" ]]; then
        touch "$LOCK_FILE"
        run && echo "ok good!"
    else
        ${EWW_BIN} close control_panel
        rm "$LOCK_FILE" && echo "closed"
    fi
}

calendar() {
    LOCK_FILE="$HOME/.config/eww-calendar.lock"

    run() {
        ${EWW_BIN} open calendar
    }

    if [[ ! -f "$LOCK_FILE" ]]; then
        touch "$LOCK_FILE"
        run && echo "ok good!"
    else
        ${EWW_BIN} close calendar
        rm "$LOCK_FILE" && echo "closed"
    fi
}

music() {
    LOCK_FILE="$HOME/.config/eww-music.lock"

    run() {
        ${EWW_BIN} open music
    }

    if [[ ! -f "$LOCK_FILE" ]]; then
        touch "$LOCK_FILE"
        run && echo "ok good!"
    else
        ${EWW_BIN} close music
        rm "$LOCK_FILE" && echo "closed"
    fi
}

if [ "$1" = "calendar" ]; then
    calendar
elif [ "$1" = "music" ]; then
    music
elif [ "$1" = "control" ]; then
    control
elif [ "$1" = "dashboard" ]; then
    dashboard
elif [ "$1" = "colourpick" ]; then
    hyprpicker -a
    notify-send -a colourpicker -i ~/.config/eww/image/eyedropper.png -t 3000 "Colour copied to clipboard"
elif [ "$1" = "scrop" ]; then
    # control
    # sleep 0.5
    grim -g "$(slurp)" - | wl-copy
    notify-send -a screenshot -i ~/.config/eww/image/screenshot.png -t 3000 "Screenshot Taken" "Image copied to clipboard"
elif [ "$1" = "sscreen" ]; then
    # control
    grim - | wl-copy
fi
