require("mini.align").setup()
require("mini.move").setup()

require("mini.statusline").setup({
  content = {
    active = function()
      local mode, mode_hl = MiniStatusline.section_mode({ trunc_width = 120 })
      local git = MiniStatusline.section_git({ trunc_width = 75 })
      local diagnostics = MiniStatusline.section_diagnostics({ trunc_width = 75 })
      local filename = MiniStatusline.section_filename({ trunc_width = 140 })
      local fileinfo = MiniStatusline.section_fileinfo({ trunc_width = 120 })
      local location = MiniStatusline.section_location({ trunc_width = 75 })
      local mode_hl_inverse = mode_hl .. "Inverse"
      -- Usage of `MiniStatusline.combine_groups()` ensures highlighting and
      -- correct padding with spaces between groups (accounts for 'missing'
      -- sections, etc.)
      return MiniStatusline.combine_groups({
        { hl = mode_hl_inverse, strings = {} },
        "",
        { hl = mode_hl, strings = { mode } },
        { hl = "MiniStatuslineDevinfo", strings = { git, diagnostics } },
        "%<", -- Mark general truncate point
        { hl = "MiniStatuslineFilename", strings = { filename } },
        "%=", -- End left alignment
        { hl = "MiniStatuslineFileinfo", strings = { fileinfo } },
        { hl = mode_hl, strings = { location } },
        { hl = mode_hl_inverse, strings = {} },
        "",
      })
    end,
  },
})
local MiniStatuslineModes = {
  "MiniStatuslineModeInsert",
  "MiniStatuslineModeNormal",
  "MiniStatuslineModeReplace",
  "MiniStatuslineModeVisual",
  "MiniStatuslineModeCommand",
  "MiniStatuslineModeOther",
}
for _, mode_hl in ipairs(MiniStatuslineModes) do
  local hl_table = vim.api.nvim_get_hl(0, { name = mode_hl })
  local fg = hl_table.fg
  hl_table.fg = hl_table.bg
  hl_table.bg = fg
  vim.api.nvim_set_hl(0, mode_hl .. "Inverse", hl_table)
end
