{ lib, config, pkgs, ... }:
let
  icons = fetchTarball {
    url = "https://files.huwe.mooo.com/waybar.tar.gz";
    sha256 = "0h5r8r7vscm6yv25kgyzx5y325n5ri78n28vmdvgmysp351drm57";
  };
in
lib.mkIf config.desktop.wm.niri.enable {
  home-manager.users.willifan = {
    programs.waybar = {
      enable = true;
      settings = {
        mainBar = {
          layer = "top";
          position = "top";
          height = 25;
          output = [
            "eDP-1"
          ];
          modules-left = [ "clock" "mpris" ];
          modules-center = [ "niri/workspaces" ];
          modules-right = [ "tray" "group/ressources" "group/peripherals" "group/wireless" "group/power" ];

          "group/ressources" = {
            orientation = "inherit";
            modules = [ "group/cpu" "group/memory" ];
          };
          "group/peripherals" = {
            orientation = "inherit";
            modules = [ "group/volume" "group/backlight" ];
          };
          "group/wireless" = {
            orientation = "inherit";
            modules = [ "group/networking" "group/bluetooth" ];
          };
          "group/power" = {
            orientation = "inherit";
            modules = [ "group/battery" "image#power" ];
          };


          "clock" = {
            interval = 1;
            format = "{:%H:%M:%S}";
          };
          "mpris" = {
            format = "";
            format-playing = "{dynamic}";
            dynamic-order = [ "title" "artist" "album" "position" "length" ];
            dynamic-len = 30; 
          };
          "niri/workspaces" = {
            all-outputs = true;
          };

          "group/cpu" = {
            orientation = "inherit";
            modules = [ "image#cpu" "cpu" ];
          };
          "image#cpu" = {
            path = "${icons}/cpu.png";
            size = 16;
          };
          "cpu" = {
            format = "{usage}%";
          };

          "group/memory" = {
            orientation = "inherit";
            modules = [ "image#memory" "memory" ];
          };
          "image#memory" = {
            path = "${icons}/ram.png";
            size = 16;
          };
          "memory" = {
            format = "{percentage}%";
          };

          "group/volume" = {
            orientation = "inherit";
            modules = [ "image#volume" "wireplumber" ];
          };
          "image#volume" = {
            path = "${icons}/volume.png";
            size = 16;
          };
          "wireplumber" = {
            format = "{volume}%";
          };

          "group/backlight" = {
            orientation = "inherit";
            modules = [ "image#backlight" "backlight" ];
          };
          "image#backlight" = {
            path = "${icons}/brightness.png";
            size = 16;
          };
          "backlight" = {
            format = "{percent}%";
          };

          "group/networking" = {
            orientation = "inherit";
            modules = [ "image#networking" "network" ];
          };
          "image#networking" = {
            path = "${icons}/wifiHigh.png";
            size = 16;
          };
          "network" = {
            format = "{signalStrength}%";
          };

          "group/bluetooth" = {
            orientation = "inherit";
            modules = [ "image#bluetooth" "bluetooth" ];
          };
          "image#bluetooth" = {
            path = "${icons}/bluetooth.png";
            size = 16;
          };
          "bluetooth" = {
            format = "{status}";
          };

          "group/battery" = {
            orientation = "inherit";
            modules = [ "image#battery" "battery" ];
          };
          "image#battery" = {
            path = "${icons}/battery.png";
            size = 16;
          };
          "battery" = {
            format = "{capacity}%";
          };

          "image#power" = {
            path = "${icons}/power.png";
            size = 16;
          };
        };
      };

      systemd = {
        enable = true;
      };

    };
  };
}