{
  pkgs,
  lib,
  config,
  ...
}: let
  program = "hypr";
  cfg = config.dots.${program};
  #sec = sops.secrets;
in {
  options.dots.${program} = {
    enable = lib.mkEnableOption "enables ${program}";
  };

  config = lib.mkIf cfg.enable {
    home.packages = with pkgs; [
      nwg-displays
      posy-cursors
      hyprpicker
    ];

    wayland.windowManager.hyprland = {
      enable = true;
      systemd.enable = true;
      systemd.variables = ["--all"];
      settings = {
        # --- displays ---
        source = [
          "~/.config/hypr/monitors.conf"
          "~/.config/hypr/workspaces.conf"
        ];

        # --- environment variables ---
        env = [
          "MOZ_ENABLE_WAYLAND,1"
          "XDG_CURRENT_DESKTOP,Hyprland"
          "XDG_SESSION_TYPE,wayland"
          "XDG_SESSION_DESKTOP,Hyprland"
        ];

        # --- input ---
        input = {
          kb_layout = "us";
          numlock_by_default = true;
          follow_mouse = 2;
          sensitivity = -0.2;

          touchpad = {
            disable_while_typing = true;
            natural_scroll = true;
            clickfinger_behavior = true;
            tap-to-click = true;
          };
        };

        # --- general ---
        general = {
          gaps_in = 2;
          gaps_out = 5;
          border_size = 3;
          "col.active_border" = lib.mkDefault "rgba(33ccffee) rgba(00ff99ee) 45deg";
          "col.inactive_border" = lib.mkDefault "rgba(595959aa)";
          layout = "dwindle";
          allow_tearing = false;
        };

        # --- decoration ---
        decoration = {
          rounding = 3;
          blur = {
            enabled = true;
            size = 3;
            passes = 1;
          };
        };

        # --- animations ---
        animations = {
          enabled = true;
          bezier = "myBezier, 0.05, 0.9, 0.1, 1.05";
          animation = [
            "windows, 1, 7, myBezier"
            "windowsOut, 1, 7, default, popin 80%"
            "border, 1, 10, default"
            "borderangle, 1, 8, default"
            "fade, 1, 7, default"
            "workspaces, 1, 6, default"
          ];
        };

        # --- dwindle ---
        dwindle = {
          pseudotile = true;
          preserve_split = true;
        };

        gestures = {
          workspace = "on";
        };

        misc = {
          force_default_wallpaper = -1;
          disable_hyprland_logo = true;
          disable_splash_rendering = true;
          focus_on_activate = true;
        };

        # --- window rules ---
        windowrulev2 = [
        ];

        # --- binds ---
        "$mainMod" = "SUPER";

        bind = [
          # system
          "$mainMod CONTROL, Q, exec, loginctl lock-session"

          # programs
          "$mainMod, Return, exec, kitty"
          "$mainMod, E, exec, kitty lf"
          "$mainMod, R, exec, tofi-drun --drun-launch=true --prompt-text=\"launch: \""
          "$mainMod, B, exec, librewolf"
          "$mainMod, G, exec, lutris"
          "$mainMod, M, exec, thunderbird"
          "$mainMod, D, exec, flatpak run com.discordapp.Discord"
          "$mainMod, K, exec, hyprpicker --autocopy --format=hex"
          "$mainMod, T, exec, cliphist list | tofi | cliphist decode | wl-copy"
          "$mainMod CONTROL, T, exec, cliphist wipe"

          # screenshots
          "$mainMod SHIFT, C, exec, hyprshot --mode region --output-folder ~/pictures/screenshots"

          # multimedia
          ", XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"
          ", XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
          ", XF86AudioRaiseVolume, exec, wpctl set-volume -l 1.5 @DEFAULT_AUDIO_SINK@ 5%+"
          ", XF86AudioPlay, exec, playerctl play-pause"

          # brightness
          ", XF86MonBrightnessUp, exec, brightnessctl set +10%"
          ", XF86MonBrightnessDown, exec, brightnessctl set 10%- --min-value"

          # scratchpad
          "$mainMod, S, togglespecialworkspace, magic"
          "$mainMod SHIFT, S, movetoworkspace, special:magic"

          # window management
          "$mainMod, Q, killactive"
          "$mainMod SHIFT, M, exit"
          "$mainMod, V, togglefloating"
          "$mainMod, F, fullscreen, 1"
          "$mainMod SHIFT, F, fullscreen, 0"
          "$mainMod, P, pseudo"
          "$mainMod, J, togglesplit"

          # focus movement
          "$mainMod, tab, cyclenext"
          "$mainMod, left, movefocus, l"
          "$mainMod, right, movefocus, r"
          "$mainMod, up, movefocus, u"
          "$mainMod, down, movefocus, d"

          # move windows
          "$mainMod SHIFT, left, swapwindow, l"
          "$mainMod SHIFT, right, swapwindow, r"
          "$mainMod SHIFT, up, swapwindow, u"
          "$mainMod SHIFT, down, swapwindow, d"

          # resize
          "$mainMod CTRL, left, resizeactive, -60 0"
          "$mainMod CTRL, right, resizeactive, 60 0"
          "$mainMod CTRL, up, resizeactive, 0 -60"
          "$mainMod CTRL, down, resizeactive, 0 60"

          # workspace switching
          "$mainMod, mouse_down, workspace, e+1"
          "$mainMod, mouse_up, workspace, e-1"
          "$mainMod, 1, workspace, 1"
          "$mainMod, 2, workspace, 2"
          "$mainMod, 3, workspace, 3"
          "$mainMod, 4, workspace, 4"
          "$mainMod, 5, workspace, 5"
          "$mainMod, 6, workspace, 6"
          "$mainMod, 7, workspace, 7"
          "$mainMod, 8, workspace, 8"
          "$mainMod, 9, workspace, 9"
          "$mainMod, 0, workspace, 10"

          # move windows between workspaces
          "$mainMod SHIFT, 1, movetoworkspace, 1"
          "$mainMod SHIFT, 2, movetoworkspace, 2"
          "$mainMod SHIFT, 3, movetoworkspace, 3"
          "$mainMod SHIFT, 4, movetoworkspace, 4"
          "$mainMod SHIFT, 5, movetoworkspace, 5"
          "$mainMod SHIFT, 6, movetoworkspace, 6"
          "$mainMod SHIFT, 7, movetoworkspace, 7"
          "$mainMod SHIFT, 8, movetoworkspace, 8"
          "$mainMod SHIFT, 9, movetoworkspace, 9"
          "$mainMod SHIFT, 0, movetoworkspace, 10"

          # waybar
          "$mainMod, N, exec, pkill -SIGUSR1 waybar"
          "$mainMod SHIFT, N, exec, pkill -SIGUSR2 waybar"
        ];

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

    # enable polkit agent
    services.hyprpolkitagent.enable = true;

    # wallpaper
    services.hyprpaper = {
      enable = true;
      settings = {
        preload = lib.mkDefault ["~/.nix/users/blake/assets/wallpapers/antartica.png"];
        wallpaper = lib.mkDefault [",~/.nix/users/blake/assets/wallpapers/antartica.png"];
        ipc = "off";
        splash = false;
      };
    };

    # screenlocker
    programs.hyprlock = {
      enable = true;
      settings = {
        general = {
          disable_loading_bar = true;
          hide_cursor = true;
        };

        background = lib.mkDefault [
          {
            monitor = "";
            path = lib.mkDefault "~/.nix/users/blake/assets/wallpapers/antartica.png";
            blur_passes = 1;
            color = lib.mkDefault "rgb(0047ab)";
          }
        ];

        label = [
          {
            monitor = "";
            text = "cmd[update:30000] echo \"$(date +'%R')\"";
            color = "rgb(ffffff)";
            font_size = 90;
            position = "-130, -100";
            halign = "right";
            valign = "top";
            shadow_passes = 1;
          }
          {
            monitor = "";
            text = "cmd[update:43200000] echo \"$(date +'%Y/%m/%d')\"";
            color = "$text";
            font_size = 25;
            position = "-130, -250";
            halign = "right";
            valign = "top";
            shadow_passes = 2;
          }
          {
            monitor = "";
            text = "$LAYOUT";
            color = "rgb(ffffff)";
            font_size = 20;
            rotate = 0;
            position = "-130, -310";
            halign = "right";
            valign = "top";
            shadow_passes = 2;
          }
        ];

        image = [
          {
            monitor = "";
            path = "~/.nix/users/blake/assets/pfps/pikacig.jpg";
            size = 350;
            border_color = lib.mkDefault "rgb(0047ab)";
            rounding = -1;
            position = "0, 85";
            halign = "center";
            valign = "center";
            shadow_passes = 2;
          }
        ];

        input-field = lib.mkForce [
          {
            monitor = "";
            size = "400, 70";
            outline_thickness = 4;
            dots_size = 0.2;
            dots_spacing = 0.2;
            dots_center = true;
            outer_color = lib.mkDefault "$accent";
            inner_color = lib.mkDefault "$surface0";
            font_color = lib.mkDefault "$text";
            fade_on_empty = true;
            placeholder_text = "# <span foreground=\"##$textAlpha\"><i>󰌾 Logged in as </i><span foreground=\"##$accentAlpha\">$USER</span></span>";
            hide_input = false;
            check_color = lib.mkDefault "rgb(0047ab)";
            fail_color = lib.mkDefault "rgb(ff0000)";
            fail_text = "<i>$FAIL <b>($ATTEMPTS)</b></i>";
            capslock_color = lib.mkDefault "rgb(ff0000)";
            position = lib.mkForce "0, -185";
            halign = "center";
            valign = "center";
            shadow_passes = 2;
          }
        ];
      };
    };

    # idle daemon
    services.hypridle = {
      enable = true;
      settings = {
        # --- general settings ---
        general = {
          lock_cmd = "pidof hyprlock || hyprlock"; # avoid multiple instances
          before_sleep_cmd = "loginctl lock-session"; # lock before suspend
          after_sleep_cmd = "hyprctl dispatch dpms on"; # wake display properly
        };

        # --- dim screen ---
        listener = [
          {
            timeout = 150; # 2.5 min
            on-timeout = "brightnessctl -s set 1"; # dim monitor (avoid 0 on OLED)
            on-resume = "brightnessctl -r"; # restore brightness
          }

          # --- blank screen ---
          {
            timeout = 330; # 5.5 min
            on-timeout = "hyprctl dispatch dpms off"; # turn off screen
            on-resume = "hyprctl dispatch dpms on"; # restore screen
          }

          # --- lock screen ---
          {
            timeout = 900; # 15 min
            on-timeout = "loginctl lock-session"; # lock screen
          }

          # --- suspend timeout ---
          {
            timeout = 1800; # 30 min
            on-timeout = "systemctl suspend"; # suspend computer
          }

          # --- keyboard backlight (optional) ---
          # Uncomment if your keyboard supports it
          # {
          #   timeout = 150;
          #   on-timeout = "brightnessctl -sd rgb:kbd_backlight set 0";
          #   on-resume = "brightnessctl -rd rgb:kbd_backlight";
          # }
        ];
      };
    };

    #    home.pointerCursor = {
    #      dotIcons.enable = false;
    #      enable = true;
    #      gtk.enable = true;
    #      x11.enable = true;
    #      package = pkgs.posy-cursors;
    #      name = "Posy_Cursor_Black";
    #      size = 48;
    #      hyprcursor = {
    #        enable = true;
    #        size = 64;
    #      };
    #    };

    #xdg.configFile."hypr/hyprland.conf" = {
    #  source = config.lib.file.mkOutOfStoreSymlink "/home/blake/.nix/users/blake/dots/hypr/hyprland.conf";
    #};
  };
}
