
{ pkgs, lib, system, user, inputs, ... }: 
lib.mkIf (user != "tv")
{
  home.packages = with pkgs; [
    yazi
    dragon
    unar
   ];
  
  programs.yazi = {
    enable = true;
    # package = inputs.yazi.packages.${system}.default;
    enableFishIntegration = true;
    settings = {
      manager = {
        layout = [2 3 4];
        sort_by = "natural";
        sort_sensitive = true;
        sort_reverse = false;
        sort_dir_first = true;
        linemode = "size";
        show_hidden = false;
        show_symlink = true;
        append_keymap = [
          { on = [ "<C-g>" ]; run = "lazygit"; desc = "Run Lazygit in current directory"; }
          { on = [ "<C-D>" ]; run = ''shell 'dragon -x -i -T "$1"' --confirm''; }
        ];
      };
      opener = {
        edit = [
	        { run  = ''hx "$@"''; desc = "helix"; block = true;}
	        { run = ''codium "$@"''; orphan = true;}
	        { run  = ''nano "$@"''; desc = "nano"; block = true;}
        ];
        play = [
          { run = ''mpv "$@"''; }
          { run = ''mediainfo "$1"; echo "Press enter to exit"; read''; block = true; desc = "Show mediainfo";}
        ];
        archive = [
          { run = ''unar "$1"''; desc = "Extract here"; }
        ];
        image = [
          { run = ''imv "$@"''; desc = "imv";}
          { run = ''gimp "$@"''; desc = "gimp";}
          { run = ''swww img --transition-type wipe --transition-angle 60 --transition-step 120 --transition-fps 120 "$@"''; desc = "swww wallpaper";}
        ];
        font = [
          { run = ''fontpreview "$@"''; desc = "fontpreview"; }
        ];
        document = [
          { run = ''zathura "$@"''; desc = "zathura"; }
          { run = ''xournal "$@"''; desc = "xournal"; }
          { run = ''firefox "$@"''; desc = "firefox"; }
        ];
        browser = [
          { run = ''firefox "$@"''; desc = "firefox"; }
        ];
        office = [
          { run = ''libreoffice "$@"''; desc = "libreoffice"; }
          { run = ''libreoffice --view "$@"''; desc = "libreoffice read-only"; }
        ];
        shell = [
          { run = ''sh -c "$@"''; desc = "sh -c"; }
          { run = ''bash -c "$@"''; desc = "bash -c"; }
        ];
        python = [
          { run = ''python "$@"''; desc = "python"; }
        ];
      };
      open.rules = [
        { mime = "text/*"; use = "edit"; }
        { mime = "text/plain"; use = "edit"; }
        { mime = "text/html"; use = ["edit" "browser"]; }
        { mime = "text/htm"; use = ["edit" "browser"]; }
        { mime = "application/x-httpd-php"; use = ["edit" "browser"]; }
        { mime = "application/json"; use = "edit"; }
        { mime = "application/ld+json"; use = "edit"; }
        { mime = "image/*"; use = "image"; }
        { mime = "image/svg"; use = ["image" "edit"]; }
        { mime = "application/pdf"; use = "document"; }
        { mime = "application/epub"; use = "document"; }
        { mime = "video/*"; use = "video"; }
        { mime = "application/vnd.oasis.opendocument.*"; use = "office"; }
        { mime = "application/vnd.ms-powerpoint"; use = "office"; }
        { mime = "application/vnd.ms-excel"; use = "office"; }
        { mime = "application/vnd.openxmlformats-officedocument.*"; use = ["office" "edit"]; }
        { mime = "application/rtf"; use = "office"; }
        { mime = "application/x-sh"; use = ["edit" "shell"]; }
        { mime = "application/x-python-code"; use = "python"; }
        { mime = "text/x-python"; use = "python"; }
        { mime = "application/xml"; use = "edit"; }
        { mime = "application/xul"; use = "edit"; }
        { mime = "application/x-bzip"; use = "archive"; }
        { mime = "application/x-bzip2"; use = "archive"; }
        { mime = "application/gzip"; use = "archive"; }
        { mime = "application/vnd.rar"; use = "archive"; }
        { mime = "application/x-tar"; use = "archive"; }
        { mime = "application/zip"; use = "archive"; }
        { mime = "application/x-7z-compressed"; use = "archive"; }
      ];
    };
  };
}
