{ lib, config, pkgs, ... }:
with lib;
let
  cfg = config.modules.cli.vifm;
in
{
  options.modules.cli.vifm = {
    enable = mkEnableOption "enable Vifm file browser";
  };
  config = mkIf cfg.enable {
    home.packages = with pkgs; [
      vifm
      chafa         # Preview images
      poppler_utils # Preview PDF file
    ];
    programs.zsh = {
      initExtra = ''
        cdv() {
          cd "$(vifm --choose-dir - "$@")"
        }
        openv() { 
          xdg-open "$(vifm --choose-file - "$@")"
        }

      '';
      shellAliases = {
        vifm = "TERM=tmux-256color vifm";
      };
    };
    home.file.".config/vifm/vifmrc".source = ./files/vifmrc;
    home.file.".config/vifm/colors/base16-default-dark.vifm".source = ./files/base16-default-dark.vifm;
    home.file.".config/vifm/devicons.vifm".source = ./files/devicons.vifm;
  };
}
