Module:ItemsNav

local p = {} local data = mw.loadData("Module:Menu Maps/Data") local tab2 = require("Module:Tab2") local terminology = require("Module:Term") local utilsError = require("Module:UtilsError") local utilsTable = require("Module:UtilsTable") local validate = require("Module:ArgsUtil").validate

function p.Main(frame) local args = frame:getParent.args return p.main({		game = args[1],		type = args[2],	}) end

local validators = { type = { required = true, values = utilsTable.keys(data) },	game = { required = true, values = function(args) return utilsTable.keys(data[args.type]) end } }

function p.main(args) local err = validate(args, validators) if err then utilsError.logWarnings(err) return utilsError.printErrorCategories(utilsError.INVALID_TEMPLATE_ARGUMENTS) end local config = data[args.type][args.game] local maps = p.createMenuMaps(config, args.game) return maps end

function p.createMenuMaps(config, game) if #config == 1 and not tabs[1].tabName then return p.createMenuMap(config[1], game) end local tabs = {} for i, v in pairs(config) do		local tab, terms = p.createMenuMap(v, game) table.insert(tabs, {			tabName = v.tab,			tabContent = tab,		}) local hasCurrentPage = utilsTable.hash(terms)[mw.title.getCurrentTitle.text] defaultTab = hasCurrentPage and i	end defaultTab = default or 1 return tab2.Main(tabs, defaultTab, "top", nil, nil, nil, nil, "center") end

function p.createMenuMap(config, game) local imagemap, pages = p.createImageMap(game, config.image, config.areas) local stateControls = mw.html.create("div") :addClass("state-container__controls") :css({			["display"] = "flex",			["flex-direction"] = "column",		}) :tag("div") :addClass("state-container__forward") :wikitext("") :done :tag("div") :addClass("state-container__back") :wikitext("") :done local html = mw.html.create("div") :addClass('state-container') :attr("states", 3) :css({			["display"] = "flex",			["justify-content"] = "center",			["align-items"] = "center",		}) :tag("div") :addClass("state-container__state") :wikitext(imagemap) :done :tag("div") :addClass("state-container__state") :css("display", "none") :wikitext("state 2") :done :tag("div") :addClass("state-container__state") :css("display", "none") :wikitext("state 3") :done :node(stateControls) return tostring(html), pages end

function p.createImageMap(game, image, areas) local lines = { image } local pages = {} for _, area in ipairs(areas) do		local page = area.page local row = terminology.fetchRow({ term = page, game = game }) local link = ("%s"):format(page, row.term or page) table.insert(pages, page) table.insert(lines, area.area .. link) end table.insert(lines, " desc none") local imagemap = mw.getCurrentFrame:extensionTag("imagemap", table.concat(lines, "\n")) return imagemap, pages end

return p