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

local classes = { stateContainer = "state-container", state = "state-container__state", defaultState = "state-container__state state-container__state--active", stateForward = "state-control state-control-forward", stateBack = "state-control state-control-back state-control--disabled", }

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") :css({			["display"] = "flex",			["flex-direction"] = "column",		}) :tag("div") :addClass(classes.stateForward) :wikitext("") :done :tag("div") :addClass(classes.stateBack) :wikitext("") :done local states = mw.html.create("div") :tag("div") :addClass(classes.defaultState) :wikitext(imagemap) :done :tag("div") :addClass(classes.state) :wikitext("state 2") :done :tag("div") :addClass(classes.state) :wikitext("state 3") :done local html = mw.html.create("div") :addClass(classes.stateContainer) :css({			["display"] = "flex",			["justify-content"] = "center",			["align-items"] = "center",		}) :node(states) :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