{ lib, config, ... }:
with lib;
let
  cfg = config.modules.application.foot;
in
{
  options.modules.application.foot = {
    enable = mkEnableOption "enable Foot terminal emulator";

    scrollback-lines = mkOption {
      type = types.int;
      default = 2500;
      description = "numbers of scrollback lines in history";
    };
    font-family = mkOption {
      type = types.str;
      default = "Fira Code Nerd Font";
      description = "font family used in Foot";
    };

    font-size = mkOption {
      type = types.str;
      default = "10";
      description = "font size used in Foot";
    };
  };

  config = mkIf cfg.enable {
    programs.foot = {
      enable = true;
      settings = {
        main = {
          font = "${cfg.font-family}:size=${cfg.font-size}";
          pad = "5x5 center";
        };
        mouse = {
          hide-when-typing = "yes";
        };
        colors = {
          background = "181818";
          foreground = "d8d8d8";
          regular0 = "181818";
          regular1 = "ab4642";
          regular2 = "a1b56c";
          regular3 = "f7ca88";
          regular4 = "7cafc2";
          regular5 = "ba8baf";
          regular6 = "86c1b9";
          regular7 = "d8d8d8";
          bright0 = "585858";
          bright1 = "dc9656";
          bright2 = "282828";
          bright3 = "383838";
          bright4 = "b8b8b8";
          bright5 = "e8e8e8";
          bright6 = "a16946";
          bright7 = "f8f8f8";
          "16" = "dc9656";
          "17" = "a16946";
          "18" = "282828";
          "19" = "383838";
          "20" = "b8b8b8";
          "21" = "e8e8e8";
          selection-background = "d8d8d8";
          selection-foreground = "181818";
          urls = "b8b8b8";
          jump-labels = "181818 f7ca88";
          scrollback-indicator= "181818 b8b8b8";
        };
        scrollback = {
          lines = cfg.scrollback-lines;
          indicator-format = "percentage";
        };
        csd = {
          preferred = "none";
        };
      };
    };
    # As foot terminal definition is not present on server I manage, this workaround is quite useful.
    home.shellAliases = {
      ssh = "TERM=xterm-256color ssh";
    };
  };
}
