local localdata = require 'Módulo:Infobox/Localdata'
local general = require 'Módulo:Infobox/Funções'
local person = require 'Módulo:Infobox/Funções/Pessoa'
local wikidata = require 'Módulo:Infobox/Wikidata'
local linguistic = require 'Módulo:Linguística'
local convert = require 'Módulo:Conversão'

function country()
    local function formatCountry(country)
        if not country then
            return nil
        end
        local countrymodule = require "Módulo:Country data"
        local val, success = countrymodule.standarddisplay(country) -- val = nil se o país não for reconhecido
        if success then
            return val
        end
    end

    return  {
        type = 'mixed',
        label = 'País',
        value = function() return formatCountry(localdata['país']) or localdata['pais'] end,
        wikidata = {
            property = 'P457',
            conjtype = 'new line',
            displayformat = function(snak)
                local id = wd.getId(snak)
                return formatCountry(id) or wd.formatSnak(snak)
            end
        }
    }
end

local function resumo()
    local pais = function(localdata)
                return localdata['país'] .. '<br />'
        end
        local ano = function(localdata)
                return localdata['ano']
        end
        local corpb = function(localdata)
                  return localdata['cor-pb']
        end
        local duracao = function(localdata)
            return localdata['duração']
        end
    if pais then
              val = pais
    end
    if ano then
            val = val .. ano
    end
    if corpb then
           val = val .. corpb
    end
    if duracao then
           val = val .. duracao
    end
    return val
end

local function italics(query)
    local val = wikidata.formatAndCat(query)
    if val then
        return '<i>' .. val .. '</i>'
    end
end

return
    {
    maincolor = '09C8BD',
    secondcolor = '5CF8F0',
    parts =
        {
        general.title( 'cinema'),
            {type = 'table', rows = {
                          {type = 'text', value = 'título-or', wikidata = function ( item )
            return italics({entity = item, property = 'P1448', conjtype = 'new line' , showlang = true }) end},
            {type = 'text', value = 'título-pt', wikidata = function ( item )
            return italics({entity = item }) end},
                    {type = 'text', value = 'título-br', wikidata = function ( item )
            return italics({entity = item }) end},
           
                {type = 'text', value = {'nome_nativo', 'nome_nativo_ling'}, wikidata = function ( item )
            return italics({property = 'P1705', showlang = true, conjtype = 'new line'})
            end }
        }},
        general.mainimage{
            cat = '!Artigos sem imagens',
            defaultimage = 'Padrao 2.svg',
            wikidata = {property = {'P3383', 'P2716', 'P18', 'P10'}, numval = 1}, upright = 1
            },
   
        {type = 'table', title = 'Informações gerais', rows = {
                        {type = 'row', label = function ( localdata )
                    return localdata['título-outros-nome'] or localdata['título-outros-nome1'] or 'Em outro países'
                    end, value = {'título-outros', 'título-outros-nome1'}},
                    {type = 'row', label = function ( localdata )
                    return localdata['título-outros-nome2']
                    end, value = 'título-outros2'},
                    {type = 'row', label = function ( localdata )
                    return localdata['título-outros-nome3']
                    end, value = 'título-outros3'},
                    {type = 'row', label = function ( localdata )
                    return localdata['título-outros-nome4']
                    end, value = 'título-outros-nome4'},
            {type = 'row', label = function ( localdata )
                return localdata['título-outros-nome5']
                    end, value = 'título-outros-nome5'},
            {type = 'row', label = 'Tipo', value = 'type' , plurallabel = 'Tipos', wikidata = {property = 'P31' , excludevalues = 'Q11424,Q24869'}},
            {type = 'row', label = 'Título original', value = 'título original', plurallabel = 'Títulos originais' , wikidata = function ( item )
            return italics({entity = item, property = 'P1476', conjtype = 'new line' , showlang = true })--encontre uma maneira de remover quando o título original estiver em português
            end
            },
            {type = 'row', label = 'Data de produção', value = 'datas de produção', plurallabel = 'Datas de lançamento' , wikidata = {property = 'P571' , sorttype = 'chronological' , numval = 1 }},
            {type = 'row', label = 'Data de lançamento', value = 'lançamento', plurallabel = 'Datas de lançamento' , wikidata = {property = 'P577' , conjtype = 'new line' , sorttype = 'chronological' , showqualifiers = 'P291,P276' }},
            {type = 'row', label = 'Difusor', value = 'difusor', plurallabel = 'Difusores' , property = 'P449'},
            {type = 'row', label = 'Duração', value = 'duração', plurallabel = 'Duracões' , wikidata = {property = 'P2047' , showunit = 'long' }},
            {type = 'row', label = 'Língua', value = 'língua original' , plurallabel = 'Línguas', property = 'P364'},
            {type = 'row', label = 'Genéro', value = 'genéro' , plurallabel = 'Genéros', property = 'P136'},
            {type = 'row', label = 'Formato', value = 'formato' , plurallabel = 'Formatos', wikidata = {property = 'P462' , excludevalues = 'Q22006653'}},
            {type = 'row', label = 'Baseado em', value = {'baseado em', 'inspiração'},  wikidata = function ( item )
            return italics({entity = item, property = 'P144'})
            end },
            {type = 'row', label = 'Tema', value = 'tema' , plurallabel = 'Temas', property = 'P921'},
            {type = 'row', label = 'País', value = 'país de origem' , property = 'P495'}, -- Seria bom mostrar a bandeira antes do país. Talvez por ser capaz de formatar a propriedade também: {{property}}.
            {type = 'row', label = 'Local de filmagem', value = 'local de filmagem' , plurallabel = 'locais de filmagem' , property = 'P915'},
            --{type = 'row', label = 'Formato', value = 'formato', plurallabel = 'Formatos' , property = 'P3803'}, plus détaillé que nécessaire pour l'infobox
            general.website
        }},
        {type = 'table', title = 'Equipa de filmagem', rows = {
            {type = 'row', label = 'Cenário', value = 'cenário', property = 'P58'},
            {type = 'row', label = 'Produção', value = {'produção', 'produtor'}, property = 'P272,P162'},
            {type = 'row', label = 'Produção executiva', value = {'produção_executiva', 'produtor_executivo', 'produtor executivo', 'produção executivo'}, property = 'P1431'},
            {type = 'row', label = 'Artista de storyboard', value ={'argumento', 'guião'}, property = 'P3275'},
            {type = 'row', label = 'Direção de arte', value = 'direção de arte', property = 'P2554'},
            {type = 'row', label = 'Figurino', value = 'figurino', property = 'P2515'},
            {type = 'row', label = 'Direção', value = {'direção', 'diretor'}, property = 'P57'},
            {type = 'row', label = 'Direção de fotografia', value = {'diretor_fotografia','diretor_de_fotografia','diretor de fotografia', 'direção de fotografia'}, property = 'P344'},
            {type = 'row', label = 'Protagonistas', value = {'protagonistas', 'elenco'}, wikidata = {property = 'P161' , conjtype = 'new line' , numval = 10}}, --problématique. Il y a souvent plus de 10 valeurs et les 10 premières ne sont pas nécessairement représentatives du poids dans l'oeuvre. Il faudrait une fonction qui place les 5 premiers noms par ordre décroissant d'interwikis existants (le plus grand nombre d'interwikis = les plus gros noms = les principaux remarqués) et place le reste en liste déroulante semblable à celle des distinctions. )
            {type = 'row', label = 'Gênero', value = 'gênero', property = 'P136'},
            {type = 'row', label = 'Género', value = 'género'}, -- maneira de mostrar label conforme lang
            {type = 'row', label = 'Música', value = 'música', property = 'P86'},
            {type = 'row', label = 'Editor filmográfico', value = 'montagem', property = 'P1040'},
           
        }},
        {type = 'table', title = 'Economia', rows = {
            {type = 'row', label = 'Custo', value = {'custo', 'orçamento'}, plurallabel = 'Custos', property = 'P2130'},
            {type = 'row', label = '[[Box-office]]', value = 'box-office' , wikidata = {property = 'P2142' , showunit = 'short'}},
            person.awards(),
--            {type = 'row', label = 'Prêmios recebidos', value = 'prêmios' , property = 'P166'},
        }},
        {type = 'table', title = 'Sequência', rows = {
            {type = 'row', label = 'Série', value = 'série', plurallabel = 'Séries' , wikidata = function ( item )
                    return italics({entity = item, property = 'P179', conjtype = 'new line' , showlang = true })
                end
            },
            {type = 'row', label = 'Predido por' , value = 'precedido' , wikidata = function ( item )
                    return italics({entity = item, property = 'P155', conjtype = 'new line' , showlang = true })
                end
            },
            {type = 'row', label = 'Sucedido por' , value = 'sucedido por' ,wikidata = function ( item )
            return italics({entity = item, property = 'P156', conjtype = 'new line' , showlang = true })
                end
            },
        },
        }
    }
}