{ inputs, pkgs, ... }:

let
  openvsx-extensions = inputs.nix-vscode-extensions.extensions.x86_64-linux.open-vsx;
  vscode-extensions = inputs.nix-vscode-extensions.extensions.x86_64-linux.vscode-marketplace;
in
{
  home.packages = with pkgs;[
    (nerdfonts.override { fonts = [ "SpaceMono" ]; })
  ];

  programs = {
    vscode = {
      enable = true;
      package = inputs.nixpkgs-unstable.legacyPackages."${pkgs.system}".vscodium;
      mutableExtensionsDir = false;
      enableUpdateCheck = false;
      enableExtensionUpdateCheck = false;
      extensions = with openvsx-extensions;[
        biomejs.biome
        mkhl.direnv
        dracula-theme.theme-dracula
        dbaeumer.vscode-eslint
        eamodio.gitlens
        pkief.material-icon-theme
        jnoortheen.nix-ide
        esbenp.prettier-vscode
        humao.rest-client
        loriscro.super
        mads-hartmann.bash-ide-vscode
        foxundermoon.shell-format
        dart-code.flutter
        ms-vscode.wasm-wasi-core
        rust-lang.rust-analyzer
        tamasfe.even-better-toml
        mikestead.dotenv
      ] ++ [ vscode-extensions.bradlc.vscode-tailwindcss ];
      userSettings = with pkgs;{
        "workbench.iconTheme" = "material-icon-theme";
        "window.titleBarStyle" = "custom";
        "workbench.colorTheme" = "Dracula Theme";
        "explorer.compactFolders" = false;
        "chat.commandCenter.enabled" = false;

        "editor.fontFamily" = "'SpaceMono Nerd Font', 'monospace', monospace";
        "editor.fontSize" = 16;
        "editor.formatOnSave" = true;
        "editor.codeActionsOnSave" = {
          "source.organizeImports" = "always";
        };

        "files.autoSave" = "onWindowChange";

        "[typescript]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "[javascript]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "[javascriptreact]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "[typescriptreact]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "[json]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "[jsonc]" = {
          "editor.defaultFormatter" = "biomejs.biome";
        };
        "biome.lsp.bin" = "${biome}/bin/biome";

        "typescript.preferences.preferTypeOnlyAutoImports" = true;

        "nix.enableLanguageServer" = true; # Enable LSP.
        "nix.serverPath" = "${nixd}/bin/nixd"; # The path to the LSP server executable.
        "nix.serverSettings" = {
          nixd = {
            formatting.command = [ "${nixpkgs-fmt}/bin/nixpkgs-fmt" ];
          };
        };

        "bashIde.shellcheckPath" = "${shellcheck}/bin/shellcheck";
        "shellformat.path" = "${shfmt}/bin/shfmt";

        "rust-analyzer.rustfmt.overrideCommand" = [ "${rustfmt}/bin/rustfmt" ];
      };
    };
  };
}

