-- lx-bundle:true

-- Default UI colors and semantic non-syntax style values

local common = require("core.common")
local colors = {}

function colors.apply(style)
	style.root = {
		-- Keep root empty-view text readable against root background
		fg = common.color("#97979c"),
		bg = common.color("#2e2e32"),
	}
	style.background = common.color("#2e2e32")
	style.background2 = common.color("#252529")
	style.background3 = common.color("#252529")
	style.text = common.color("#97979c")
	style.input = style.input or style.text
	style.prompt = style.prompt or style.text
	style.cursor = common.color("#93DDFA")
	style.accent = common.color("#e1e1e6")
	style.dim = common.color("#424247")
	style.divider = common.color("#202024")
	style.outline = style.outline or style.divider
	style.selection = common.color("#48484f")

	-- Find match highlights use the general selection palette by default
	style.candidate = style.candidate or style.selection
	style.match = style.match or {
		fg = style.text,
		bg = nil,
	}
	style.word_highlight = style.word_highlight or style.candidate

	-- Keep header and gutter defaults with the rest of the shared UI palette
	style.headerbar_background = style.headerbar_background or style.background2
	style.headerbar_text = style.headerbar_text or style.dim
	style.gridlock_changed_line = style.gridlock_changed_line or style.accent
	style.line_number = common.color("#525259")
	style.line_number2 = common.color("#83838f")
	style.line_highlight = common.color("#343438")
	style.scrollbar = common.color("#414146")
	style.scrollbar2 = common.color("#4b4b52")
	style.gridlock_eol = common.color("#2b2b30")
	style.gridlock_text = common.color("#3a3a41")
	style.eol = common.color("#bacc55")

	-- Keep semantic status colors outside syntax so other UI can reuse them
	style.error = style.error or common.color("#ff0000")
	style.deleted = style.deleted or style.error
	style.success = style.success or common.color("#1ff583")
	style.warning = style.warning or common.color("#f2b94b")
	style.notice = style.notice or common.color("#5bb6ff")
	style.remark = style.remark or common.color("#a7aab3")
	style.changed = style.changed or common.color("#f2d84b")
	style.added = style.added or common.color("#54c56f")
	style.removed = style.removed or common.color("#e06c75")

	-- Keep Lite XL compatibility aliases grouped with the base palette values
	style.normal = style.normal or style.text
	style.warn = style.warn or style.warning or style.error

	--- Default syntax colors
	local syntax = {
		normal = common.color("#e1e1e6"),
		symbol = common.color("#e1e1e6"),
		comment = common.color("#676b6f"),
		comment2 = common.color("#376b6f"),
		keyword = common.color("#E58AC9"),
		keyword2 = common.color("#F77483"),
		number = common.color("#FFA94D"),
		hex = common.color("#FFA94D"),
		literal = common.color("#FFA94D"),
		string = common.color("#f7c95c"),
		operator = common.color("#93DDFA"),
		["function"] = common.color("#93DDFA"),
		variable = common.color("#e1e1e6"),
		constant = common.color("#c7e0e6"),
		control = common.color("#ffd289"),
		exception = common.color("#ffd289"),
		date = common.color("#ffffff"),
		time = common.color("#ffffff"),
		value = common.color("#ffffff"),
		bold = common.color("#FFFFFF"),
		bold_italic = common.color("#FFFFFF"),
		heading = common.color("#E58AC9"),
		quote = common.color("#FFFF00"),
	}
	-- Token aliases and semantic fallbacks
	syntax.unit = syntax.normal
	syntax.key = syntax.normal
	syntax.object = syntax["function"]
	syntax.array = syntax["function"]
	syntax.meta = syntax.keyword2
	syntax.label = syntax.normal
	syntax.italic = style.normal
	syntax.error = style.error or syntax.normal
	syntax.success = style.success or syntax.normal
	syntax.warning = style.warning or syntax.normal
	syntax.notice = style.notice or syntax.normal
	syntax.remark = style.remark or syntax.comment
	syntax.changed = style.changed or syntax.normal
	syntax.added = style.added or syntax.normal
	syntax.removed = style.removed or syntax.normal
	syntax.separator = style.line_number2 or syntax.normal
	syntax.preprocessor = syntax.normal

	-- Active indent guide color
	style.guide_active = style.guide_active or syntax["function"]

	style.syntax = syntax
end

return colors
