-- lx-bundle:true

--- Live theme colors and measurements for tabular previews
-- @module plugins.tabpreview.design

local style = require("core.style")

local design = {
	typography = {
		font_size = 14,
		line_height_scale = 1,
	},
	document = {
		minimum_content_width = 80,
		padding_horizontal = 18,
		padding_vertical = 14,
	},
	table = {
		cell_padding_horizontal = 10,
		cell_padding_vertical = 5,
		minimum_column_width = 72,
		minimum_row_number_width = 46,
		frame_width = 1,
		frame_opacity = 0.48,
		inner_line_opacity = 0.18,
		alternate_row_opacity = 0.035,
	},
	-- Shared painter reads these values before it inspects individual runs
	code_spans = {
		padding_vertical = 0,
	},
	links = {
		underline_width = 1,
		underline_offset = 2,
	},
}

--- Return the live document background
-- @return table color
function design.get_document_background_color()
	return style.background
end

--- Resolve one optional syntax role to its live foreground color
-- @param syntax_type string|nil optional live color role
-- @return table color
function design.get_text_color(syntax_type)
	local syntax_style = syntax_type and style.syntax and style.syntax[syntax_type]

	if type(syntax_style) == "table" and (syntax_style.fg or syntax_style.bg) then
		return syntax_style.fg or style.text
	end

	return syntax_style or style.text
end

--- Return the live link color required by the shared painter
-- @return table color
function design.get_link_color()
	return style.accent or style.text
end

--- Return the row and column header background
-- @return table color
function design.get_table_header_background_color()
	return style.background2 or style.line_highlight or style.background
end

--- Return a subtle alternating data-row background
-- @return table color
function design.get_table_alternate_background_color()
	return style.transparent(style.text, design.table.alternate_row_opacity)
end

--- Return the outer grid color
-- @return table color
function design.get_table_frame_color()
	return style.transparent(style.text, design.table.frame_opacity)
end

--- Return the inner grid color
-- @return table color
function design.get_table_inner_line_color()
	return style.transparent(style.text, design.table.inner_line_opacity)
end

--- Return scaled grid-line thickness
-- @return number width
function design.get_table_frame_width()
	return math.max(1, design.table.frame_width * (SCALE or 1))
end

--- Return an error-tinted background for recoverable parser diagnostics
-- @return table color
function design.get_error_block_background_color()
	return style.transparent(style.error or style.text, 0.12)
end

--- Return the live error text color
-- @return table color
function design.get_error_block_text_color()
	return style.error or style.text
end

return design
