{ config, pkgs, lib, ... }:

with lib;
let
  cfg = config.modules.software.editors.vscode;
in {
  options.modules.software.editors.vscode = {
    enable = mkEnableOption "Enable visual studio code, microsoft's gui code editor + IDE";
  };

  config = mkIf cfg.enable {
    hm.programs.vscode = {
      enable = true;
      extensions = with pkgs.vscode-extensions; [
        # nix is *the* language here
        jnoortheen.nix-ide

        # general extensions
        oderwat.indent-rainbow
        usernamehw.errorlens
        editorconfig.editorconfig
        ms-vsliveshare.vsliveshare
        ms-vscode-remote.remote-ssh
        tamasfe.even-better-toml

        # language specific
        astro-build.astro-vscode
        dbaeumer.vscode-eslint
      ] ++ pkgs.vscode-utils.extensionsFromVscodeMarketplace [
        {
          name = "discord-vscode";
          publisher = "icrawl";
          version = "5.8.0";
          sha256 = "sha256-IU/looiu6tluAp8u6MeSNCd7B8SSMZ6CEZ64mMsTNmU=";
        }
      ];
      mutableExtensionsDir = false;
      enableExtensionUpdateCheck = false;
      enableUpdateCheck = false;
      userSettings = with config.modules.desktop.fonts.fonts; {
        "editor.fontFamily" = "'${monospace.family}', monospace";
        "editor.fontSize" = monospace.size;

        "terminal.integrated.fontFamily" = "\"${monospace.family}\"";
        "terminal.integrated.fontSize" = monospace.size;
        "terminal.integrated.smoothScrolling" = true;

        "telemetry.telemetryLevel" = "off";

        "editor.tabSize" = 4;
        "editor.cursorSmoothCaretAnimation" = "on";

        "window.dialogStyle" = "custom";
        "window.titleBarStyle" = "custom";

        "workbench.tips.enabled" = false;
        "workbench.list.smoothScrolling" = true;

        "nix.enableLanguageServer" = true;
        "nix.serverPath" = "${lib.getExe pkgs.nil}";

        "security.workspace.trust.untrustedFiles" = "open";

        "explorer.compactFolders" = false;
        "explorer.confirmDelete" = false;
        "explorer.confirmDragAndDrop" = true;

        "editor.smoothScrolling" = true;
        "editor.wordWrap" = "on";
        "editor.wrappingStrategy" = "advanced";
        "editor.fontWeight" = "normal";
        "editor.semanticHighlighting.enabled" = true;

        # prevent vscode from modifying the terminal colors
        "terminal.integrated.minimumContrastRatio" = 1;
      };
    };
  };
}
