{ config, lib, pkgs, ... }:
{
  imports = [
    ../shared/hyprland.nix
    ./subs/waybar.nix
  ];

  config = lib.mkIf config.shared.hyprland.enable {

    wayland.windowManager.hyprland = {
      enable = true;

      package = null;

      settings = {
        "$mod" = "SUPER";
        "$clipboard" = "rofi -modi Clipboard:~/.config/rofi/scripts/cliphist-rofi -show Clipboard -theme ~/.config/rofi/menu.rasi";
        "$browser" = "zen-beta";
        "$fileManager" = "thunar";
        "$terminal" = "foot";
        "$LAPTOP_KB_ENABLED" = true;
        "$TOUCHPAD_ENABLED" = true;

        monitor = [",preferred,auto,auto"];

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

        general = {
            gaps_in = 0;
            gaps_out = 0;
            border_size = 1;
            resize_on_border = false;
            allow_tearing = false;
            layout = "master";
        };

        exec-once = [
          "waybar -c ~/.config/waybar/topbar.jsonc -s ~/.config/waybar/topbar.css"
          "wl-paste --watch cliphist store"
          "hyprswitch init --show-title &"
          "hyprpaper"
        ];

        exec-shutdown = "cliphist wipe";

        decoration = {
          rounding = 0;
          rounding_power = 0;
          dim_inactive = false;
          active_opacity = "1.0";
          inactive_opacity = "1.0";
          shadow = {
              enabled = false;
          };
          blur = {
              enabled = false;
          };
        };

        animations = {
          enabled = false;
        };

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

        master = {
            new_status = "master";
        };

        input = {
            kb_layout = "us";
            kb_options = "caps:escape";
            follow_mouse = 1;
            sensitivity = 0;
            touchpad = {
                natural_scroll = true;
            };
        };

        gestures = {
            workspace_swipe = true;
        };

        device = [
          {
            name = "at-translated-set-2-keyboard";
            enabled = "$LAPTOP_KB_ENABLED";
          }
          {
              name = "elan1301:00-04f3:30c6-touchpad";
              enabled = "$TOUCHPAD_ENABLED";
          }
        ];

        group = {
          "col.border_active" = "rgba(172729FF)";
          "col.border_inactive" = "rgba(111111FF)";

          groupbar = {
            enabled = true;
            font_family = "SF Pro Display";
            font_size = 10;
            indicator_height = 15;
            render_titles = false;
            rounding = 0;
            round_only_edges = false;
            gradients = false;
            "col.active" = "rgba(172729FF)";
            "col.inactive" = "rgba(111111FF)";
            gaps_in = 0;
            gaps_out = 0;
            keep_upper_gap = false;
          };
        };

        unbind = [ "$mod, W" ];

        bind = [
          "$mod, Q, exec, ~/.local/bin/hypr-custom-kill"
          "$mod, X, exec, hyprlock"
          "$mod Shift, Space, togglefloating,"
          "$mod, Return, exec, $terminal"
          "$mod, C, exec, speedcrunch"
          "$mod, B, exec, $browser"
          "$mod, F, exec, $fileManager"
          "$mod, T, exec, flatpak run eu.betterbird.Betterbird"
          "$mod, M, exec, emacsclient -ca ''"
          "$mod Shift, P, exec, hyprshot -z -m region -o ~/Pictures"
          "$mod Shift, W, exec, hyprshot -z -m window -o ~/Pictures/"
          ", PRINT,  exec, hyprshot -z -m output -o ~/Pictures"
          "$mod Ctrl, C, exec, hyprpicker --autocopy --format=hex"
          "$mod Ctrl, W, exec, killall hyprpaper && hyprpaper"
          "$mod Ctrl, 1, exec, ~/.local/bin/books"
          "$mod Shift, D, exec, ~/.local/bin/define"
          "Alt, Space, exec, ~/.config/rofi/scripts/launcher.sh"
          "Ctrl Alt, N, exec, ~/.config/rofi/scripts/powermenu.sh"
          "$mod Ctrl Shift, 7, exec, ~/.local/bin/wl-toggle-keyboard && ~/.local/bin/wl-toggle-touchpad"
          "$mod Ctrl, B, exec, ~/.config/waybar/scripts/launch.sh"
          "$mod, Z, exec, $clipboard"
          "ALT, Tab, exec, hyprswitch simple -w --switch-type client"
          "ALT Shift, Tab, exec, hyprswitch simple -r -w --switch-type client"
          "$mod, Tab, exec, hyprswitch simple --switch-type workspace"
          "$mod Shift, Tab, exec, hyprswitch simple -r --switch-type workspace"
          "$mod, w, togglegroup"
          "$mod, left,  movefocus, l"
          "$mod, right, movefocus, r"
          "$mod, up,    movefocus, u"
          "$mod, down,  movefocus, d"
          "$mod, H,     movefocus, l"
          "$mod, L,     movefocus, r"
          "$mod, K,     movefocus, u"
          "$mod, J,     movefocus, d"
          "$mod Shift, H, movewindow, l"
          "$mod Shift, L, movewindow, r"
          "$mod Shift, K, movewindow, u"
          "$mod Shift, J, movewindow, d"
          "$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, 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"
          "$mod, mouse_down, workspace, e+1"
          "$mod, mouse_up, workspace, e-1"
        ];

        bindel = [
          "$mod Ctrl, H, resizeactive, -30 0"
          "$mod Ctrl, L, resizeactive, 30 0"
          "$mod Ctrl, K, resizeactive, 0 -30"
          "$mod Ctrl, J, resizeactive, 0 30"
          ",XF86AudioRaiseVolume,  exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 5%+"
          ",XF86AudioLowerVolume,  exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%-"
          ",XF86AudioMute,         exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle"
          ",XF86AudioMicMute,      exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle"
          ",XF86MonBrightnessUp,   exec, brightnessctl s 10%+"
          ",XF86MonBrightnessDown, exec, brightnessctl s 10%-"
        ];

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

        bindl = [
          ", XF86AudioNext,        exec, playerctl next"
          ", XF86AudioPause,       exec, playerctl play-pause"
          ", XF86AudioPlay,        exec, playerctl play-pause"
          ", XF86AudioPrev,        exec, playerctl previous"
        ];

        windowrule = [
          "suppressevent maximize, class:.*"
          "nofocus,class:^$,title:^$,xwayland:1,floating:1,fullscreen:0,pinned:0"
          "workspace 2,class:(zen)"
          "workspace 2,class:(google-chrome)"
          "workspace 3,class:(vesktop)"
          "float,class:(blueman-manager)"
          "float,title:(Dictionary)"
          "float,title:(SpeedCrunch)"
        ];

        workspace = [
          "1,persistent:true"
          "2,persistent:true"
          "3,persistent:true"
          "4,persistent:true"
          "5,persistent:true"
        ];
      };

      systemd.variables = [ "--all" ];
    };

    home.packages = with pkgs; [
      hyprpaper cliphist hyprswitch wl-clipboard wireplumber
      playerctl hyprpicker hyprshot hyprlock evtest nwg-look
      blueman
    ];

    home.file = {
      ".local/bin/hypr-custom-kill".source = ../bin/hypr-custom-kill;
      ".local/bin/wl-toggle-keyboard".source = ../bin/wl-toggle-keyboard;
      ".local/bin/wl-toggle-touchpad".source = ../bin/wl-toggle-touchpad;
      ".config/hypr/hyprlock.conf".source = ../config/hypr/hyprlock.conf;
      ".config/hypr/hyprpaper.conf".source = ../config/hypr/hyprpaper.conf;
      ".config/hypr/hyprswitch.css".source = ../config/hypr/hyprswitch.css;
    };

  };
}
