{ config, lib, pkgs, ... }:

let 
  cfg = config.samfelag.modules.desktop.tools.eww;
  hyprCfg = config.samfelag.modules.desktop.wm.hyprland;
in {

  options.samfelag.modules.desktop.tools.eww = {
    enable = lib.mkEnableOption "eww";
  };

  config = lib.mkIf cfg.enable {

    # - Configuration ----------------------------

    environment.systemPackages = with pkgs; [
      eww
      # Scripts' dependencies
      jq
      socat
    ];

    hm.xdg.configFile."eww/eww.yuck".source = ../../../config/eww/eww.yuck;
    hm.xdg.configFile."eww/eww.scss".source = ../../../config/eww/eww.scss;
    hm.xdg.configFile."eww/bars".source = ../../../config/eww/bars;
    hm.xdg.configFile."eww/widgets".source = ../../../config/eww/widgets;
    hm.xdg.configFile."eww/scripts".source = ../../../config/eww/scripts;

    # - Execute on startup -----------------------
    hm.wayland.windowManager.hyprland.settings.exec-once = lib.mkIf hyprCfg.enable [
      "eww open top-bar"
    ];

    # - Themeing ---------------------------------
    hm.xdg.configFile."eww/colour-scheme.scss".text = ''
      $base00: #${config.colorScheme.palette.base00};
      $base01: #${config.colorScheme.palette.base01};
      $base02: #${config.colorScheme.palette.base02};
      $base03: #${config.colorScheme.palette.base03};
      $base04: #${config.colorScheme.palette.base04};
      $base05: #${config.colorScheme.palette.base05};
      $base06: #${config.colorScheme.palette.base06};
      $base07: #${config.colorScheme.palette.base07};
      $base08: #${config.colorScheme.palette.base08};
      $base09: #${config.colorScheme.palette.base09};
      $base0A: #${config.colorScheme.palette.base0A};
      $base0B: #${config.colorScheme.palette.base0B};
      $base0C: #${config.colorScheme.palette.base0C};
      $base0D: #${config.colorScheme.palette.base0D};
      $base0E: #${config.colorScheme.palette.base0E};
      $base0F: #${config.colorScheme.palette.base0F};
    '';

    # - Dependencies -----------------------------
    samfelag.modules.desktop.tools.rofi.enable = true;

  };
}
