{ pkgs, lib, ... }:

with builtins;
{
  config.home-manager.users.moritz.programs.neovim.lazy.plugins = with pkgs.vimPlugins; [
    {
      plugin = nvim-dap;
      keys = [
        { key = "<leader>cb"; cmd = "<cmd>lua require('dap').toggle_breakpoint()<cr>"; desc = "Toggle breakpoint"; }
        { key = "<leader>cd"; cmd = "<cmd>lua require('dap').continue()<cr>"; desc = "Continue"; }
      ];
      dependencies = [
        {
          plugin = nvim-dap-python;
          ft = [ "python" ];
          conf =
            let
              pythonWithDebugpy = pkgs.python3.withPackages (ps: with ps; [ debugpy ]);
            in
              /* lua */ ''
              require("dap-python").setup("${lib.getExe pythonWithDebugpy}")
            '';
        }
        {
          plugin = nvim-dap-virtual-text;
          opts = { };
        }
        {
          plugin = nvim-dap-ui;
          opts = { };
          conf = /* lua */ ''
            local dap = require("dap")
            local dapui = require("dapui")
            dapui.setup(opts)
            dap.listeners.after.event_initialized["dapui_config"] = function()
              dapui.open({})
            end
            dap.listeners.before.event_terminated["dapui_config"] = function()
              dapui.close({})
            end
            dap.listeners.before.event_exited["dapui_config"] = function()
              dapui.close({})
            end
          '';
        }
      ];
    }
  ];
}
