{ system, username }: { config, pkgs, lib, ... }:

let
  homeDirectory = "/home/${username}";

  util = import ./util pkgs;
in

{
  imports = [
    ./git
    ./shell
    ./term
    ./nvim
    ./modules/niri.nix
    ./modules/swaybg.nix
    (import ./wofi util)
    (import ./im pkgs)
    ./pkgs.nix
  ];

  home.username = username;
  home.homeDirectory = homeDirectory;

  home.stateVersion = "26.05";

  home.sessionPath = [ "$HOME/.local/bin" "$HOME/.zvm/bin" ];

  home.sessionVariables = {
    DISPLAY = ":0";
    NIXOS_OZONE_WL = "1";
    GTK_IM_MODULE = "fcitx";
    QT_IM_MODULE = "fcitx";
  };

  programs.bat.enable = true;
  programs.difftastic.enable = true;
  programs.jujutsu.enable = true;
  programs.neovim = {
    enable = true;
    defaultEditor = true;
    viAlias = true;
    vimAlias = true;
  };

  services.mako.enable = true;
  services.niri = {
    enable = true;
    settings = {
      environment = {
        PATH = "/etc/profiles/per-user/sundo/bin:/run/current-system/sw/bin";
      };

      binds = {
        "Win+Shift+Slash".show-hotkey-overlay = {};
        "Win+W".spawn = [ "nu" "-c" "zsh -c (open $nu.history-path | lines | reverse | str join \"\\n\" | wofi)" ];
        "Win+Q".spawn = [ "nu" "-c" "zsh -c (^echo -e 'foot\\nneovide\\nvivaldi' | wofi)" ];
        "Win+N".spawn = [ "nu" "-c" "zsh -c ('nix run nixpkgs#' + (wofi))" ];
        "Win+Shift+E".quit = {};
        "Win+F".maximize-column = {};
        "Win+Ctrl+F".fullscreen-window = {};
        "Win+Shift+P".power-off-monitors = {};
        XF86AudioRaiseVolume.spawn = [ "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.05+" ];
        XF86AudioLowerVolume.spawn = [ "wpctl" "set-volume" "@DEFAULT_AUDIO_SINK@" "0.05-" ];

        "Win+H".focus-column-left = {};
        "Win+J".focus-workspace-down = {};
        "Win+K".focus-workspace-up = {};
        "Win+L".focus-column-right = {};

        "Win+Shift+L".focus-monitor-right = {};
        "Win+Shift+H".focus-monitor-left = {};
        "Win+Shift+J".move-workspace-to-monitor-left = {};
        "Win+Shift+K".move-workspace-to-monitor-right = {};
      } // builtins.foldl' (acc: e: acc // {
          "Win+${toString e}".focus-workspace = e;
          "Win+Ctrl+${toString e}".move-column-to-workspace = e;
        }) {} (builtins.genList (x: x + 1) 9);

      cursor.hide-when-typing = {};

      input.touchpad.tap = {};

      output."eDP-1" = {
        mode = "2880x1800@60.001";
        background-color = "#000000";
        backdrop-color = "#000000";
      };

      output."HDMI-A-1" = {
        position = {
          x = 2880;
          y = 0;
        };
      };

      layout = {
        background-color = "black";
        always-center-single-column = {};
        center-focused-column = "on-overflow";
        gaps = 0;
      };

      window-rule = [
        { focus-ring.off = {}; }
        {
          match._props.is-active = false;
          exclude._props.app-id = "vivaldi";
          opacity = 0.8;
        }
      ];

      layer-rule = {
        match._props.namespace = "^wallpaper$";
        place-within-backdrop = true;
      };
    };
  };
  services.swaybg = {
    enable = true;
    image = ./img/wallpaper.png;
  };
}