local overrides = require("custom.configs.overrides")

---@type NvPluginSpec[]
local plugins = {
  ---------------------
  -- General Plugins --
  ---------------------
  -- LSP Stuff
  {
    "williamboman/mason.nvim",
    -- opts = overrides.mason
    opts = {
      ensure_installed = {
        -- rust stuff
        "rust-analyzer",

        -- lua stuff
        "lua-language-server",
        "stylua",

        -- web dev stuff
        "css-lsp",
        "html-lsp",
        "typescript-language-server",
        -- "deno",
        "prettier",

        -- c/cpp stuff
        "clangd",
        "clang-format",

        -- python stuff
        "pyright",
        "mypy",
        "autoflake",
        "debugpy"
        -- "ruff",

      }
    }
  },
  {
    'nvimtools/none-ls.nvim',
    ft = {'python'},
    opts = function()
      return require('custom.configs.null-ls')
    end
  },
  {
    "neovim/nvim-lspconfig",
    config = function()
      require "plugins.configs.lspconfig"
      require "custom.configs.lspconfig"
    end, -- Override to setup mason-lspconfig
    ft = {"python"}
  },

  -- Debugger
  {'mfussenegger/nvim-dap',
    config = function(_,opts)
      require('core.utils').load_mappings('dap')
    end
  },
  {
    "rcarriga/nvim-dap-ui",
    dependencies = "mfussenegger/nvim-dap",
    config = function ()
      local dap = require('dap')
      local dapui = require("dapui")
      dapui.setup()
      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
    end
  },

  -- Delimiters
  'Raimondi/delimitMate',

  -- Syntax Highlighting
  {
    "nvim-treesitter/nvim-treesitter",
    opts = overrides.treesitter,
  },
  -- File manager
  {
    "nvim-tree/nvim-tree.lua",
    opts = overrides.nvimtree,
  },

  -- Install a plugin
  {
    "max397574/better-escape.nvim",
    event = "InsertEnter",
    config = function()
      require("better_escape").setup()
    end,
  },

  -- TODO: remove this on nvim 0.10
  {
    "ojroques/nvim-osc52",
    config = function()
      local function copy(lines, _)
        require('osc52').copy(table.concat(lines, '\n'))
      end

      local function paste()
        return {vim.fn.split(vim.fn.getreg(''), '\n'), vim.fn.getregtype('')}
      end

      vim.g.clipboard = {
        name = 'osc52',
        copy = {['+'] = copy, ['*'] = copy},
        paste = {['+'] = paste, ['*'] = paste},
      }

      -- Now the '+' register will copy to system clipboard using OSC52
      -- vim.keymap.set('n', '<leader>c', '"+y')
      -- vim.keymap.set('n', '<leader>cc', '"+yy')
    end
  },

  -- Nyoom around files
  {
    "smoka7/hop.nvim",
    lazy = false,
    config = function ()
      local hop = require('hop')
      hop.setup()
      require('core.utils').load_mappings('hop')

    end
  },

  ------------
  -- Python --
  ------------
  {
    'mfussenegger/nvim-dap-python',
    ft = 'python',
    dependencies = {
      'mfussenegger/nvim-dap',
        'rcarriga/nvim-dap-ui'
    },
    config = function(_, opts)
      local path = vim.fn.stdpath("data") .. "/mason/packages/debugpy/venv/bin/python"
      require('dap-python').setup(path)
      require('core.utils').load_mappings('dap_python')
    end
  },

  ----------
  -- Rust --
  ----------
  { 'rust-lang/rust.vim', ft = 'rust',
    init = function()
      vim.g.rustfmt_autosave = 1
    end
  },
  {
    'simrat39/rust-tools.nvim',
    ft = 'rust',
    dependencies = "neovim/nvim-lspconfig",
    opts = function()
      return require('custom.configs.rust-tools')
    end,
    config = function(_, opts)
      require("rust-tools").setup(opts)
    end
  },
  {
    'saecki/crates.nvim',
    ft = {'rust', 'toml'},
    config = function (_, opts)
      local crates = require('crates')
      crates.setup(opts)
      crates.show()
    end
  }

  -- All NvChad plugins are lazy-loaded by default
  -- For a plugin to be loaded, you will need to set either `ft`, `cmd`, `keys`, `event`, or set `lazy = false`
  -- If you want a plugin to load on startup, add `lazy = false` to a plugin spec, for example
  -- {
  --   "mg979/vim-visual-multi",
  --   lazy = false,
  -- }
}

return plugins
