local M = {
  "mfussenegger/nvim-dap",
  commit = "6b12294a57001d994022df8acbe2ef7327d30587",
  event = "VeryLazy",
  dependencies = {
    {
      'Joakker/lua-json5',
      build = './install.sh'
    }
  }
}

function M.config()
  local dap = require "dap"

  local dap_ui_status_ok, dapui = pcall(require, "dapui")
  if not dap_ui_status_ok then
    return
  end

  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

  dap.adapters.codelldb = {
    type = "server",
    port = "${port}",
    executable = {
      -- provide the absolute path for `codelldb` command if not using the one installed using `mason.nvim`
      command = "codelldb",
      args = { "--port", "${port}" },
      -- On windows you may have to uncomment this:
      -- detached = false,
    },
  }
  dap.adapters.cppdbg = {
    id = 'cppdbg',
    type = "executable",
    command = '/home/badcoute/src/vscode-cpptools-1.17/extension/debugAdapters/bin/OpenDebugAD7',
  }
  dap.configurations.c = {
    {
      name = "Launch file",
      type = "codelldb",
      request = "launch",
      program = function()
        local path
        -- vim.ui.input({ prompt = "Path to executable: ", default = vim.loop.cwd() .. "/build/" }, function(input)
        vim.ui.input({ prompt = "Path to executable: ", default = vim.loop.cwd()}, function(input)
          path = input
        end)
        vim.cmd [[redraw]]
        return path
      end,
      cwd = "${workspaceFolder}",
      stopOnEntry = false,
    },
  }
  require('dap.ext.vscode').json_decode = require'json5'.parse
  require('dap.ext.vscode').load_launchjs(nil, { cppdbg = {'c', 'cpp'} })
end

-- M = {
--   "ravenxrz/DAPInstall.nvim",
--   commit = "8798b4c36d33723e7bba6ed6e2c202f84bb300de",
--   lazy = true,
--   config = function()
--     require("dap_install").setup {}
--     require("dap_install").config("python", {})
--   end,
-- }

return M
