Module:Teste

From determinar.ia.br - Determine suas informações
Revision as of 11:14, 1 August 2026 by Determinaradmin (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local p = {}

function p.main(frame)
    local id = frame.args.ID or frame.args[1]
    local entity = mw.wikibase.getEntity(id)

    if not entity then
        return '<strong>Item não encontrado: ' .. tostring(id) .. '</strong>'
    end

    local label = entity:getLabel('pt-br') or entity:getLabel('pt') or entity:getLabel('en') or id
    local description = entity:getDescription('pt-br') or entity:getDescription('pt') or ''

    local html = mw.html.create('table')
        :addClass('infobox-medico')

    html:tag('tr')
        :tag('th'):attr('colspan', '2'):css('text-align', 'center'):wikitext(label)

    if description ~= '' then
        html:tag('tr')
            :tag('td'):attr('colspan', '2'):css('font-style', 'italic'):wikitext(description)
    end

    if entity.claims then
        for propertyId, claims in pairs(entity.claims) do
            local propLabel = mw.wikibase.label(propertyId) or propertyId
            local valores = {}

            for _, claim in ipairs(claims) do
                local snak = claim.mainsnak
                if snak and snak.datavalue then
                    local dv = snak.datavalue
                    local val

                    if dv.type == 'string' then
                        val = dv.value
                    elseif dv.type == 'monolingualtext' then
                        val = dv.value.text
                    elseif dv.type == 'wikibase-entityid' then
                        val = mw.wikibase.label(dv.value.id) or dv.value.id
                    elseif dv.type == 'quantity' then
                        val = dv.value.amount
                    elseif dv.type == 'time' then
                        val = dv.value.time
                    else
                        val = tostring(dv.value)
                    end

                    table.insert(valores, val)
                end
            end

            if #valores > 0 then
                local row = html:tag('tr')
                row:tag('th'):wikitext(propLabel)
                row:tag('td'):wikitext(table.concat(valores, ', '))
            end
        end
    end

    return tostring(html)
end

return p