local BASE_URL = "http://wiki.esoui.com"

--- Quickhelp Documentation (ctrl-Q)
-- This is called when the user invokes quick help via ctrl-q, or by
-- having the quickhelp panel open and set to autolookup
-- @param name The name to get documentation for.
-- @return the documentation as an HTML or plain text string
function getDocumentation(name)
    -- Use for development
    -- disableCache()
    -- log(name)
	local data = fetchURL(getDocumentationUrl(name))

    local contentTag = [[<div id=['"]content['"]>]]
    local footerTag = [[<div id=['"]footer['"]>]]

    local contentPos = data:find(contentTag);
    local footerPos = data:find(footerTag);

    data = data:sub(contentPos, footerPos)

    data =  data:gsub([[href="]], [[href="]]..BASE_URL)

    data = "<html><h3>" .. name .. "</h3>" .. data .. "<br><br><b>[data provided by esoui]</b></html>"

    return data
end

--- External Documentation URL (shift-F1)
-- This is called by shift-F1 on the symbol, or by the
-- external documentation button on the quick help panel
-- @param name The name to get documentation for.
-- @return the URL of the external documentation
function getDocumentationUrl(name)
	local p1, p2 = string.match(name, "(%a+)\.?(%a*)")
	--local url = BASE_URL .. "/docs/api/" .. p1
	--They don't have urls for pages yet, so go to the base page
	local url = BASE_URL

	if p2 then url = url .. p2 end

	return url
end


--- Quick Navigation Tooltip Text, (ctrl-hover on symbol)
-- This is called when the user ctrl-hovers over a symbol
-- @param name The name to get documentation for.
-- @return the documentation as a plain text string
function getQuickNavigateDocumentation(name)
	local sig = SIGNATURES[name]
	if not sig then return end

	return "[EsoUI]\r\n " .. sig
end