local M = {}

---@param colors CobaltColors
---@param config? CobaltConfig
function M.setup(colors, config)
    config = config or require("cobalt").config
    local theme = colors.theme
    return {
        -- Neovcs
        -- NeovcsBranch = {},
        -- NeovcsRemote = {},
        -- NeovcsDiffDelete = { fg = theme.vcs.removed, bg = theme.diff.delete },
        -- NeovcsDiffAdd = { fg = theme.vcs.added, bg = theme.diff.add },
        -- NeovcsHunkHeader = { fg = theme.syn.identifier },
        -- NeovcsDiffContextHighlight = { bg = theme.diff.change },

        -- vcsSigns
        -- vcsSignsAdd = { link = "diffAdded" },
        -- vcsSignsChange = { link = "diffChanged" },
        -- vcsSignsDelete = { link = "diffDeleted" },
        -- vcsSignsDeleteLn = { bg = theme.diff.delete },

        BlinkCmpMenuBorder                = { link = "FloatBorder" },
        BlinkCmpDocBorder                 = { link = "FloatBorder" },
        BlinkCmpSignatureHelpBorder       = { link = "FloatBorder" },

        -- copilot.lua
        CopilotAnnotation                 = { fg = theme.syn.deprecated, italic = true },
        CopilotSuggestion                 = { fg = theme.syn.deprecated, italic = true },

        -- Gitsigns
        GitSignsAdd                       = { fg = theme.vcs.added, bg = theme.ui.bg_gutter },
        GitSignsChange                    = { fg = theme.vcs.changed, bg = theme.ui.bg_gutter },
        GitSignsDelete                    = { fg = theme.vcs.removed, bg = theme.ui.bg_gutter },
        -- Neogit
        -- NeogitNormal                      = { bg = theme.ui.float.bg },
        -- NeogitNormalFloat                 = { link = "NormalFloat" },
        NeogitHunkHeader                  = { fg = theme.ui.nontext },
        NeogitHunkHeaderHighlight         = { bg = theme.diff.change,   fg = theme.ui.special },
        NeogitDiffContextHighlight        = { bg = theme.ui.bg,         fg = theme.ui.nontext },
        NeogitDiffContext                 = { bg = theme.ui.float.bg,   fg = theme.ui.nontext },
        NeogitDiffAdd                     = { bg = theme.diff.add,      fg = theme.ui.nontext },
        NeogitDiffDelete                  = { bg = theme.diff.delete,   fg = theme.ui.nontext },
        NeogitDiffAddHighlight            = { bg = theme.diff.add,      fg = theme.vcs.added },
        NeogitDiffDeleteHighlight         = { bg = theme.diff.delete,   fg = theme.vcs.removed },
        -- TreeSitter Extensions
        TreesitterContext                 = { link = "Folded" },
        TreesitterContextLineNumber       = { fg = theme.ui.special, bg = theme.ui.bg_gutter },
        -- Telescope
        TelescopeBorder                   = { link = "FloatBorder" },
        TelescopeTitle                    = { fg = theme.ui.special },
        TelescopeSelection                = { link = 'CursorLine' },
        TelescopeSelectionCaret           = { link = 'CursorLineNr' },
        TelescopeResultsClass             = { link = "Structure" },
        TelescopeResultsStruct            = { link = "Structure" },
        TelescopeResultsField             = { link = "@field" },
        TelescopeResultsMethod            = { link = "Function" },
        TelescopeResultsVariable          = { link = "@variable" },
        -- NvimTree
        NvimTreeNormal                    = { link = "NormalFloat" },
        NvimTreeNormalNC                  = { link = "NvimTreeNormal" },
        NvimTreeRootFolder                = { fg = theme.syn.identifier, bold = true },
        NvimTreeGitDirty                  = { fg = theme.vcs.changed },
        NvimTreeGitNew                    = { fg = theme.vcs.added },
        NvimTreeGitDeleted                = { fg = theme.vcs.removed },
        NvimTreeGitStaged                 = { fg = theme.vcs.added },
        NvimTreeSpecialFile               = { fg = theme.syn.special1 },
        -- NvimTreeIndentMarker           = {},
        NvimTreeImageFile                 = { fg = theme.syn.special2 },
        NvimTreeSymlink                   = { link = "Type" },
        NvimTreeFolderName                = { link = "Directory" },
        NvimTreeExecFile                  = { fg = theme.syn.string, bold = true },
        NvimTreeOpenedFile                = { fg = theme.syn.special1, italic = true },
        NvimTreeWinSeparator              = { link = "WinSeparator" },
        NvimTreeWindowPicker              = { bg = theme.ui.bg_m1, fg = theme.syn.special1, bold = true },
        -- NeoTree
        NeoTreeTabInactive                = { link = "TabLine" },
        NeoTreeTabActive                  = { link = "TabLineSel" },
        NeoTreeTabSeparatorInactive       = { link = "NeoTreeTabInactive" },
        NeoTreeTabSeparatorActive         = { link = "NeoTreeTabActive" },
        NeoTreeRootName                   = { fg = theme.syn.identifier, bold = true },
        NeoTreeModified                   = { link = "String" },
        NeoTreeGitModified                = { fg = theme.vcs.changed },
        NeoTreeGitAdded                   = { fg = theme.vcs.added },
        NeoTreeGitDeleted                 = { fg = theme.vcs.removed },
        NeoTreeGitStaged                  = { fg = theme.vcs.added },
        NeoTreeGitConflict                = { fg = theme.diag.error },
        NeoTreeGitUntracked               = { link = "NeoTreeGitModified", default = true },
        NeoTreeGitUnstaged                = { link = "NeoTreeGitModified", default = true },
        NeoTreeIndentMarker               = { link = "NonText" },
        -- WindowPicker
        -- NvimWindowSwitch = { bg = theme.ui.bg_m3, fg = theme.diag.warning },
        -- NvimWindowSwitchNC = { link = "NvimWindowSwitch" },
        -- Dashboard
        DashboardShortCut                 = { fg = theme.syn.special1 },
        DashboardHeader                   = { fg = theme.vcs.removed },
        DashboardCenter                   = { fg = theme.syn.identifier },
        DashboardFooter                   = { fg = theme.syn.comment },
        DashboardDesc                     = { fg = theme.syn.identifier },
        DashboardKey                      = { fg = theme.syn.special1 },
        DashboardIcon                     = { fg = theme.ui.special },
        -- Notify
        NotifyBackground                  = { bg = theme.ui.bg },
        NotifyERRORBorder                 = { link = "DiagnosticError" },
        NotifyWARNBorder                  = { link = "DiagnosticWarn" },
        NotifyINFOBorder                  = { link = "DiagnosticInfo" },
        NotifyHINTBorder                  = { link = "DiagnosticHint" },
        NotifyDEBUGBorder                 = { link = "Debug" },
        NotifyTRACEBorder                 = { link = "Comment" },
        NotifyERRORIcon                   = { link = "DiagnosticError" },
        NotifyWARNIcon                    = { link = "DiagnosticWarn" },
        NotifyINFOIcon                    = { link = "DiagnosticInfo" },
        NotifyHINTIcon                    = { link = "DiagnosticHint" },
        NotifyDEBUGIcon                   = { link = "Debug" },
        NotifyTRACEIcon                   = { link = "Comment" },
        NotifyERRORTitle                  = { link = "DiagnosticError" },
        NotifyWARNTitle                   = { link = "DiagnosticWarn" },
        NotifyINFOTitle                   = { link = "DiagnosticInfo" },
        NotifyHINTTitle                   = { link = "DiagnosticHint" },
        NotifyDEBUGTitle                  = { link = "Debug" },
        NotifyTRACETitle                  = { link = "Comment" },
        -- Dap-UI
        -- DapUIVariable = { link = "Normal" },
        DapUIScope                        = { link = "Special" },
        DapUIType                         = { link = "Type" },
        -- DapUIValue = { link = "Normal" },
        DapUIModifiedValue                = { fg = theme.syn.special1, bold = true },
        DapUIDecoration                   = { fg = theme.ui.float.fg_border },
        DapUIThread                       = { fg = theme.syn.identifier },
        DapUIStoppedThread                = { fg = theme.syn.special1 },
        -- DapUIFrameName = { link = "Normal"},
        DapUISource                       = { fg = theme.syn.special2 },
        DapUILineNumber                   = { fg = theme.syn.special1 },
        DapUIFloatBorder                  = { link = "FloatBorder" },
        DapUIWatchesEmpty                 = { fg = theme.diag.error },
        DapUIWatchesValue                 = { fg = theme.syn.identifier },
        DapUIWatchesError                 = { fg = theme.diag.error },
        DapUIBreakpointsPath              = { link = "Directory" },
        DapUIBreakpointsInfo              = { fg = theme.diag.info },
        DapUIBreakpointsCurrentLine       = { fg = theme.syn.identifier, bold = true },
        -- DapUIBreakpointsLine = {},
        DapUIBreakpointsDisabledLine      = { link = "Comment" },
        -- DapUICurrentFrameName = {},
        DapUIStepOver                     = { fg = theme.syn.special1 },
        DapUIStepInto                     = { fg = theme.syn.special1 },
        DapUIStepBack                     = { fg = theme.syn.special1 },
        DapUIStepOut                      = { fg = theme.syn.special1 },
        DapUIStop                         = { fg = theme.diag.error },
        DapUIPlayPause                    = { fg = theme.syn.string },
        DapUIRestart                      = { fg = theme.syn.string },
        DapUIUnavailable                  = { fg = theme.syn.comment },
        -- Floaterm
        FloatermBorder                    = { link = "FloatBorder" },
        -- NeoVim                         = {},
        healthError                       = { fg = theme.diag.error },
        healthSuccess                     = { fg = theme.diag.ok },
        healthWarning                     = { fg = theme.diag.warning },
        -- Cmp
        CmpDocumentation                  = { link = "NormalFloat" },
        CmpDocumentationBorder            = { link = "FloatBorder" },
        CmpCompletion                     = { link = "Pmenu" },
        CmpCompletionSel                  = { fg = "NONE", bg = theme.ui.pmenu.bg_sel },
        CmpCompletionBorder               = { link = "FloatBorder" },
        CmpCompletionThumb                = { link = "PmenuThumb" },
        CmpCompletionSbar                 = { link = "PmenuSbar" },
        CmpItemAbbr                       = { fg = theme.ui.pmenu.fg },
        CmpItemAbbrDeprecated             = { fg = theme.syn.comment, strikethrough = true },
        CmpItemAbbrMatch                  = { fg = theme.syn.fun },
        CmpItemAbbrMatchFuzzy             = { link = "CmpItemAbbrMatch" },
        CmpItemKindDefault                = { fg = theme.syn.deprecated },
        CmpItemMenu                       = { fg = theme.syn.comment },
        CmpItemKindVariable               = { fg = theme.ui.fg_dim },
        CmpItemKindFunction               = { link = "Function" },
        CmpItemKindMethod                 = { link = "Function" },
        CmpItemKindConstructor            = { link = "@constructor" },
        CmpItemKindClass                  = { link = "Type" },
        CmpItemKindInterface              = { link = "Type" },
        CmpItemKindStruct                 = { link = "Type" },
        CmpItemKindProperty               = { link = "@property" },
        CmpItemKindField                  = { link = "@field" },
        CmpItemKindEnum                   = { link = "Type" },
        CmpItemKindSnippet                = { fg = theme.syn.special1 },
        CmpItemKindText                   = { fg = theme.ui.pmenu.fg },
        CmpItemKindModule                 = { link = "@include" },
        CmpItemKindFile                   = { link = "Directory" },
        CmpItemKindFolder                 = { link = "Directory" },
        CmpItemKindKeyword                = { link = "@keyword" },
        CmpItemKindTypeParameter          = { link = "Type" },
        CmpItemKindConstant               = { link = "Constant" },
        CmpItemKindOperator               = { link = "Operator" },
        CmpItemKindReference              = { link = "Type" },
        CmpItemKindEnumMember             = { link = "Constant" },
        CmpItemKindValue                  = { link = "String" },
        CmpItemKindCopilot                = { link = "String" },
        -- CmpItemKindUnit = {},
        -- CmpItemKindEvent = {},
        -- CmpItemKindColor = {},

        -- IndentBlankline
        IndentBlanklineChar               = { fg = theme.ui.whitespace },
        IndentBlanklineSpaceChar          = { fg = theme.ui.whitespace },
        IndentBlanklineSpaceCharBlankline = { fg = theme.ui.whitespace },
        IndentBlanklineContextChar        = { fg = theme.ui.special },
        IndentBlanklineContextStart       = { sp = theme.ui.special, underline = true },
        IblIndent                         = { fg = theme.ui.whitespace },
        IblWhitespace                     = { fg = theme.ui.whitespace },
        IblScope                          = { fg = theme.ui.special },
        -- Lazy
        LazyProgressTodo                  = { fg = theme.ui.nontext },

        -- Snacks-indent
        SnacksIndent                      = { fg = theme.ui.whitespace },
        -- SnacksIndentScope = { fg = theme.ui.special },

        -- Snacks-picker
        -- Snacks will, by default, dim the window behind the picker. So we
        -- don't really need to use a darker background, which can also look a
        -- bit _too_ different when it's showing normal code in the preview
        -- window
        SnacksPicker                      = { bg = theme.ui.bg },
        SnacksPickerBorder                = { bg = theme.ui.bg },
        SnacksPickerTitle                 = { bg = theme.ui.bg, fg = theme.ui.special, bold = true },
        SnacksPickerListCursorLine        = { bg = theme.ui.bg_p2 },
        SnacksPickerPreviewCursorLine     = { bg = theme.ui.bg_p2 },

        -- Nvim-Navic
        NavicIconsFile                    = { link = "Directory" },
        NavicIconsModule                  = { link = "TSInclude" },
        NavicIconsNamespace               = { link = "TSInclude" },
        NavicIconsPackage                 = { link = "TSInclude" },
        NavicIconsClass                   = { link = "Structure" },
        NavicIconsMethod                  = { link = "Function" },
        NavicIconsProperty                = { link = "TSProperty" },
        NavicIconsField                   = { link = "TSField" },
        NavicIconsConstructor             = { link = "@constructor" },
        NavicIconsEnum                    = { link = "Identifier" },
        NavicIconsInterface               = { link = "Type" },
        NavicIconsFunction                = { link = "Function" },
        NavicIconsVariable                = { link = "@variable" },
        NavicIconsConstant                = { link = "Constant" },
        NavicIconsString                  = { link = "String" },
        NavicIconsNumber                  = { link = "Number" },
        NavicIconsBoolean                 = { link = "Boolean" },
        NavicIconsArray                   = { link = "Type" },
        NavicIconsObject                  = { link = "Type" },
        NavicIconsKey                     = { link = "Keyword" },
        NavicIconsNull                    = { link = "Type" },
        NavicIconsEnumMember              = { link = "TSField" },
        NavicIconsStruct                  = { link = "Structure" },
        NavicIconsEvent                   = { link = "Structure" },
        NavicIconsOperator                = { link = "Operator" },
        NavicIconsTypeParameter           = { link = "Identifier" },
        NavicText                         = { fg = theme.ui.fg },
        NavicSeparator                    = { fg = theme.ui.fg },
    }
end

return M
