{ lib, config, pkgs, ... }:
let
  configuredMpv = config.programs.mpv.finalPackage;
in{

  config = lib.mkIf (config.syscfg.make.gui) {
    programs.mpv = {
      enable = true;
      scripts = with pkgs.mpvScripts; [ mpris modernz ];
      config = {
        hwdec ="auto";
        profile ="high-quality";
        osc ="no";

      };

      bindings =
      let
        shadersPkg = "${pkgs.mpv-shim-default-shaders}/share/mpv-shim-default-shaders/shaders";
        setShader = message: files:
          ''no-osd change-list glsl-shaders set "${lib.concatStringsSep ":" files}"; show-text "${message}"'';
      in
      {
        "CTRL+1" = setShader "Anime4K: Mode A+A (Balanced)" [
          "${shadersPkg}/Anime4K_Clamp_Highlights.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_M.glsl"
          "${shadersPkg}/Anime4K_Upscale_CNN_x2_M.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_S.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x4.glsl"
          "${shadersPkg}/Anime4K_Upscale_CNN_x2_S.glsl"
        ];
        "CTRL+2" = setShader "Anime4K: Mode B+B (Soft)" [
          "${shadersPkg}/Anime4K_Clamp_Highlights.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_Soft_M.glsl"
          "${shadersPkg}/Anime4K_Upscale_CNN_x2_M.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x4.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_Soft_S.glsl"
          "${shadersPkg}/Anime4K_Upscale_CNN_x2_S.glsl"
        ];
        "CTRL+3" = setShader "Anime4K: Mode C+A (Heavy Denoise)" [
          "${shadersPkg}/Anime4K_Clamp_Highlights.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_Upscale_Denoise_CNN_x2_M.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x4.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_S.glsl"
          "${shadersPkg}/Anime4K_Upscale_CNN_x2_S.glsl"
        ];
        "CTRL+4" = setShader "Hybrid: FSRCNNX + Anime4K Balanced" [
          "${shadersPkg}/Anime4K_Clamp_Highlights.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x4.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_M.glsl"
          "${shadersPkg}/FSRCNNX_x2_16-0-4-1.glsl"
          "${shadersPkg}/CAS-scaled.glsl"
        ];

        "CTRL+5" = setShader "Hybrid: FSRCNNX + Anime4K Fast" [
          "${shadersPkg}/Anime4K_Clamp_Highlights.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x2.glsl"
          "${shadersPkg}/Anime4K_AutoDownscalePre_x4.glsl"
          "${shadersPkg}/Anime4K_Restore_CNN_VL.glsl"
          "${shadersPkg}/FSRCNNX_x2_16-0-4-1.glsl"
          "${shadersPkg}/CAS-scaled.glsl"
        ];

        "CTRL+6" = setShader "Movie: FSRCNNX + Natural Sharp" [
          "${shadersPkg}/FSRCNNX_x2_16-0-4-1.glsl"
          "${shadersPkg}/CAS-scaled.glsl"
        ];

        "CTRL+0" = ''no-osd change-list glsl-shaders clr ""; show-text "GLSL shaders cleared"'';
      };
    };#--target-colorspace-hint-mode=source for HDR
    xdg.configFile."jellyfin-mpv-shim/conf.json".text = builtins.toJSON {
      "mpv_ext" = true;
      "mpv_ext_path" = "${configuredMpv}/bin/mpv";
      "mpv_ext_start" = true;
      "mpv_ext_no_ovr" = true;
    };

    programs.yt-dlp.enable = true;
  };
}
