{
  config,
  pkgs,
  lib,
  ...
}: let
  for_hyprland = config.programs.waybar.enable && config.wayland.windowManager.hyprland.enable;
in {
  wayland.windowManager.hyprland = lib.mkIf for_hyprland {
    settings = {
      exec-once = [
        "${pkgs.waybar}/bin/waybar &"
        "${pkgs.networkmanagerapplet}/bin/nm-applet &"
        "${pkgs.pasystray}/bin/pasystray &"
        "${pkgs.blueman}/bin/blueman-applet &"
      ];
    };
  };

  programs.waybar = lib.mkIf for_hyprland {
    settings.mainBar = {
      position = "top";
      layer = "top";
      height = 5;
      margin-top = 0;
      margin-bottom = 0;
      margin-left = 0;
      margin-right = 0;
      modules-left = [
        "custom/launcher"
        "hyprland/workspaces"
      ];
      modules-center = [
        "hyprland/window"
      ];
      modules-right = [
        "clock"
        "cpu"
        "memory"
        "disk"
        "battery"
        "network"
        "tray"
      ];
      clock = {
        calendar = {
          format = {today = "<span color='#b4befe'><b>{}</b></span>";};
        };
        format = " {:%H:%M}";
        tooltip = "true";
        tooltip-format = "<big>{:%Y %B}</big>\n<tt><small>{calendar}</small></tt>";
        format-alt = " {:%d/%m}";
      };
      "hyprland/workspaces" = {
        active-only = false;
        disable-scroll = true;
        format = "{icon}";
        on-click = "activate";
        format-icons = {
          "1" = "1";
          "2" = "2";
          "3" = "3";
          "4" = "4";
          "5" = "5";
          "6" = "6";
          "7" = "7";
          "8" = "8";
          urgent = "";
          default = "";
          sort-by-number = true;
        };
        persistent-workspaces = {
          "1" = [];
          "2" = [];
          "3" = [];
          "4" = [];
          "5" = [];
          "6" = [];
          "7" = [];
          "8" = [];
        };
      };
      memory = {
        format = "󰟜 {}%";
        format-alt = "󰟜 {used} GiB"; # 
        interval = 2;
      };
      cpu = {
        format = "  {usage}%";
        format-alt = "  {avg_frequency} GHz";
        interval = 2;
      };
      disk = {
        # path = "/";
        format = "󰋊 {percentage_used}%";
        interval = 60;
      };
      network = {
        format-wifi = "  {signalStrength}%";
        format-ethernet = "󰀂 ";
        tooltip-format = "Connected to {essid} {ifname} via {gwaddr}";
        format-linked = "{ifname} (No IP)";
        format-disconnected = "󰖪 ";
      };
      tray = {
        icon-size = 20;
        spacing = 8;
      };
      pulseaudio = {
        format = "{icon} {volume}%";
        format-muted = "󰖁  {volume}%";
        format-icons = {
          default = [" "];
        };
        scroll-step = 5;
        on-click = "pamixer -t";
      };
      battery = {
        format = "{icon} {capacity}%";
        format-icons = [" " " " " " " " " "];
        format-charging = " {capacity}%";
        format-full = " {capacity}%";
        format-warning = " {capacity}%";
        interval = 5;
        states = {
          warning = 20;
        };
        format-time = "{H}h{M}m";
        tooltip = true;
        tooltip-format = "{time}";
      };
      "custom/launcher" = {
        format = "";
        on-click = "${pkgs.wofi}/bin/wofi --show drun";
        tooltip = "false";
      };
    };
    style = ''
      * {
          border: none;
          font-family: Font Awesome, Roboto, Arial, sans-serif;
          font-size: 13px;
          color: #ffffff;
          border-radius: 15px;
      }

      window {
        /*font-weight: bold;*/
      }
      window#waybar {
          border-style: none;
          border-width: 1px;
          border-color: #33ccff;
          background: rgba(0, 0, 0, 0);
      }
      /*-----module groups----*/
      .modules-right {
          background-color: rgba(0,43,51,0.85);
          margin: 2px 10px 2px 0;
      }
      .modules-left {
        margin: 2px 0 2px 5px;
        background-color: rgba(0,119,179,0.6);
      }
      /*-----modules indv----*/
      #workspaces button {
          padding: 1px 5px;
          background-color: transparent;
      }
      #workspaces button:hover {
          box-shadow: inherit;
        background-color: rgba(0,153,153,1);
      }
      #workspaces button.empty {
        color: rgba(0 ,40, 40, 40);
      }
      #workspaces button.active {
        background-color: rgba(0,43,51,0.85);
      }
      #window {
          border-style: solid;
          background-color: rgba(0,43,51,0.5);
          margin: 2px 5px;
          padding: 2px 5px;
          border-width: 1px;
          border-color: #33ccff;
      }
      #window.empty {
          border-style: none;
          background-color: transparent;
      }
      #custom-launcher {
          background-color: rgba(0,119,179,0.6);
          border-radius: 100px;
          margin: 5px 5px;
      }

      #clock,
      #battery,
      #cpu,
      #memory,
      #temperature,
      #network,
      #pulseaudio,
      #custom-media,
      #tray,
      #mode,
      #custom-power,
      #custom-menu,
      #idle_inhibitor {
          padding: 0 10px;
      }
      #mode {
          color: #cc3436;
          font-weight: bold;
      }
      #custom-power {
          background-color: rgba(0,119,179,0.6);
          border-radius: 100px;
          margin: 5px 5px;
          padding: 1px 1px 1px 6px;
      }
      /*-----Indicators----*/
      #idle_inhibitor.activated {
          color: #2dcc36;
      }
      #pulseaudio.muted {
          color: #cc3436;
      }
      #battery.charging {
          color: #2dcc36;
      }
      #battery.warning:not(.charging) {
        color: #e6e600;
      }
      #battery.critical:not(.charging) {
          color: #cc3436;
      }
      #temperature.critical {
          color: #cc3436;
      }
      /*-----Colors----*/
      /*
      *rgba(0,85,102,1),#005566 --> Indigo(dye)
      *rgba(0,43,51,1),#002B33 --> Dark Green
      *RGBA(0,153,153,1),#009999 --> PERSIAN GREEN
      *
      */
    '';
  };
}
