{
  pkgs,
  config,
  lib,
  ...
}:
with lib;
let
  cfg = config.eboskma.programs.hyprland;
  terminal = "${pkgs.foot}/bin/footclient";
  dmenu = "${pkgs.rofi}/bin/rofi -show drun -no-lazy-grab";
  menu = "${pkgs.rofi}/bin/rofi -show run -no-lazy-grab";
  rofiPower = pkgs.writeShellScriptBin "rofi-power" (builtins.readFile ../sway/powermenu.sh);
  powerMenu = "${rofiPower}/bin/rofi-power";
  swaylockcmd = "${pkgs.swaylock}/bin/swaylock --ignore-empty-password --daemonize --show-failed-attempts --indicator-caps-lock --image ${../../../wallpapers/river-2560.png} --scaling fill";
in
{
  options.eboskma.programs.hyprland = {
    enable = mkEnableOption "Hyprland";
  };

  config = mkIf cfg.enable {
    wayland.windowManager.hyprland = {
      enable = true;

      settings = {
        monitor = "DP-2,2560x1440@165,0x0,1";

        general = {
          gaps_out = 10;
        };

        decoration = {
          rounding = 5;
          inactive_opacity = 0.9;
          dim_inactive = true;
          dim_strength = 0.5;
        };

        animations = [
          "workspaces,1,3,default"
          "windows,1,3,default"
          "windowsOut,1,3,default"
        ];

        input = {
          kb_layout = "us";
          kb_options = "lv3:ralt_switch,eurosign:5";
          natural_scroll = true;
        };

        misc = {
          no_vfr = false;
          focus_on_activate = false;
        };

        binds = {
          workspace_back_and_forth = true;
        };

        "$mod" = "SUPER";

        bind =
          [
            "$mod,Return,exec,${terminal}"
            "$mod_SHIFT,Q,killactive"
            "$mod,S,exec,${dmenu}"
            "$mod_SHIFT,S,exec,${menu}"

            "$mod,N,movefocus,l"
            "$mod,E,movefocus,d"
            "$mod,I,movefocus,u"
            "$mod,O,movefocus,r"

            "$mod_SHIFT,N,movewindow,l"
            "$mod_SHIFT,E,movewindow,d"
            "$mod_SHIFT,O,movewindow,r"
            "$mod_SHIFT,I,movewindow,u"

            "$mod_SHIFT,Space,togglefloating,active"

            "$mod,T,fullscreen,0"
            "$mod_SHIFT,T,fullscreen,1"

            "$mod,1,workspace,1"
            "$mod,2,workspace,2"
            "$mod,3,workspace,3"
            "$mod,4,workspace,4"
            "$mod,5,workspace,5"
            "$mod,6,workspace,6"
            "$mod,7,workspace,7"
            "$mod,8,workspace,8"
            "$mod,9,workspace,9"
            "$mod,0,workspace,10"

            "$mod_SHIFT,1,movetoworkspacesilent,1"
            "$mod_SHIFT,2,movetoworkspacesilent,2"
            "$mod_SHIFT,3,movetoworkspacesilent,3"
            "$mod_SHIFT,4,movetoworkspacesilent,4"
            "$mod_SHIFT,5,movetoworkspacesilent,5"
            "$mod_SHIFT,6,movetoworkspacesilent,6"
            "$mod_SHIFT,7,movetoworkspacesilent,7"
            "$mod_SHIFT,8,movetoworkspacesilent,8"
            "$mod_SHIFT,9,movetoworkspacesilent,9"
            "$mod_SHIFT,0,movetoworkspacesilent,10"

            "$mod_SHIFT,Minus,movetoworkspacesilent,special"
            "$mod,Minus,togglespecialworkspace"

            "$mod_SHIFT,C,exec,${config.wayland.windowManager.hyprland.package}/bin/hyprctl reload"

            "$mod_SHIFT,F,exec,${powerMenu}"
            "$mod,L,exec,${swaylockcmd}"

            "$mod_SHIFT,K,pin"

            "$mod,Print,exec,${pkgs.grim}/bin/grim"
            "$mod_SHIFT,Print,exec,${pkgs.grim}/bin/grim | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png -f"

            ",XF86AudioRaiseVolume,exec,${pkgs.pamedia}/bin/pamedia up"
            ",XF86AudioLowerVolume,exec,${pkgs.pamedia}/bin/pamedia down"
            ",XF86AudioMute,exec,${pkgs.pamedia}/bin/pamedia mute"
            ",XF86Calculator,exec,${pkgs.gnome-calculator}/bin/gnome-calculator"

            "$mod,D,exec,${pkgs.swaynotificationcenter}/bin/swaync-client -t -sw"

            "$mod,W,togglegroup"
            "$mod,N,changegroupactive,b"
            "$mod,O,changegroupactive,f"
          ]
          ++ (lib.optional config.eboskma.programs.emacs.enable "$mod,C,exec,${config.eboskma.programs.emacs.package}/bin/emacsclient -c");

        bindm = [
          "$mod,mouse:272,movewindow"
          "$mod,mouse:273,resizewindow"
        ];

        exec = [ "${pkgs.networkmanagerapplet}/bin/nm-applet --indicator" ];

        exec-once = [
          "${pkgs.swaybg}/bin/swaybg -i ${../../../wallpapers/river-2560.png} -m fill"
          "${config.wayland.windowManager.hyprland.package}/bin/hyprctl setcursor Nordzy-cursors 24"
          "${pkgs.systemd}/bin/systemctl --user start swaync"
          "${pkgs.systemd}/bin/systemctl --user start fcitx5-daemon"
        ];
      };
    };

    systemd.user.services.hypridle = {
      Unit = {
        Description = "Idle manager for Wayland (Hyprland)";
        Documentation = "man:swayidle(1)";
        PartOf = "graphical-session.target";
      };

      Service = {
        ExecStart = "${pkgs.swayidle}/bin/swayidle -w timeout 900 '${swaylockcmd}' timeout 1200 '${config.wayland.windowManager.hyprland.package}/bin/hyprctl dispatch dpms off' resume '${config.wayland.windowManager.hyprland.package}/bin/hyprctl dispatch dpms on'";
      };

      Install = {
        WantedBy = [ "hyprland-session.target" ];
      };
    };
  };
}