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

let
  scripts = ../../scripts;
  extra = ../../extra;
  terminal = pkgs.alacritty;
in {
  imports = [
    ../../snippets/gammastep.nix
    ../../snippets/kdeconnect.nix
    ../../snippets/ssh.nix
    ../../snippets/zsh.nix
    ../../snippets/taskwarrior.nix
    ../../snippets/kakoune.nix
    ../../snippets/clifm.nix
    ../../snippets/git.nix
    ../../snippets/firefox.nix
    ../../snippets/thunderbird.nix
  ];
  home.username = "alice";
  home.homeDirectory = "/home/alice";

  home.stateVersion = "24.05";

  # Configure cursor
  home.pointerCursor = {
    package = pkgs.vanilla-dmz;
    name = "Vanilla-DMZ";
    size = 64;
  };

  # Configure icon theme
  gtk = {
    enable = true;
    iconTheme = {
      name = "Papirus";
      package = pkgs.papirus-icon-theme;
    };
  };

  # Configure xdg-desktop-portal (for file picker, etc.)
  # xdg.portal = {
  #     enable = true;
  # };

  # Install packages
  home.packages = with pkgs;
    let
      mons = callPackage ../../pkgs/mons/mons.nix { };
      archivo = callPackage ../../pkgs/archivo/archivo.nix { };
      highway-gothic = callPackage ../../pkgs/highway-gothic/highway-gothic.nix { };
      olympus = callPackage ../../pkgs/olympus/package.nix { };
    in [ gcc tree-sitter ] ++ # Basic dev tools
    [ marksman nil ] ++ # Language servers except those installed through package sections
    [ texliveFull texlab ] ++ # LaTeX
    # (with ocamlPackages; [
    #   ocaml
    #   opam
    #   dune_3
    #   dune-release
    #   merlin
    #   ocaml-lsp
    #   odoc
    #   ocamlformat
    #   utop
    # ]) ++ # OCaml
    # [ rustup ] ++ # Rust
    # [ go gopls ] ++ # Golang
    # (with elmPackages; [ elm elm-language-server elm-format elm-test ]) ++
    [ python3 ] ++ # I guess.....
    [
      kak-lsp
      brightnessctl
      jq
      blueman
      upower
      glib # provides trash and mount (latter may supplant udisks2?)
    ] ++ # Basic utilities
    [ bitwarden-cli htop snore hledger hledger-ui ]
    ++ # Personalized selection of command-line (CLI/TUI) apps
    [ terminal ] ++ # Terminal emulator
    [
      imv
      vlc
      pavucontrol
    ] ++ # Basic graphical apps
    [
      libreoffice
      signal-desktop
      element-desktop
      prismlauncher
      mumble
      gimp
      inkscape
      deluge-gtk
      shotwell
      lorien
      keepassxc
      zulip
      filezilla
      bitwarden
      activate-linux
    ] ++ # Personalized selection of graphical apps
    [ olympus shticker-book-unwritten ] ++ # Games
    [ bemenu j4-dmenu-desktop xclip xdotool ] ++ # i3 and x11 related packages
    [
      noto-fonts
      redhat-official-fonts
      overpass
      ibm-plex
      rubik
      archivo
      highway-gothic
      font-awesome
    ] ++ # Fonts
    [ temurin-jre-bin-17 ] ++ # Temp
    [ ];

  programs.home-manager.enable = true;


  # programs.swaylock = {
  #   enable = true;
  #   settings = { font-size = 14; };
  # };
  # services.swayidle = {
  #   enable = true;
  #   events = [{
  #     event = "before-sleep";
  #     command = "${pkgs.lib.getExe pkgs.swaylock} -f";
  #   }];
  # };

  xsession = let
    term = terminal;
    dmenuCommand = builtins.readFile "${scripts}/dmenu.sh";
    shutdownMenu = pkgs.writeShellScript "shutdownmenu"
      (builtins.readFile "${scripts}/shutdownmenu.sh");
  in {
    enable = true;
    windowManager.i3 = {
      enable = true;
      package = pkgs.i3-gaps;
      config = rec {
        terminal = "${pkgs.lib.getExe term}";
        modifier = "Mod4";
        fonts = {
            names = [ "Red Hat Display" ];
            style = "Regular";
            size = 12.0;
        };
        # input = {
        #   "type:keyboard" = {
        #     xkb_layout = "ca,ca";
        #     xkb_variant = ",eng";
        #   };
        # };
        # leaving bars out for now
        # bars = ...
        window = {
          border = 2;
          titlebar = true;
        };
        menu = "j4-dmenu-desktop --no-generic --term=${pkgs.lib.getExe term} --dmenu='${dmenuCommand}'";
        focus.followMouse = false;
        # keybindings and extraConfig go here
        keybindings = lib.mkOptionDefault rec {
          XF86PowerOff =
            "exec DMENU_COMMAND='${dmenuCommand}' bash ${shutdownMenu}";
          "${modifier}+Pause" = XF86PowerOff;        };
      };
    };
  };

  # configure fonts correctly
  fonts.fontconfig.enable = true;
  xdg.configFile."fontconfig/conf.d/5-default.fonts.conf".source =
    "${extra}/20-default-fonts.conf";

  # terminal emulator
  programs.alacritty.enable = true;

  # programs.neovim = import ./snippets/neovim.nix;

  programs.zathura = {
    enable = true;
  };

  programs.pandoc = { enable = true; };

  # Configure notifications
  services.dunst = {
    enable = true;
    settings = {
      global = {
        font = "Red Hat Display 12";
        mouse_left_click = "do_action, close_current";
        mouse_middle_click = "close_all";
        mouse_right_click = "close_current";
      };
    };
  };

}
