#!/usr/bin/env bash

main() {
  : "${BRIGHTNESS_DAY:=100}"
  : "${BRIGHTNESS_TRANSITION:=50}"
  : "${BRIGHTNESS_NIGHT:=20}"
  : "${FADE_TIME:=60000}"

  if [[ "${1}" != period-changed ]]; then
    return
  fi

  case "${3}" in
  night)
    xbacklight -set "${BRIGHTNESS_NIGHT}" -time "${FADE_TIME}"
    ;;
  transition)
    xbacklight -set "${BRIGHTNESS_TRANSITION}" -time "${FADE_TIME}"
    ;;
  daytime)
    xbacklight -set "${BRIGHTNESS_DAY}" -time "${FADE_TIME}"
    ;;
  esac
}

main "$@"
