local transparent_mode = false

local c = {
  foreground = "#fbf1c7",
  soft_green = "#b8bb26",
  forest_green = "#b8bb26",
  soft_yellow = "#fabd2f",
  light_blue = "#83a598",
  magenta = "#d3869b",
  orange = "#fe8019",
  gray = "#928374",
  comment = "#928374",
  dark0 = "#0d0e0f",
  dark = "#202020",
  background = "#282828",
  background_dark = "#1d2021",
  background_light = "#32302f",
  medium_gray = "#504945",
  bright_yellow = "#fabd2f",
  red = "#fb4934",
  error_red = "#cc241d",
  pink = "#D4879C",
  dark_gray = "#83a598",
  blue_gray = "#458588",
  clean_green = "#8ec07c",
  milk = "#E7D7AD",
  none = "NONE",
  diff = {
    add = "#26332c",
    change = "#273842",
    delete = "#572E33",
    text = "#314753",
  }
}

if transparent_mode then
  c.background = c.NONE
  c.background_dark = c.NONE
  c.background_light = c.NONE
end


local theme = {
  NormalFloat = { fg = c.foreground, bg = c.background },
  Normal = { fg = c.foreground, bg = c.background },
  Comment = { fg = c.comment, italic = true },
  Constant = { fg = c.pink },
  String = { fg = c.soft_green, nocombine = true },
  Character = { fg = c.soft_yellow },
  Number = { fg = c.bright_yellow },
  Boolean = { fg = c.orange },
  Float = { fg = c.bright_yellow },
  Identifier = { fg = c.light_blue },
  Function = { fg = c.soft_yellow },
  Statement = { fg = c.red },
  Conditional = { fg = c.foreground },
  Repeat = { fg = c.magenta },
  Label = { fg = c.dark_gray },
  Operator = { fg = c.foreground },
  Keyword = { fg = c.red, italic = true },
  Exception = { fg = c.magenta },
  PreProc = { fg = c.soft_yellow },
  Include = { fg = c.red },
  Define = { fg = c.magenta },
  Title = { fg = c.foreground },
  Macro = { fg = c.magenta },
  PreCondit = { fg = c.magenta },
  Type = { fg = c.soft_yellow },
  StorageClass = { fg = c.blue_gray },
  Structure = { fg = c.soft_yellow },
  Typedef = { fg = c.soft_yellow },
  Special = { fg = c.dark_gray },
  SpecialComment = { fg = c.comment },
  MoreMsg = { fg = c.foreground },
  Error = { fg = c.red, bold = true },
  Todo = { fg = c.magenta, bold = true },
  CursorLineNr = { fg = c.comment, bold = true },
  debugPc = { bg = c.error_red },
  Conceal = { fg = c.comment },
  Directory = { fg = c.dark_gray },

  TabLine = { bg = c.dark, fg = c.comment },
  TabLineFill = { bg = c.background },
  TabLineSel = { fg = c.foreground, bg = c.background_dark },

  DiffAdd = { bg = c.diff.add },
  DiffChange = { bg = c.diff.change },
  DiffDelete = { bg = c.diff.delete },
  DiffText = { bg = c.diff.text },

  ErrorMsg = { fg = c.red },
  VertSplit = { fg = c.background_light },
  Folded = { fg = "#928374", bg = "#3c3836", italic = true },
  LineNr = { fg = c.medium_gray },
  MatchParen = { bg = c.diff.text, underline = true },
  NonText = { fg = c.comment },
  Pmenu = { fg = c.foreground, bg = c.background_light },
  PmenuSel = { fg = c.background, bg = c.blue_gray },
  Question = { fg = c.magenta },
  QuickFixLine = { fg = c.background, bg = c.soft_yellow },
  Search = { bg = c.medium_gray },
  SpecialKey = { fg = c.comment },
  SpellBad = { fg = c.red, underline = true },
  SpellCap = { fg = c.bright_yellow },
  SpellLocal = { fg = c.bright_yellow },
  SpellRare = { fg = c.bright_yellow },
  StatusLine = { fg = c.foreground, bg = c.background },
  StatusLineNC = { fg = c.comment },
  StatusLineTerm = { fg = c.foreground, bg = c.background },
  StatusLineTermNC = { fg = c.medium_gray },
  Terminal = { fg = c.foreground, bg = c.background },
  VisualNOS = { fg = c.medium_gray },
  WarningMsg = { fg = c.soft_yellow },
  WildMenu = { fg = c.background, bg = c.blue_gray },
  EndOfBuffer = { fg = c.background },
  WhichKey = { fg = c.magenta },
  WhichKeySeperator = { fg = c.soft_yellow },
  WhichKeyGroup = { fg = c.orange },
  WhichKeyDesc = { fg = c.forest_green },

  -- Tree Sitter
  ["@boolean"] = { fg = c.orange },
  ["@define"] = { fg = c.red },
  ["@keyword.directive"] = { fg = c.red },
  ["@comment"] = { fg = c.comment, italic = true },
  ["@error"] = { fg = c.red },
  ["@punctuation.delimiter"] = { fg = c.foreground },
  ["@punctuation.bracket"] = { fg = c.foreground },
  ["@punctuation.special"] = { fg = c.foreground },
  ["@markup.list"] = { fg = c.foreground },
  ["@constant"] = { fg = c.pink, bold = true },
  ["@definition.constant"] = { fg = c.pink, bold = true },
  ["@constant.builtin"] = { fg = c.pink },
  ["@string"] = { fg = c.soft_green },
  ["@character"] = { fg = c.soft_green },
  ["@number"] = { fg = c.magenta },
  ["@namespace"] = { fg = c.light_blue },
  ["@module"] = { fg = c.light_blue },
  ["@func.builtin"] = { fg = c.soft_yellow },
  ["@function"] = { fg = c.soft_yellow, bold = true },
  ["@function.call"] = { fg = c.soft_yellow, bold = true },
  ["@function.builtin"] = { fg = c.soft_yellow, bold = true },
  ["@func.macro"] = { fg = c.soft_yellow },
  ["@parameter"] = { fg = c.blue_gray, nocombine = true },
  ["@variable.parameter"] = { fg = c.blue_gray, nocombine = true },
  ["@parameter.reference"] = { fg = c.dark_gray },
  ["@method"] = { fg = c.soft_yellow, bold = true },
  ["@function.method"] = { fg = c.soft_yellow, bold = true },
  ["@method.call"] = { fg = c.soft_yellow, bold = true },
  ["@function.method.call"] = { fg = c.soft_yellow, bold = true },
  ["@field"] = { fg = c.light_blue },
  ["@variable.member"] = { fg = c.light_blue },
  ["@property"] = { fg = c.blue_gray },
  ["@constructor"] = { fg = c.clean_green, nocombine = true },
  ["@conditional"] = { fg = c.red },
  ["@keyword.conditional"] = { fg = c.red },
  ["@repeat"] = { fg = c.red },
  ["@keyword.repeat"] = { fg = c.red },
  ["@label"] = { fg = c.blue_gray },
  ["@keyword"] = { fg = c.red, italic = true },
  ["@keyword.return"] = { fg = c.red, italic = true },
  ["@keyword.function"] = { fg = c.red, italic = true },
  ["@keyword.operator"] = { fg = c.red },
  ["@operator"] = { fg = c.foreground },
  ["@exception"] = { fg = c.red },
  ["@keyword.exception"] = { fg = c.red },
  ["@type"] = { fg = c.clean_green },
  ["@type.builtin"] = { fg = c.blue_gray },
  ["@type.qualifier"] = { fg = c.orange },
  ["@storageclass.lifetime"] = { fg = c.orange },
  ["@keyword.storage.lifetime"] = { fg = c.orange },
  ["@structure"] = { fg = c.blue_gray },
  ["@variable"] = { fg = c.light_blue },
  ["@variable.builtin"] = { fg = c.blue_gray },
  ["@text"] = { fg = c.soft_yellow },
  ["@text.strong"] = { fg = c.soft_yellow, bold = true },
  ["@text.emphasis"] = { fg = c.soft_yellow, italic = true },
  ["@text.underline"] = { fg = c.soft_yellow, underline = true },
  ["@text.strike"] = { fg = c.medium_gray, strikethrough = true },
  ["@text.title"] = { fg = c.soft_yellow },
  ["@text.literal"] = { fg = c.soft_yellow },
  ["@markup"] = { fg = c.soft_yellow },
  ["@markup.strong"] = { fg = c.soft_yellow, bold = true },
  ["@markup.emphasis"] = { fg = c.soft_yellow, italic = true },
  ["@markup.underline"] = { fg = c.soft_yellow, underline = true },
  ["@markup.strike"] = { fg = c.medium_gray, strikethrough = true },
  ["@markup.heading"] = { fg = c.soft_yellow },
  ["@markup.raw"] = { fg = c.soft_yellow },
  ["@uri"] = { fg = c.soft_yellow },
  ["@tag"] = { fg = c.clean_green },
  ["@tag.delimiter"] = { fg = c.comment },
  ["@tag.attribute"] = { fg = c.soft_yellow },
  --

  ["@lsp.type.class"] = { fg = c.clean_green },
  ["@lsp.type.decorator"] = { fg = c.orange },
  ["@lsp.type.enum"] = { fg = c.clean_green },
  ["@lsp.type.enumMember"] = { fg = c.clean_green },
  ["@lsp.type.function"] = { fg = c.soft_yellow, bold = true },
  ["@lsp.type.interface"] = { fg = c.clean_green },
  ["@lsp.type.macro"] = { fg = c.orange },
  ["@lsp.type.method"] = { fg = c.soft_yellow },
  ["@lsp.type.namespace"] = { fg = c.clean_green },
  ["@lsp.type.parameter"] = { fg = c.blue_gray },
  ["@lsp.type.property"] = { fg = c.blue_gray },
  ["@lsp.type.struct"] = { fg = c.clean_green },
  ["@lsp.type.type"] = { fg = c.clean_green },
  ["@lsp.type.typeParameter"] = { fg = c.clean_green },
  ["@lsp.type.variable"] = { fg = c.light_blue },

  diffAdded = { fg = c.forest_green },
  diffRemoved = { fg = c.red },
  diffFileId = { fg = c.magenta },
  diffFile = { fg = c.comment },
  diffNewFile = { fg = c.soft_yellow },
  diffOldFile = { fg = c.orange },

  SignifySignAdd = { fg = c.soft_yellow },
  SignifySignChange = { fg = c.soft_yellow },
  SignifySignDelete = { fg = c.orange },
  GitGutterAdd = { fg = c.forest_green },
  GitGutterChange = { fg = c.soft_yellow },
  GitGutterDelete = { fg = c.error_red },
  debugBreakpoint = { fg = c.error_red, reverse = true },

  ColorColumn = { bg = c.background_dark },
  SignColumn = { bg = c.background },
  CursorColumn = { bg = c.background_light },
  CursorLine = { bg = c.background_light },
  FoldColumn = { fg = c.none },
  PmenuSbar = { bg = c.comment },
  PmenuThumb = { bg = c.foreground },
  EasyMotionShade = { fg = c.NONE },
  Visual = { bg = c.medium_gray },
  MultiCursor = { bg = c.background_light },
  Cursor = { bg = c.medium_gray, fg = c.NONE },

  -- mix
  GitSignsCurrentLineBlame = { fg = c.medium_gray },
  Underlined = { fg = c.error_red, underline = true },
  ["@variable.cpp"] = { fg = c.foreground },

  -- NeoTree
  NeoTreeNormal = { fg = c.foreground, bg = c.background },
  NeoTreeNormalNC = { fg = c.foreground, bg = c.background },
  NeoTreeVertSplit = { fg = c.background, bg = c.background },
  NeoTreeWinSeparator = { fg = c.background, bg = c.background },
  NeoTreeDirectoryIcon = { fg = c.soft_yellow },
  NeoTreeRootName = { fg = c.magenta },
  NeoTreeExecFile = { fg = c.light_blue },

  NeoTreeGitUnstaged = { fg = c.red },
  NeoTreeGitStaged = { fg = c.foreground },
  NeoTreeGitModified = { fg = c.soft_yellow },
  NeoTreeGitUnstracked = { fg = c.soft_green },
  NeoTreeGitDeleted = { fg = c.red },

  FloatBorder = { bg = c.background },
  -- Cmp
  CmpDocumentation = { fg = c.foreground, bg = c.bg_float },
  CmpDocumentationBorder = { fg = c.medium_gray, bg = c.bg_float },

  CmpItemAbbr = { fg = c.foreground },
  CmpItemAbbrDeprecated = { fg = c.milk, strikethrough = true },
  CmpItemAbbrMatch = { fg = c.light_blue },
  CmpItemAbbrMatchFuzzy = { fg = c.light_blue },

  CmpItemKindDefault = { fg = c.dark_gray },
  CmpItemMenu = { fg = c.comment },

  CmpItemKindKeyword = { fg = c.blue_gray },

  CmpItemKindVariable = { fg = c.magenta },
  CmpItemKindConstant = { fg = c.magenta },
  CmpItemKindReference = { fg = c.magenta },
  CmpItemKindValue = { fg = c.magenta },

  CmpItemKindFunction = { fg = c.orange },
  CmpItemKindMethod = { fg = c.orange },
  CmpItemKindConstructor = { fg = c.orange },

  CmpItemKindClass = { fg = c.pink },
  CmpItemKindInterface = { fg = c.pink },
  CmpItemKindStruct = { fg = c.pink },
  CmpItemKindEvent = { fg = c.pink },
  CmpItemKindEnum = { fg = c.pink },
  CmpItemKindUnit = { fg = c.pink },

  CmpItemKindModule = { fg = c.soft_yellow },

  CmpItemKindProperty = { fg = c.forest_green },
  CmpItemKindField = { fg = c.forest_green },
  CmpItemKindTypeParameter = { fg = c.forest_green },
  CmpItemKindEnumMember = { fg = c.forest_green },
  CmpItemKindOperator = { fg = c.forest_green },
  CmpItemKindSnippet = { fg = c.gray },

  DiagnosticError = { fg = c.red },
  DiagnosticWarning = { fg = c.soft_yellow },
  DiagnosticInformation = { fg = c.light_blue },
  DiagnosticHint = { fg = c.dark_gray },

  ModeMsg = { fg = c.milk },
  IncSearch = { bg = "#ff9e64", fg = "White" },
  CurSearch = { bg = "#ff9e64", fg = "White" },
  FlashLabel = { bg = "#0076CE" },

  WinBar = { bg = c.background_light },
  WinBarNC = { bg = c.background_light },
}

-- reset colors
if vim.g.colors_name then
  vim.cmd.hi("clear")
end

for group, conf in pairs(theme) do
  vim.api.nvim_set_hl(0, group, conf)
end
