-- Barbar configuration with bearded-arc colors

local colors = {
  bg = "#1c2433",           -- black (main bg)
  bg_inactive = "#232b3a",  -- black2 (inactive tabs)
  fg = "#c3cfd9",           -- base05
  fg_inactive = "#626a79",  -- light_grey
  white = "#ABB7C1",        -- white (active text)

  selected_bg = "#303847",  -- one_bg2 (selected tab bg)
  modified = "#3CEC85",     -- green
  error = "#FF738A",        -- red
  warn = "#EACD61",         -- yellow
  info = "#69C3FF",         -- blue
  hint = "#bd93ff",         -- purple

  nord_blue = "#6da4cd",    -- accent color
}

require("barbar").setup({
  animation = false,
  auto_hide = false,
  tabpages = true,
  clickable = true,
  focus_on_close = "left",

  highlight_alternate = false,
  highlight_inactive_file_icons = false,
  highlight_visible = false,

  icons = {
    buffer_index = false,
    buffer_number = false,
    button = "",
    diagnostics = {
      [vim.diagnostic.severity.ERROR] = { enabled = true, icon = " " },
      [vim.diagnostic.severity.WARN] = { enabled = false },
      [vim.diagnostic.severity.INFO] = { enabled = false },
      [vim.diagnostic.severity.HINT] = { enabled = false },
    },
    gitsigns = {
      added = { enabled = false },
      changed = { enabled = false },
      deleted = { enabled = false },
    },
    filetype = {
      custom_colors = false,
      enabled = false,
    },
    separator = { left = "▎", right = "" },
    separator_at_end = true,
    modified = { button = "●" },
    pinned = { button = "󰐃 ", filename = true },
    preset = "default",
    alternate = { filetype = { enabled = false } },
    current = { buffer_index = false },
    inactive = { button = "" },
    visible = { modified = { buffer_number = false } },
  },

  insert_at_end = false,
  insert_at_start = false,
  maximum_padding = 1,
  minimum_padding = 1,
  maximum_length = 15,
  minimum_length = 15,  -- Set to same as maximum for uniform width

  semantic_letters = true,
  sidebar_filetypes = {
    undotree = { text = "undotree" },
  },

  no_name_title = nil,
})

-- Set custom highlight groups to match bearded-arc theme
vim.api.nvim_set_hl(0, "BufferCurrent", { fg = colors.white, bg = colors.bg, bold = true })
vim.api.nvim_set_hl(0, "BufferCurrentIndex", { fg = colors.white, bg = colors.bg })
vim.api.nvim_set_hl(0, "BufferCurrentMod", { fg = colors.modified, bg = colors.bg, bold = true })
vim.api.nvim_set_hl(0, "BufferCurrentSign", { fg = colors.nord_blue, bg = colors.bg })
vim.api.nvim_set_hl(0, "BufferCurrentTarget", { fg = colors.error, bg = colors.bg, bold = true })

vim.api.nvim_set_hl(0, "BufferVisible", { fg = colors.fg, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferVisibleIndex", { fg = colors.fg, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferVisibleMod", { fg = colors.modified, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferVisibleSign", { fg = colors.fg_inactive, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferVisibleTarget", { fg = colors.error, bg = colors.bg_inactive, bold = true })

vim.api.nvim_set_hl(0, "BufferInactive", { fg = colors.fg_inactive, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferInactiveIndex", { fg = colors.fg_inactive, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferInactiveMod", { fg = colors.modified, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferInactiveSign", { fg = colors.fg_inactive, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferInactiveTarget", { fg = colors.error, bg = colors.bg_inactive })

vim.api.nvim_set_hl(0, "BufferTabpages", { fg = colors.nord_blue, bg = colors.bg_inactive, bold = true })
vim.api.nvim_set_hl(0, "BufferTabpageFill", { fg = colors.fg_inactive, bg = colors.bg_inactive })

vim.api.nvim_set_hl(0, "BufferOffset", { fg = colors.fg_inactive, bg = colors.bg_inactive })

-- Error diagnostics highlight
vim.api.nvim_set_hl(0, "BufferCurrentERROR", { fg = colors.error, bg = colors.bg })
vim.api.nvim_set_hl(0, "BufferVisibleERROR", { fg = colors.error, bg = colors.bg_inactive })
vim.api.nvim_set_hl(0, "BufferInactiveERROR", { fg = colors.error, bg = colors.bg_inactive })
