local M = {}

M.lazy = {

  -- Is plugin loaded?
  -- This function is safe to use even if plugin does not exist
  is_plugin_loaded = function(plugin)
    plugin = require("lazy.core.config").plugins[plugin]
    return (plugin ~= nil) and (plugin._.loaded ~= nil)
  end,

  -- Is plugin configured?
  is_plugin = function(plugin)
    return require("lazy.core.config").plugins[plugin] ~= nil
  end,
}

function M.statuscolumn()
  -- lazyvim.util.ui.statuscolumn uses vim.wo[win].signcolumn to determine if it should show signcolumn
  --

  local win = vim.g.statusline_winid
  local buf = vim.api.nvim_win_get_buf(win)
  local next = next -- https://stackoverflow.com/a/1252776
  local signcolumn = vim.g.signcolumn

  -- If there are no signs to show, nvim_buf_get_extmarks() will return {}
  -- also, <nvim-0.10 might not show *all* signs, so always show signcolumn if <nvim-0.10
  local extmarks = vim.fn.has("nvim-0.10") and vim.api.nvim_buf_get_extmarks(
    buf, -- bufnr
    -1,  -- namespace id
    0,   -- start(line)
    -1,  -- end(line)
    { details = true, type = "sign" } -- options
  ) or {true}

  -- if signcolumn == yes or signcolumn = auto, and extmarks is *not* empty
  if signcolumn == "yes" or (signcolumn == "auto" and next(extmarks) ~= nil) then
    vim.wo[win].signcolumn = "yes"
  else
    vim.wo[win].signcolumn = "no"
  end

  return require('lazyvim.util').ui.statuscolumn()
end

return M