{inputs, pkgs, lib, config, ...}:
let
  cfg = config.nix-config.hypr;
in
{
  options = {
    nix-config.hypr.internal-screen.resolution = lib.mkOption { type = lib.types.str; };
    nix-config.hypr.internal-screen.scale = lib.mkOption { type = lib.types.str; };
    nix-config.hypr.browser = lib.mkOption {
      type = lib.types.str;
      default = "firefox";
      description = "The browser to use in Hyprland.";
    };
    nix-config.hypr.ide = lib.mkOption {
      type = lib.types.str;
      default = "code";
      description = "The IDE to use in Hyprland.";
    };
  };

  config = {

    wayland.windowManager.hyprland = lib.mkIf cfg.enable {
      enable = true;
      systemd.enable = true;
      settings = {
        # debug = {
        #   disable_logs = false;
        # };
        general = {
          resize_on_border = true;
          gaps_in = 3;
          gaps_out = 3;
          border_size = 1;
          "col.active_border" = "rgb(98971A) rgb(CC241D) 45deg";
          "col.inactive_border" = "rgba(595959aa)";
          layout = "master";
        };

      input = {
        kb_layout = "de";
        # remap caps lock to ctrl
        kb_options = "ctrl:nocaps";
        numlock_by_default = true;
        # mouse input should be unchanged
        natural_scroll = false;
        sensitivity = 0.3;
        touchpad = {
          disable_while_typing = false;
          natural_scroll = true;
        };
      };

      device = {
        name = "syna329a:00-06cb:cd4f-touchpad";
        sensitivity = 0.5;
      };

      gestures = {
        workspace_swipe = true;
        workspace_swipe_fingers = 4;
        workspace_swipe_touch = true;
      };

      decoration = {
        rounding = 10;
        inactive_opacity = 0.9;
        dim_inactive = false;
        dim_strength = 0.1;

        shadow = {
          enabled = false;
        };

        # blur = {
        #   enabled = true;
        #   size = 5;
        #   passes = 2;
        # };

        # blur is set on a per-program basis
        windowrulev2 = [
          # kitty should behave like a floating window
          "animation popin, class:kitty"
          "move cursor -50% -50%, class:kitty"
          "float, class:kitty"
          "size 50% 50%, class:kitty"

          # blur the launcher background
          # "blur 10, class:${config.nix-config.launcher.name}"

          # some more floating windows
          "float, class:org.gnome.Settings"
          "float, class:desktopclient.owncloud.com"
          "float, class:org.keepassxc.KeePassXC"
          "float, title:^(Picture-in-Picture)$"
          "float, class:org.gnome.Nautilus"
          # when there is a single window, deactivate border and gaps
          # "border_size 0, onworkspace:w[tv1], "

          # File pickers and dialogs
          "float, title:^(Save As)$"
          "float, title:^(Open File)$"
          "size 50% 50%, title:^(Open File)$"
          "center, title:^(Open File)$"

          # Disable idle when gaming
          "idleinhibit always, class:^(steam_app_)"
          "idleinhibit always, class:^(gamescope)$"
        ];
      };

      monitor = [
        # the internal monitor, always at the "center"
        "eDP-1, ${cfg.internal-screen.resolution}, 0x0, ${cfg.internal-screen.scale}"

        # ultra wide monitor at home
        "desc:Samsung Electric Company C34H89x H4ZN501178, 3440x1440@99.98, auto-up, 1"

        # Samsung monitors at irchel (matching the description)
        "desc:Samsung Electric Company LS27D80xU, 2560x1440@59.95, auto-up, 1"

        ", preferred, auto-up, auto" # automatically add any newly detected monitor
      ];

      xwayland = {
        enabled = true;
        force_zero_scaling = true;
      };

      env = [
        # force apps to use wayland
        "NIXOS_OZONE_WL, 1"
        "ELECTRON_OZONE_PLATFORM_HINT, wayland"
        # set the scale factor for GDK apps
        "GDK_SCALE, ${cfg.internal-screen.scale}"
        # set the scale factor for QT apps
        # "QT_SCALE_FACTOR, ${cfg.internal-screen.scale}"
        "QT_SCALE_FACTOR, 1.1"
        # set the scale factor for GTK apps
      ];
    };

      plugins = [
        # Global overview
        pkgs.hyprlandPlugins.hyprspace
        # Touch gestures
        # pkgs.hyprlandPlugins.hyprgrass
      ];
    };
  };
}
