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

let
  cfg = config.wayland.windowManager.sway;
  bg = "#150F19";
  fg = "#D099F5";
  bg-inactive = "#6b4c7f";
  bg-urgent = "#f47a99";
  laptop-screen-name = "eDP-2";
in
{
  wayland.windowManager.sway = {
    enable = true;
    checkConfig = true;
    wrapperFeatures = {
      base = true;
      gtk = true;
    };
    systemd = {
      enable = true;
      xdgAutostart = true;
    };
    swaynag.enable = true;
    config = {
      startup = [
        { command = "poweralertd"; }
        {
          command = ''
            swayidle -w \
               timeout 300 'swaylock -f -c 000000' \
               timeout 600 'swaymsg "output * power off"' resume 'swaymsg "output * power on"' \
               before-sleep 'swaylock -f -c 000000'
          '';
        }
      ];

      modifier = "Mod4";
      menu = "${pkgs.wofi}/bin/wofi --show drun";
      # Switch to ghostty ?
      terminal = "${pkgs.ghostty}/bin/ghostty";

      output = {
        "*" = {
          bg = "~/.config/background fill #2c6325";
        };

        "${laptop-screen-name}" = {
          scale = "1.25";
          mode = "2560x1600@165Hz";
          # pos = "1920 0 res 2880x1800";
        };
      };

      input = {
        "type:keyboard" = {
        	xkb_layout = "fr";
        	xkb_variant = "oss";
        };
        
        "type:touchpad" = {
        	dwt = "disabled";
        	click_method = "button_areas";
        	tap = "enabled";
        	natural_scroll = "enabled";
        	drag_lock = "disabled";
        };
        
        # "2362:628:PIXA3854:00_093A:0274_Touchpad" = {
        # 	dwt = "disabled";
        # 	click_method = "button_areas";
        # 	tap = "enabled";
        # 	natural_scroll = "enabled";
        # };

        # "12972:24:Framework_Laptop_16_Keyboard_Module_-_ISO" = {
        # 	xkb_layout = "fr";
        # 	xkb_variant = "oss";
        # };
      };

      window = {
        commands = [
          {
            command = ''title_format "[XWayland] %title"'';
            criteria = {
              shell = "xwayland";
            };
          }
          {
            command = "inhibit_idle fullscreen";
            criteria = {
              app_id = "^.*";
            };
          }
        ];
      };

      floating.modifier = "${cfg.config.modifier} normal";

      keybindings = lib.mkOptionDefault {
        "${cfg.config.modifier}+n" = "exec ${pkgs.nautilus}/bin/nautilus -w";
        "${cfg.config.modifier}+Shift+n" = "exec ${pkgs.swaynotificationcenter}/bin/swaync-client -t -sw";

        "${cfg.config.modifier}+e" = lib.mkForce "exec ${pkgs.wlogout}/bin/wlogout";

        "${cfg.config.modifier}+ampersand" = "workspace 1";
        "${cfg.config.modifier}+eacute" = "workspace 2";
        "${cfg.config.modifier}+quotedbl" = "workspace 3";
        "${cfg.config.modifier}+apostrophe" = "workspace 4";
        "${cfg.config.modifier}+parenleft" = "workspace 5";
        "${cfg.config.modifier}+minus" = "workspace 6";
        "${cfg.config.modifier}+egrave" = "workspace 7";
        "${cfg.config.modifier}+underscore" = "workspace 8";
        "${cfg.config.modifier}+ccedilla" = "workspace 9";
        "${cfg.config.modifier}+agrave" = "workspace 10";

        "${cfg.config.modifier}+Shift+ampersand" = "move container to workspace 1";
        "${cfg.config.modifier}+Shift+eacute" = "move container to workspace 2";
        "${cfg.config.modifier}+Shift+quotedbl" = "move container to workspace 3";
        "${cfg.config.modifier}+Shift+apostrophe" = "move container to workspace 4";
        "${cfg.config.modifier}+Shift+parenleft" = "move container to workspace 5";
        "${cfg.config.modifier}+Shift+minus" = "move container to workspace 6";
        "${cfg.config.modifier}+Shift+egrave" = "move container to workspace 7";
        "${cfg.config.modifier}+Shift+underscore" = "move container to workspace 8";
        "${cfg.config.modifier}+Shift+ccedilla" = "move container to workspace 9";
        "${cfg.config.modifier}+Shift+agrave" = "move container to workspace 10";

        "${cfg.config.modifier}+Shift+equal" = "move scratchpad";
        "${cfg.config.modifier}+equal" = "scratchpad show";

      	"Print" = ''exec ${pkgs.grim}/bin/grim -g "$(${pkgs.slurp}/bin/slurp)" "$HOME/Images/Captures d’écran/grim/$(date --iso-8601=seconds).png"'';
      	"Shift+Print" = ''exec ${pkgs.grim}/bin/grim -c -o ${laptop-screen-name} "$HOME/Images/Captures d’écran/grim/$(date --iso-8601=seconds).png"'';
      };

      # bindswitches = {
      #   "lid:on" = {
      #     reload = true;
      #     locked = true;
      #     action = "output ${laptop-screen-name} disable";
      #   };
      #   "lid:off" = {
      #     reload = true;
      #     locked = true;
      #     action = "output ${laptop-screen-name} enable";
      #   };
      # };
      
      bars = [
        {
          command = "${pkgs.waybar}/bin/waybar";
          position = "bottom";
        }
      ];

      fonts = {
        names = ["Amy Mono" "JetBrains Mono NFP" "Adwaita"];
      };

      colors = {
        background = bg;
        unfocused = {
          background = bg;
          border = bg;
          childBorder = bg;
          indicator = bg;
          text = fg;
        };
        focused = {
          background = fg;
          border = fg;
          childBorder = fg;
          indicator = fg;
          text = bg;
        };
        focusedInactive = {
          background = bg-inactive;
          border = bg-inactive;
          childBorder = bg-inactive;
          indicator = bg-inactive;
          text = bg;
        };
        placeholder = {
          background = bg;
          border = bg;
          childBorder = bg;
          indicator = bg;
          text = fg;
        };
        urgent = {
          background = bg-urgent;
          border = bg-urgent;
          childBorder = bg-urgent;
          indicator = bg-urgent;
          text = bg;
        };
      };
    };

    extraConfigEarly = ''
      exec --no-startup-id lxpolkit
    '';

    extraConfig = ''
      # Gestures
      bindgesture swipe:right workspace prev
      bindgesture swipe:left workspace next
      bindgesture swipe:down workspace prev
      bindgesture swipe:up workspace next

      # Special keys to adjust volume via PulseAudio
      # bindsym --locked XF86AudioMute exec ${pkgs.wireplumber}/bin/wpctl set-mute \@DEFAULT_SINK@ toggle
      # bindsym --locked XF86AudioLowerVolume exec ${pkgs.wireplumber}/bin/wpctl set-volume \@DEFAULT_SINK@ 5%-
      # bindsym --locked XF86AudioRaiseVolume exec ${pkgs.wireplumber}/bin/wpctl set-volume \@DEFAULT_SINK@ 5%+
      # bindsym --locked XF86AudioMicMute exec ${pkgs.wireplumber}/bin/wpctl set-mute \@DEFAULT_SOURCE@ toggle
      # bindsym --locked Shift+XF86AudioLowerVolume exec ${pkgs.wireplumber}/bin/wpctl set-volume \@DEFAULT_SOURCE@ 5%-
      # bindsym --locked Shift+XF86AudioRaiseVolume exec ${pkgs.wireplumber}/bin/wpctl set-volume \@DEFAULT_SOURCE@ 5%+
      
      bindsym --locked XF86AudioMute exec ${pkgs.swayosd}/bin/swayosd-client --output-volume mute-toggle
      bindsym --locked XF86AudioLowerVolume exec ${pkgs.swayosd}/bin/swayosd-client --output-volume lower --max-volume 120
      bindsym --locked XF86AudioRaiseVolume exec ${pkgs.swayosd}/bin/swayosd-client --output-volume raise --max-volume 120
      bindsym --locked Shift+XF86AudioMute exec ${pkgs.swayosd}/bin/swayosd-client --input-volume mute-toggle
      bindsym --locked Shift+XF86AudioLowerVolume exec ${pkgs.swayosd}/bin/swayosd-client --input-volume lower --max-volume 100
      bindsym --locked Shift+XF86AudioRaiseVolume exec ${pkgs.swayosd}/bin/swayosd-client --input-volume raise --max-volume 100

      # Special keys to adjust brightness via brightnessctl
      # bindsym --locked XF86MonBrightnessDown exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%-
      # bindsym --locked XF86MonBrightnessUp exec ${pkgs.brightnessctl}/bin/brightnessctl set 5%+

      bindsym --locked XF86MonBrightnessDown exec ${pkgs.swayosd}/bin/swayosd-client --brightness -5
      bindsym --locked XF86MonBrightnessUp exec ${pkgs.swayosd}/bin/swayosd-client --brightness +5

      bindsym XF86AudioPlay exec ${pkgs.swayosd}/bin/swayosd-client --playerctl play-pause
      bindsym XF86AudioNext exec ${pkgs.swayosd}/bin/swayosd-client --playerctl next
      bindsym --release Caps_Lock exec ${pkgs.swayosd}/bin/swayosd-client --caps-lock

      # 
      # Status Bar:
      #
      # Read `man 5 sway-bar` for more information about this section.
      # bar {
      #     swaybar_command waybar

      #     position bottom

      #     # When the status_command prints a new line to stdout, swaybar updates.
      #     # The default just shows the current date and time.
      #     status_command while date +'%Y-%m-%d %X'; do sleep 1; done

      #     colors {
      #         statusline #ffffff
      #         background #323232
      #         inactive_workspace #32323200 #32323200 #5c5c5c
      #     }
      # }
    '';
  };

  # xdg.portal.wlr.enable = true;

  services = {
    swayosd.enable = true;
    swaync = {
      enable = true;

      # From @shvedes on github
      settings = {
        # "$schema" = "/etc/xdg/swaync/configSchema.json";
        "positionX" = "left";
        "positionY" = "top";
      	"layer" = "overlay";
        "control-center-margin-top" = 10;
        "control-center-margin-bottom" = 10;
        "control-center-margin-right" = 10;
        "control-center-margin-left" = 10;
        "notification-icon-size" = 64;
        "notification-body-image-height" = 100;
        "notification-body-image-width" = 200;
        "timeout" = 10;
        "timeout-low" = 5;
        "timeout-critical" = 0;
        "fit-to-screen" = false;
        "control-center-width" = 500;
        "control-center-height" = 1025;
        "notification-window-width" = 440;
        "keyboard-shortcuts" = true;
        "image-visibility" = "when-available";
        "transition-time" = 200;
        "hide-on-clear" = true;
        "hide-on-action" = true;
        "script-fail-notify" = true;
        "widgets" = [
          "title"
          "dnd"
          "notifications"
      		"mpris"
      		"volume"
          "buttons-grid"
        ];
        "widget-config" = {
          "title" = {
            "text" = "Notification Center";
            "clear-all-button" = true;
            "button-text" = "󰆴 Clear All";
          };
          "dnd" = {
            "text" = "Do Not Disturb";
          };
          "label" = {
            "max-lines" = 1;
            "text" = "Notification Center";
          };
          "mpris" = {
            "image-size" = 96;
            "image-radius" = 7;
          };
          "volume" = {
            "label" = "󰕾";
      			"show-per-app" = true;
          };
          "buttons-grid" = {
            "actions" = [
              {
                "label" = "󰐥";
                "command" = "systemctl poweroff";
              }
              {
                "label" = "󰜉";
                "command" = "systemctl reboot";
              }
              {
                "label" = "󰌾";
                "command" = "${pkgs.swaylock}/bin/swaylock -f -c 000000";
              }
              {
                "label" = "󰍃";
                "command" = "${pkgs.sway}/bin/swaymsg exit";
              }
              {
                "label" = "󰤄";
                "command" = "systemctl suspend";
              }
              {
                "label" = "󰖩";
                "command" = "${pkgs.networkmanagerapplet}/bin/nm-connection-editor";
              }
              {
                "label" = "󰂯";
                "command" = "${pkgs.blueman}/bin/blueman-manager";
              }
            ];
          };
        };
      };
      style = ''
        /*
        @define-color cc-bg #32302f;
        @define-color noti-border-color #32302f;
        @define-color noti-bg #3c3836;
        @define-color noti-bg-darker #3c3836;
        @define-color noti-bg-hover rgb(27, 27, 43);
        @define-color noti-bg-focus rgba(27, 27, 27, 0.6);
        @define-color text-color #f9f5d7;
        @define-color text-color-disabled #bdae93;
        @define-color bg-selected #fabd2f;
        */

        @define-color cc-bg ${bg};
        @define-color noti-border-color ${fg};
        @define-color noti-bg ${bg};
        @define-color noti-bg-darker ${bg};
        @define-color noti-bg-hover ${bg};
        @define-color noti-bg-focus ${bg};
        @define-color text-color ${fg};
        @define-color text-color-disabled ${fg};
        @define-color bg-selected ${bg};
 
        * {
          font-family: JetBrainsMono NFP;
          font-weight: bold;
        	font-size: 14px;
        }

        .notification-row *,
        .control-center-list * {
          background: transparent;
          border-radius: 0;
        }
 
        .control-center .notification-row:focus,
        .control-center .notification-row:hover {
          opacity: 1;
          background: @noti-bg-darker;
        }
 
        .notification-row {
          outline: none;
          margin: 20px;
          padding: 0;
          background: transparent;
        }
 
        .notification {
          background: transparent;
          margin: 0px;
          border: none;
        }
 
        .notification-content {
          background: @cc-bg;
          padding: 7px;
          border-radius: 0px;
          border: 2px solid ${fg};
          margin: 0;
        }
 
        .close-button {
          background: ${fg};
          color: @cc-bg;
          text-shadow: none;
          padding: 0;
          border-radius: 0px;
          margin-top: 5px;
          margin-right: 5px;
        }
 
        .close-button:hover {
          box-shadow: none;
          background: ${fg};
          transition: all .15s ease-in-out;
          border: none
        }
 
        .notification-action {
          color: ${fg};
          border: 2px solid ${fg};
          border-radius: 0px;
          background: ${bg};
        }
 
        .notification-default-action,
          color: ${bg};
          background: ${fg};
          border-radius: 0;
        }
 
        .summary {
        	padding-top: 7px;
          font-size: 13px;
          color: ${fg};
        }
 
        .time {
          font-size: 11px;
          color: ${fg};
          margin-right: 24px
        }
 
        .body {
          font-size: 12px;
          color: ${fg};
        }
 
        .control-center {
          background: @cc-bg;
          border: 2px solid ${fg};
          border-radius: 0px;
        }
 
        .control-center-list {
          background: transparent;
        }
 
        .control-center-list-placeholder {
          opacity: .5;
        }
 
        .floating-notifications {
          background: transparent;
        }
 
        .blank-window {
          background: alpha(black, 0.1);
        }
 
        .widget-title {
          color: ${fg};
          background: @noti-bg-darker;
          padding: 5px 10px;
          margin: 10px 10px 5px 10px;
          font-size: 1.5rem;
          border-radius: 5px;
        }
 
        .widget-title>button {
          font-size: 1rem;
          color: @text-color;
          text-shadow: none;
          background: @noti-bg;
          box-shadow: none;
          border-radius: 5px;
        }
 
        .widget-title>button:hover {
          background: ${fg};
          color: @cc-bg;
        }
 
        .widget-dnd {
          background: @noti-bg-darker;
          padding: 5px 10px;
          margin: 5px 10px 10px 10px;
          border-radius: 5px;
          font-size: large;
          color: ${fg};
        }
 
        .widget-dnd>switch {
          border-radius: 4px;
          background: ${fg};
        }
 
        .widget-dnd>switch:checked {
          background: ${fg};
          border: 1px solid ${fg};
        }
 
        .widget-dnd>switch slider {
          background: @cc-bg;
          border-radius: 5px;
        }
 
        .widget-dnd>switch:checked slider {
          background: @cc-bg;
          border-radius: 5px;
        }
 
        .widget-label {
          margin: 10px 10px 5px 10px;
        }
 
        .widget-label>label {
          font-size: 1rem;
          color: @text-color;
        }
 
        .widget-mpris {
          color: @text-color;
          background: @noti-bg-darker;
          padding: 5px 10px 0px 0px;
          margin: 5px 10px 5px 10px;
          border-radius: 0px;
        }
 
        .widget-mpris > box > button {
          border-radius: 5px;
        }
 
        .widget-mpris-player {
          padding: 5px 10px;
          margin: 10px;
        }
 
        .widget-mpris-title {
          font-weight: 700;
          font-size: 1.25rem;
        }
 
        .widget-mpris-subtitle {
          font-size: 1.1rem;
        }
 
        .widget-buttons-grid {
          font-size: x-large;
          padding: 5px;
          margin: 5px 10px 10px 10px;
          border-radius: 5px;
          background: @noti-bg-darker;
        }
 
        .widget-buttons-grid>flowbox>flowboxchild>button {
          margin: 3px;
          background: @cc-bg;
          border-radius: 5px;
          color: @text-color;
        }
 
        .widget-buttons-grid>flowbox>flowboxchild>button:hover {
          background: ${fg};
          color: @cc-bg;
        }
 
        .widget-menubar>box>.menu-button-bar>button {
          border: none;
          background: transparent;
        }
 
        .topbar-buttons>button {
          border: none;
          background: transparent;
        }
      '';
    };

    blueman-applet = {
      enable = true;
      systemdTargets = [
        "sway-session.target"
      ];
    };
  };

  programs = {
    wofi = {
      enable = true;
      settings = {};
      style = ''
        window {
          margin: 5px;
          border: 2px solid ${fg};
          background-color: ${fg};
        }

        #input {
          margin: 5px;
          border: 2px solid ${bg};
          background-color: ${bg};
        }

        #inner-box {
          margin: 5px;
          border: 2px solid ${bg};
          background-color: ${bg};
        }

        #outer-box {
          margin: 1px;
          border: 2px solid ${bg};
          background-color: ${bg};
        }

        #scroll {
          margin: 5px;
          border: 2px solid ${bg};
          background-color: ${bg};
        }

        #text {
          margin: 5px;
          border: 2px ${bg};
          color: ${fg};
        }  

        #entry:selected {
          background-color: ${fg};
        }

        #text:selected {
          color: ${bg};
        }
      '';
    };

    waybar = {
      enable = true;
      # From https://github.com/saatvik333/niri-dotfiles
      settings = {
        mainBar = {
          reload_style_on_change = true;
          toggle = true;
          layer = "top";
          position = "left";
          margin-top = 0;
          margin-bottom = 0;
          margin-left = 0;
          margin-right = 0;
          spacing = 0;
          modules-left = ["custom/notification" "clock" "cpu"];
          modules-center = ["mpd" "sway/workspaces" "privacy"];
          modules-right = [
            "group/extras"
            "network"
            "bluetooth"
            "pulseaudio#microphone"
            "group/audio"
            "group/brightness"
            "idle_inhibitor"
            "battery"
          ];

          idle_inhibitor = {
            format = "<span size='12pt'>{icon}</span>";
            format-icons = {
              activated = "󰈈";
              deactivated = "󰈉";
            };
          };
          "custom/notification" = {
            "tooltip" = true;
            "format" = "<span size='16pt'>{icon}</span>";
            "format-icons" = {
              "notification" = "󱅫";
              "none" = "󰂜";
              "dnd-notification" = "󰂠";
              "dnd-none" = "󰪓";
              "inhibited-notification" = "󰂛";
              "inhibited-none" = "󰪑";
              "dnd-inhibited-notification" = "󰂛";
              "dnd-inhibited-none" = "󰪑";
            };
            "return-type" = "json";
            "exec-if" = "which swaync-client";
            "exec" = "swaync-client -swb";
            # "on-click" = "swaync-client -t -sw";
            # format = "󰂚";
            # tooltip = false;
            on-click = "${pkgs.swaynotificationcenter}/bin/swaync-client -t -sw";
            on-click-right = "${pkgs.swaynotificationcenter}/bin/swaync-client -d -sw";
            escape = true;
          };
          "group/extras" = {
            "orientation" = "inherit";
            "drawer" = {
              "transition-duration" = 400;
              "children-class" = "extras";
              "transition-left-to-right" = false;
            };
            "modules" = [
              "custom/menu"
              "tray"
            ];
          };
          "group/brightness" = {
            "orientation" = "inherit";
            "drawer" = {
              "transition-duration" = 400;
              "children-class" = "brightness";
              "transition-left-to-right" = false;
            };
            "modules" = [
              "backlight"
              "backlight/slider"
            ];
          };
          "group/audio" = {
            "orientation" = "inherit";
            "drawer" = {
              "transition-duration" = 400;
              "children-class" = "audio";
              "transition-left-to-right" = false;
            };
            "modules" = [
              "pulseaudio"
              "pulseaudio/slider"
            ];
          };
          "sway/workspaces" = {
            "format" = "{icon}";
            "on-click" = "activate";
            "format-icons" = {
              "1" = "<span size='10pt'></span>";
              "2" = "<span size='10pt'></span>";
              "3" = "<span size='10pt'></span>";
              "4" = "<span size='10pt'></span>";
              "5" = "<span size='10pt'></span>";
              "default" = "󰄰";
              "active" = "󰄯";
            };
            "sort-by-number" = true;
          };
          "cpu" = {
            "format" = "{icon}";
            "format-icons" = [
              "<span size='14pt'>⠁</span>"
              "<span size='14pt'>⠉</span>"
              "<span size='14pt'>⠙</span>"
              "<span size='14pt'>⠛</span>"
              "<span size='14pt'>⠟</span>"
              "<span size='14pt'>⠿</span>"
            ];
            "interval" = 1;
            "tooltip" = true;
            "tooltip-format" = "CPU Frequency = {avg_frequency} GHz";
            "on-click" = "alacritty -e btm";
          };
          "clock" = {
            "interval" = 1;
            "format" = "{:%H\n%M\n%S}";
              "format-alt" = "{:%d\n%m\n%y}";
              "tooltip-format" = "<tt><small>{calendar}</small></tt>";
          };
          "mpd" = {
            "format" = "<span size='14pt'>󰏤</span>";
            "format-paused" = "<span size='14pt'>󰐊</span>";
            "format-stopped" = "<span size='14pt'>󰓛</span>";
            "format-disconnected" = "<span size='14pt'>󰓛</span>";
            "interval" = 1;
            "on-click" = "${pkgs.mpc}/bin/mpc toggle";
            "on-click-right" = "${pkgs.mpc}/bin/mpc next";
            "on-click-middle" = "${pkgs.mpc}/bin/mpc previous";
            "tooltip" = true;
            "tooltip-format" = "{title}";
          };
          "custom/menu" = {
            "format" = "<span size='16pt'>󰅃</span>";
            "tooltip" = false;
          };
          "tray" = {
            "spacing" = 16;
            "reverse-direction" = true;
            "icon-size" = 16;
            "show-passive-items" = false;
          };
          "privacy" = {
            "icon-size" = 14;
            "transition-duration" = 250;
            "modules" = [
              {
                "type" = "screenshare";
                "tooltip" = false;
              }
            ];
            "ignore" = [
              {
                "type" = "screenshare";
                "name" = "obs";
              }
            ];
          };
          "network" = {
            "format-icons" = {
              "wifi" = [
                "<span size='12pt'>󰤯</span>"
                "<span size='12pt'>󰤟</span>"
                "<span size='12pt'>󰤢</span>"
                "<span size='12pt'>󰤥</span>"
                "<span size='12pt'>󰤨</span>"
              ];
              "ethernet" = "<span size='12pt'>󰈀</span>";
              "disabled" = "<span size='12pt'>󰤭</span>";
              "disconnected" = "<span size='12pt'>󰤩</span>";
            };
            "format-wifi" = "{icon}";
            "format-ethernet" = "{icon}";
            "format-disconnected" = "{icon}";
            "format-disabled" = "{icon}";
            "interval" = 5;
            "tooltip-format" = "{essid}\t{gwaddr}";
            "on-click" = "rfkill toggle wifi";
            "on-click-right" = "${pkgs.networkmanagerapplet}nm-connection-editor";
            "tooltip" = true;
            "max-length" = 20;
          };
          "bluetooth" = {
            "interval" = 5;
            "format-on" = "<span size='14pt'>󰂯</span>";
            "format-off" = "<span size='14pt'>󰂲</span>";
            "format-disabled" = "<span size='14pt'>󰂲</span>";
            "format-connected" = "<span size='14pt'>󰂱</span>";
            "format-no-controller" = "span size='14pt'>󰂯</span>";
            "tooltip" = true;
            "tooltip-format" = "{device_enumerate}";
            "tooltip-format-enumerate-connected" = "{device_address}";
            "tooltip-format-enumerate-connected-battery" = "{device_address} | Battery = {device_battery_percentage}%";
            "on-click" = "rfkill toggle bluetooth";
            "on-click-right" = "${pkgs.blueman}/bin/blueman-manager";
          };
          "pulseaudio#microphone" = {
            "format" = "{format_source}";
            "format-source" = "<span size='14pt'>󰍬</span>";
            "format-source-muted" = "<span size='14pt'>󰍭</span>";
            "on-click" = "pactl set-source-mute @DEFAULT_SOURCE@ toggle";
            "on-click-right" = "pavucontrol -t 4";
            "tooltip" = false;
          };
          "pulseaudio/slider" = {
            "min" = 0;
            "max" = 100;
            "orientation" = "vertical";
          };
          "pulseaudio" = {
            "interval" = 1;
            "format" = "{icon}";
            "format-icons" = [
              "<span size='14pt'>󰕿</span>"
              "<span size='14pt'>󰖀</span>"
              "<span size='14pt'>󰕾</span>"
            ];
            "format-muted" = "<span size='14pt'>󰝟</span>";
            "on-click-right" = "pavucontrol -t 3";
            "on-click" = "pactl set-sink-mute @DEFAULT_SINK@ toggle";
            "reverse-scrolling" = true;
            "tooltip" = true;
            "tooltip-format" = "Volume = {volume}%\n{desc}";
            "ignored-sinks" = [
              "Easy Effects Sink"
            ];
          };
          "backlight/slider" = {
            "min" = 0;
            "max" = 100;
            "orientation" = "vertical";
            "device" = "intel_backlight";
          };
          "backlight" = {
            "device" = "intel_backlight";
            "format" = "{icon}";
            "format-icons" = [
              "󰃚"
              "󰃛"
              "󰃜"
              "󰃝"
              "󰃞"
              "󰃟"
              "󰃠"
            ];
            "reverse-scrolling" = true;
            "smooth-scrolling-threshold" = 0.2;
            "tooltip" = false;
          };
          "battery" = {
            "interval" = 5;
            "states" = {
              "critical" = 10;
            };
            "format" = "{icon}";
            "format-icons" = [
              "<span size='14pt'>󰁺</span>"
              "<span size='14pt'>󰁻</span>"
              "<span size='14pt'>󰁼</span>"
              "<span size='14pt'>󰁽</span>"
              "<span size='14pt'>󰁾</span>"
              "<span size='14pt'>󰁿</span>"
              "<span size='14pt'>󰂀</span>"
              "<span size='14pt'>󰂁</span>"
              "<span size='14pt'>󰂂</span>"
              "<span size='14pt'>󰁹</span>"
            ];
            "format-charging" = "<span size='14pt'>󰂄</span>";
            "format-plugged" = "<span size='14pt'>󰚥</span>";
            "format-critical" = "<span size='14pt'>󰂃</span>";
            "tooltip" = true;
            "tooltip-format" = "Charge = {capacity}%";
            "tooltip-format-charging" = "Charging = {capacity}%";
          };
          "custom/powermenu" = {
            "format" = "<span size='13pt'>󰐥</span>";
            "on-click" = "$HOME/.config/rofi/powermenu/powermenu.sh";
            "tooltip" = false;
          };
        };
      };

      style = ''
        @define-color background ${bg};
        @define-color foreground ${fg};
        @define-color color1  #F38BA8;
        @define-color color2  #A6E3A1;
        @define-color color3  #F9E2AF;
        @define-color color4  #89B4FA;

        * {
          font-family: "JetBrainsMono NFP";
          font-size: 14pt;
          border-radius: 0;
          box-shadow: none;
        }

        window#waybar {
          background: @background;
        }

        #custom-notification:hover,
        #cpu:hover,
        #network:hover,
        #bluetooth:hover,
        #pulseaudio:hover,
        #pulseaudio.microphone:hover,
        #pulseaudio.sink-muted:hover,
        #brightness:hover,
        #battery:hover,
        #mpd:hover,
        #idle_inhibitor:hover,
        #custom-powermenu:hover {
          opacity: 0.5;
        }

        #custom-notification,
        #cpu,
        #clock,
        #custom-menu,
        #tray,
        #privacy,
        #network,
        #bluetooth,
        #pulseaudio,
        #pulseaudio.microphone,
        #backlight,
        #battery,
        #mpd,
        #idle_inhibitor,
        #custom-powermenu {
          color: @foreground;
          padding: 6px 0;
        }

        #mpd {
          border-bottom: 1px solid @foreground;
        }

        #workspaces {
          border-top: 1px solid @background;
        }

        #workspaces button {
          color: @foreground;
          padding: 6px 0;
        }
        #workspaces button.active {
          color: @color2;
        }
        #workspaces button.focused {
          background: @foreground;
          color: @background;
        }

        #privacy {
          margin: 4px;
          color: @color3;
        }

        #clock {
          color: @foreground;
          font-size: 16pt;
        }

        #network.disabled {
          color: @color1;
        }
        #network.wifi {
          color: @color2;
        }
        #network.ethernet {
          color: @color3;
        }

        #bluetooth.disabled {
          color: @color1;
        }
        #bluetooth.connected {
          color: @color4;
        }

        #pulseaudio.sink-muted:not(.microphone) {
          color: @color3;
        }
        #pulseaudio.microphone.source-muted {
          color: @color1;
        }

        #battery.plugged {
          color: @color4;
        }
        #battery.charging {
          color: @color2;
        }
        #battery.critical {
          color: @color3;
        }

        tooltip {
          background: @background;
          border: 1px solid @foreground;
        }
        tooltip * {
          color: @foreground;
          margin: 2px;
          background: @background;
        }

        #pulseaudio-slider,
        #backlight-slider {
          min-height: 80px;
        }

        #pulseaudio-slider slider,
        #backlight-slider slider {
          background: transparent;
        }

        #pulseaudio-slider trough,
        #backlight-slider trough {
          min-width: 8px;
        }

        #pulseaudio-slider highlight {
          background: @color4;
        }
        #backlight-slider highlight {
          background: @color3;
        }
      '';
    };
  };

  # services.network-manager-applet = {
  #   enable = true;
  # };
}
