-- lx-bundle:true

--- Markdown reference adapter used while core preview parts are extracted
-- @module plugins.mdpreview2.view

local PreviewView = require("core.preview.view")
local markdown_design = require("plugins.mdpreview.design")
local markdown_images = require("plugins.mdpreview.images")
local markdown_math = require("plugins.mdpreview.math")
local markdown_tables = require("plugins.mdpreview.tables")
local MarkdownPreview = require("plugins.mdpreview.view")

local MarkdownPreview2 = PreviewView:extend()

-- Retain reference behavior only for Markdown parts not moved into core yet
for name, member in pairs(MarkdownPreview) do
	if type(member) == "function" and name:sub(1, 2) ~= "__" then
		MarkdownPreview2[name] = member
	end
end

MarkdownPreview2.is_markdown_preview = true	-- Keep normal Markdown commands and key bindings
MarkdownPreview2.is_markdown_preview2 = true	-- Let tests and developers identify the opt-in view
MarkdownPreview2.preview_line_height_scale =
	markdown_design.typography.line_height_scale	-- Keep extracted row geometry identical
MarkdownPreview2.preview_design = markdown_design	-- Supply colors and logical measurements
MarkdownPreview2.preview_table_renderer = markdown_tables	-- Draw Markdown table decorations
MarkdownPreview2.preview_image_renderer = markdown_images	-- Draw resolved Markdown image blocks
MarkdownPreview2.preview_math_renderer = markdown_math	-- Draw MaLxTeX boxes stored in runs

-- Core methods replace reference methods copied by the temporary Markdown adapter
for _, name in ipairs({
	"add_layout_row",
	"get_first_visible_layout_row",
	"get_visible_source_line",
	"capture_layout_anchor",
	"restore_layout_anchor",
	"draw_code_block_background",
	"draw_document",
}) do
	MarkdownPreview2[name] = PreviewView[name]
end

return MarkdownPreview2
