-- lx-bundle:true

-- This file is part of Lx, created by Liqube <www.liqube.com>
-- Copyright Liqube Audio. All rights reserved.
-- Lx Interim License. See LICENSE for details.

--- Write optional, friendly reports for Lx and add-on developers
-- @module core.dev.details

local core = require("core")
local config = require("core.config")

local details = {}

--- Return whether friendly developer reports are enabled
-- @return boolean enabled
function details.is_enabled()
	return type(config.dev) == "table"
		and config.dev.show_details == true
end

--- Toggle friendly developer reports for this session
-- @return boolean enabled
function details.toggle()
	if type(config.dev) ~= "table" then
		config.dev = {}
	end

	config.dev.show_details = not config.dev.show_details

	return config.dev.show_details
end

--- Add one compact report to the Log View when details are enabled
-- Empty lines are omitted so frequent reports stay easy to scan
-- @param title string short report title
-- @param lines table readable detail lines
-- @return boolean reported
function details.report(title, lines)
	if not details.is_enabled() then
		return false
	end

	local report = { tostring(title) .. ":" }
	for index = 1, #(lines or {}) do
		local line = lines[index]
		if type(line) == "string" and line ~= "" then
			-- Headings stay flush left while their values form one compact list
			report[#report + 1] = line:sub(-1) == ":" and line or " - " .. line
		end
	end
	local item = core.log_quiet("%s", table.concat(report, "\n"))
	if item then
		-- Friendly reports show feature decisions instead of their Lua callsite
		item.hide_source = true
	end

	return true
end

return details
