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

with lib;
let
  cfg = config.modules.software.system.fish;
  nix-colors-lib = inputs.nix-colors.lib.contrib { inherit pkgs; };
in {
  options.modules.software.system.fish = {
    enable = mkEnableOption "Enable fish, the friendly interpreted shell";
  };

  config = mkIf cfg.enable {
    # runtime dependencies of plugins
    user.packages = with pkgs; [ 
      # fzf-fish
      bat fd fzf 
      # grc
      grc 
      # tide
      fishPlugins.tide 
      # done
      libnotify
    ];

    users.defaultUserShell = pkgs.fish;
    programs.fish.enable = true;
    hm.programs.fish = let
      colorScript = nix-colors-lib.shellThemeFromScheme { scheme = config.colorScheme; };
    in {
      enable = true;
      plugins = with pkgs.fishPlugins; [ 
        { name = "fzf-fish"; src = fzf-fish.src; } 
        { name = "grc"; src = grc.src; } 
        { name = "tide"; src = tide.src; } 
        { name = "done"; src = done.src; }

        { name = "autopair"; src = autopair.src; }
      ];
      interactiveShellInit = ''
        sh ${colorScript}
      '';
      functions.fish_greeting = ''
        ${lib.getExe pkgs.fastfetch} --logo-type small --key-width 11 -s title:separator:os:host:kernel:uptime:memory:swap:colors --colors-symbol circle --colors-padding-left 11
      '';
    };
  };
}
