{
  # Snowfall Lib provides a customized `lib` instance with access to your flake's library
  # as well as the libraries available from your flake's inputs.
  lib,
  # An instance of `pkgs` with your overlays and packages applied is also available.
  pkgs,
  # You also have access to your flake's inputs.
  inputs,

  # Additional metadata is provided by Snowfall Lib.
  system, # The system architecture for this host (eg. `x86_64-linux`).
  target, # The Snowfall Lib target for this system (eg. `x86_64-iso`).
  format, # A normalized name for the system target (eg. `iso`).
  virtual, # A boolean to determine whether this system is a virtual target using nixos-generators.
  systems, # An attribute map of your defined hosts.

  # All other arguments come from the module system.
  config,
  ...
}:

let
  cfg = config.modules.yazi;
in
{
  options.modules.yazi = {
    enable = lib.mkOption { default = false; };
  };

  config = lib.mkIf cfg.enable {
    programs.zoxide.enable = true;
    programs.zoxide.enableFishIntegration = true;

    home.packages = with pkgs; [
      exiftool
      unar # extract archives
      xdragon # dragndrop
      poppler_utils # pdf preview
      fd
      ripgrep
      fzf
      jq # json preview
      ffmpegthumbnailer
      xclip
    ];

    home.shellAliases = {
      y = "ya"; # Yazi shell wrapper (cd on quit)
    };

    programs.yazi.enable = true;
    programs.yazi.enableFishIntegration = true;
    programs.yazi.settings.manager = {
      sort_by = "modified";
      sort_reverse = true;
      show_hidden = true;
    };

    programs.yazi.keymap = {
      manager.prepend_keymap = [
        # Override defaults
        {
          on = [ "e" ];
          run = ''shell --orphan --confirm "pcmanfm &"'';
          desc = "Open gui file manager";
        }
        {
          on = [ "<C-o>" ];
          run = ''shell "$SHELL" --block --confirm'';
          desc = "Open shell here";
        }
        {
          on = [ "<C-n>" ];
          run = ''shell 'dragon -x -i -T "$1"' --confirm'';
          desc = "Dragndrop via dragon";
        }
        {
          on = [ "<Enter>" ];
          run = "plugin --sync smart-enter";
          desc = "Enter the child directory, or open the file";
        }
      ];
      input.prepend_keymap = [
        {
          on = [ "<Esc>" ];
          run = "close";
          desc = "Cancel input";
        }
      ];
    };

    programs.yazi.settings.opener = {
      play = [
        {
          run = ''vlc "$1"'';
          orphan = true;
        }
      ];
    };

    xdg.configFile."yazi/flavors" = {
      source = "${inputs.yazi-flavors}";
    };
    xdg.configFile."yazi/plugins/smart-enter.yazi/init.lua".text = ''
      return {
        entry = function()
          local h = cx.active.current.hovered
          ya.manager_emit(h and h.cha.is_dir and "enter" or "open", { hovered = true })
        end,
      }
    '';
    programs.yazi.theme = {
      flavor.use = "catppuccin-mocha";
    };
  };
}