#!/bin/bash

sketchybar --set battery popup.drawing=toggle \
                         popup.background.drawing=on \
                         popup.background.color="0xff363a4f" \
                         popup.background.corner_radius=3


if /usr/local/bin/battery status | grep -q 'Your battery'; then
  sketchybar --set batteryStatus label="Maintaining" \
                                 label.color="0xffa6da95"
  sketchybar --set batteryMaintain label="Stop Maintaining" \
                                   label.color="0xffed8796" \
                                   click_script="/usr/local/bin/battery maintain stop && sketchybar --set battery popup.drawing=toggle"
else
  sketchybar --set batteryStatus label="Not Maintaining" \
                                 label.color="0xffed8796"
  sketchybar --set batteryMaintain label="Maintain" \
                                   label.color="0xffa6da95" \
                                   click_script="/usr/local/bin/battery maintain 80 && sketchybar --set battery popup.drawing=toggle"
fi

if [[ "$CHARGING" != "" ]]; then
  sketchybar --set batteryCharge label="Stop Charging" \
                                 label.color="0xffed8796"\
                                 click_script="/usr/local/bin/battery charging off && sketchybar --set battery popup.drawing=toggle"
else
  sketchybar --set batteryCharge label="Start Charging" \
                                 label.color="0xffa6da95"\
                                 click_script="/usr/local/bin/battery charging on && sketchybar --set battery popup.drawing=toggle"
fi
