Documentation for this module may be created at Module:ItemSlot/doc

local p = {}

function p.render(frame)
  local args = frame:getParent().args
  local itemParam = args.item or ""
  local tooltipParam = args.tooltip

  local output = {}

  -- Split items by comma
  for filename in string.gmatch(itemParam, '([^,]+)') do
    filename = filename:gsub("^%s*(.-)%s*$", "%1") -- trim spaces

    if not filename:lower():match("%.png$") then
      filename = filename .. ".png"
    end

    local imgTag
    if args.link and args.link ~= "" then
      imgTag = string.format('[[File:%s|link=%s]]', filename, args.link)
    else
      imgTag = string.format('[[File:%s]]', filename)
    end
    table.insert(output, imgTag)
  end

  local result = table.concat(output, "")

  local tooltipText = tooltipParam
  if not tooltipText or tooltipText == "" then
    tooltipText = itemParam
  end

  if tooltipText ~= "" then
    result = result .. '<span class="item-tooltip">' .. tooltipText .. '</span>'
  end

  return '<div class="item-slot-container"><div class="item-slot">' .. result .. '</div></div>'
end

return p