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

with lib;
{
  options.terminal = {
    nixUpdateLocation = mkOption {
      type = types.str;
    };
    flakeUpdateLocation = mkOption {
      type = types.str;
    };
  };

  config = {
    home.packages = with pkgs;[
      blesh
      (nerdfonts.override { fonts = [ "SpaceMono" ]; })
      git-credential-manager
    ];

    home.file = {
      # # Building this configuration will create a copy of 'dotfiles/screenrc' in
      # # the Nix store. Activating the configuration will then make '~/.screenrc' a
      # # symlink to the Nix store copy.
      # ".screenrc".source = dotfiles/screenrc;

      # # You can also set the file content immediately.
      # ".gradle/gradle.properties".text = ''
      #   org.gradle.console=verbose
      #   org.gradle.daemon.idletimeout=3600000
      # '';

      ".gitconfig".source = ./dotfiles/gitconfig;
    };

    programs = {
      bash = {
        enable = true;
        bashrcExtra = ''
          source $(blesh-share)/ble.sh
          bleopt canvas_winch_action=redraw-prev
        '';
      };

      starship.enable = true;

      atuin.enable = true;

      zellij = {
        enable = true;
        enableBashIntegration = true;
        settings = {
          theme = "dracula";
        };
      };

      direnv = {
        enable = true;
        enableBashIntegration = true;
        nix-direnv.enable = true;
      };

      git = {
        enable = true;
        delta.enable = true;
      };

      gitui = {
        enable = true;
      };

      helix = {
        enable = true;
        defaultEditor = true;
        settings = {
          theme = "dracula";
        };
      };

      bat = {
        enable = true;
      };

      eza = {
        enable = true;
        enableBashIntegration = true;
        git = true;
        extraOptions = [
          "--color=auto"
          "--icons=always"
          "--group-directories-first"
          "--header"
        ];
      };

      yazi = {
        enable = true;
        settings = {
          manager = {
            sort_by = "natural";
            show_hidden = true;
          };
        };
      };

      bottom = {
        enable = true;
      };

      fd = {
        enable = true;
      };

      ripgrep = {
        enable = true;
      };

      topgrade = {
        enable = true;
        settings = {
          misc = {
            assume_yes = true;
          };
          linux = {
            nix_arguments = "--flake ${config.terminal.nixUpdateLocation}";
          };
          pre_commands = {
            nix-flake-update = "sudo nix flake update --flake ${config.terminal.flakeUpdateLocation}";
          };
        };
      };

      alacritty = {
        enable = true;
        settings = {
          font = {
            normal = {
              family = "SpaceMono Nerd Font";
              style = "Regular";
            };
            size = 14;
          };
        };
      };

      # eh not feeling it
      # ghostty = {
      #   enable = true;
      #   enableBashIntegration = true;
      #   settings = {
      #     "font-family" = "SpaceMono Nerd Font";
      #     "font-size" = 14;
      #     theme = "Dracula";
      #   };
      # };

      yt-dlp = {
        enable = true;
      };
    };
  };
}
