{
  host,
  config,
  lib,
  pkgs,
  inputs,
  myhostname,
  ...
}:
let
  hyprlandPkg = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland;
in
with lib;
{
  options = {
    hyprland = {
      enable = mkEnableOption "enables hyprland";
      theme = lib.mkOption {
        type = lib.types.str;
        default = "latte";
        description = "the theme for hyprland";
      };
    };
  };
  config = mkIf config.hyprland.enable {
    environment.systemPackages = with pkgs; [
      swww
      swappy
      ydotool
      wl-clipboard
      hyprpolkitagent
      hyprland-qtutils
      waypipe
      wmenu
      playerctl
    ];

    fonts.packages = with pkgs; [
      font-awesome
    ];

    services.greetd = {
      enable = true;
      settings = rec {
        initial_session = {
          command = "${pkgs.hyprland}/bin/Hyprland";
          user = "fw";
        };
        default_session = initial_session;
      };
    };

    nix.settings = {
      substituters = [ "https://hyprland.cachix.org" ];
      trusted-substituters = [ "https://hyprland.cachix.org" ];
      trusted-public-keys = [ "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" ];
    };
    programs.hyprland = {
      enable = true;
      package = inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.hyprland;
      portalPackage =
        inputs.hyprland.packages.${pkgs.stdenv.hostPlatform.system}.xdg-desktop-portal-hyprland;
    };
    home-manager.users.fw =
      { pkgs, ... }:
      {
        programs = {
          hyprlock = {
            enable = true;
          };
          rofi = {
            enable = true;
            font = lib.mkForce "FiraCode Nerd Font 18";
          };
        };
        services = {
          cliphist = {
            enable = true;
          };
          hypridle = {
            enable = true;
            settings = {
              general = {
                after_sleep_cmd = "hyprctl dispatch dpms on";
                ignore_dbus_inhibit = false;
                lock_cmd = "hyprlock";
              };

              listener = [
                {
                  timeout = 900;
                  on-timeout = "hyprlock";
                }
                {
                  timeout = 1200;
                  on-timeout = "hyprctl dispatch dpms off";
                  on-resume = "hyprctl dispatch dpms on";
                }
              ];
            };
          };
          hyprpaper = {
            enable = true;
            settings = {
              ipc = "on";
              splash = false;
              splash_offset = 2.0;

              preload = [
                "/home/fw/nix/wallpapers/nix-wallpaper-nineish-catppuccin-${config.hyprland.theme}.png"
                "/home/fw/nix/wallpapers/tux.catppuccin-${config.hyprland.theme}.jpg"
              ];

              wallpaper = [
                ",/home/fw/nix/wallpapers/nix-wallpaper-nineish-catppuccin-${config.hyprland.theme}.png"
              ];
            };
          };
        };

        wayland.windowManager.hyprland = {
          enable = true;
          xwayland = {
            enable = true;
          };

          settings = {
            "$terminal" = "kitty";
            "$mod" = "ALT";

            monitor = [
              "desc: ASUSTek COMPUTER INC ASUS PA279CV S4LMTF159462 (DP-1), 3840x2160@60, 0x0, 1.5, transform, 0"
              "desc: ASUSTek COMPUTER INC VG279 JBLMQS021792 (DP-1), 1920x1080@144, 0x0, 1"
              "eDP-1, 1920x1080@60, 0x0, 1, transform, 0"
              ",prefered,auto,1"
            ];

            xwayland = {
              force_zero_scaling = true;
            };

            general = {
              gaps_in = 7;
              gaps_out = 14;
              border_size = 2;
              layout = "dwindle";
              allow_tearing = true;
            };

            input = {
              kb_layout = "se";
              kb_options = [
                "caps:escape"
              ];

              follow_mouse = true;
              touchpad = {
                natural_scroll = true;
              };
              accel_profile = "flat";
              sensitivity = 0;
            };

            decoration = {
              rounding = 10;
              active_opacity = 0.9;
              inactive_opacity = 0.8;
              fullscreen_opacity = 0.9;

              blur = {
                enabled = true;
                xray = true;
                special = false;
                new_optimizations = true;
                size = 14;
                passes = 4;
                brightness = 1;
                noise = 0.01;
                contrast = 1;
                popups = true;
                popups_ignorealpha = 0.6;
                ignore_opacity = false;
              };
            };

            animations = {
              enabled = true;
              bezier = [
                "easeOutQuint,0.23,1,0.32,1"
                "easeInOutCubic,0.65,0.05,0.36,1"
                "linear,0,0,1,1"
                "almostLinear,0.5,0.5,0.75,1.0#fffff"
                "quick,0.15,0,0.1,1"
              ];
              animation = [
                "global, 1, 10, default"
                "border, 1, 5.39, easeOutQuint"
                "windows, 1, 4.79, easeOutQuint"
                "windowsIn, 1, 4.1, easeOutQuint, popin 87%"
                "windowsOut, 1, 1.49, linear, popin 87%"
                "fadeIn, 1, 1.73, almostLinear"
                "fadeOut, 1, 1.46, almostLinear"
                "fade, 1, 3.03, quick"
                "layers, 1, 3.81, easeOutQuint"
                "layersIn, 1, 4, easeOutQuint, fade"
                "layersOut, 1, 1.5, linear, fade"
                "fadeLayersIn, 1, 1.79, almostLinear"
                "fadeLayersOut, 1, 1.39, almostLinear"
                "workspaces, 1, 1.94, almostLinear, fade"
                "workspacesIn, 1, 1.21, almostLinear, fade"
                "workspacesOut, 1, 1.94, almostLinear, fade"
              ];
            };

            cursor = {
              enable_hyprcursor = true;
            };

            dwindle = {
              pseudotile = true;
              preserve_split = true;
              smart_split = false;
              smart_resizing = false;
            };

            misc = {
              disable_hyprland_logo = true;
              disable_splash_rendering = true;
              enable_swallow = true;
              swallow_regex = "^(kitty)$";
            };

            bind = [
              # General
              "$mod, return, exec, $terminal"
              "$mod SHIFT, q, killactive"
              "$mod SHIFT, e, exit"
              "$mod SHIFT, d, exec, /home/fw/scripts/dmenu_sys"
              "$mod SHIFT, x, exec, ${pkgs.hyprlock}/bin/hyprlock"
              "$mod SHIFT, w, exec, /home/fw/scripts/watch"

              # Screen focus
              "$mod, v, togglefloating"
              "$mod, u, focusurgentorlast"
              "$mod, tab, focuscurrentorlast"
              "$mod, f, fullscreen"

              # Screen resize
              "$mod CTRL, h, resizeactive, -20 0"
              "$mod CTRL, l, resizeactive, 20 0"
              "$mod CTRL, k, resizeactive, 0 -20"
              "$mod CTRL, j, resizeactive, 0 20"

              # Workspaces
              "$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"

              # Move to workspaces
              "$mod SHIFT, 1, movetoworkspace,1"
              "$mod SHIFT, 2, movetoworkspace,2"
              "$mod SHIFT, 3, movetoworkspace,3"
              "$mod SHIFT, 4, movetoworkspace,4"
              "$mod SHIFT, 5, movetoworkspace,5"
              "$mod SHIFT, 6, movetoworkspace,6"
              "$mod SHIFT, 7, movetoworkspace,7"
              "$mod SHIFT, 8, movetoworkspace,8"
              "$mod SHIFT, 9, movetoworkspace,9"
              "$mod SHIFT, 0, movetoworkspace,10"

              # Navigation
              "$mod, h, movefocus, l"
              "$mod, l, movefocus, r"
              "$mod, k, movefocus, u"
              "$mod, j, movefocus, d"

              # Applications
              "$mod, q, exec, ${pkgs.librewolf}/bin/librewolf"
              "$mod, d, exec, ${pkgs.rofi}/bin/rofi -show drun -p 'Run: '"

              # Screencapture
              "$mod SHIFT, s, exec, ${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" - | ${pkgs.wl-clipboard}/bin/wl-copy -t image/png"
              "$mod SHIFT, c, exec, ${pkgs.grim}/bin/grim -g \"$(${pkgs.slurp}/bin/slurp)\" \"$HOME/$(date +screenshot-%Y%m%d-%H%M%S.png)\""

              # special
              "SUPER+SHIFT, code:201, exec, confetti"
            ];

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

            windowrulev2 = [
              "float, class:^(org.pulseaudio.pavucontrol)$"
              "size 500 400, class:^(org.pulseaudio.pavucontrol)"
              "move onscreen cursor -250 10, class:^(org.pulseaudio.pavucontrol)"
              "float, title:^(Bluetooth Devices)$"
              "size 500 400, title:^(Bluetooth Devices)"
              "move onscreen cursor -250 10, title:^(Bluetooth Devices)"

              "float, class:^(.playerctl-gtk-wrapped)$"
              "size 300 50, class:^(.playerctl-gtk-wrapped)"
              "move onscreen cursor -150 30, class:^(.playerctl-gtk-wrapped)"
            ];

            env = [
              "NIXOS_OZONE_WL,1"
              "_JAVA_AWT_WM_NONREPARENTING,1"
              "QT_WAYLAND_DISABLE_WINDOWDECORATION,1"
              "QT_QPA_PLATFORM,wayland"
              "SDL_VIDEODRIVER,wayland"
              "GDK_BACKEND,wayland"
              "XDG_SESSION_TYPE,wayland"
              "XDG_SESSION_DESKTOP,Hyprland"
              "XDG_CURRENT_DESKTOP,Hyprland"
            ];
          };
          systemd = {
            enable = true;
          };
        };
      };
  };
}
