#! /usr/bin/python3
# Last edited on 2019-08-09 22:17:37 by stolfilocal

from datetime import datetime, timezone

def pagina_de_entrada(data):
  cor_texto = "#000488"
  cor_fundo = "#fff844"
  cor_bloco = "#ffd844"
  cabe = cabecalho("Projeto MC857A 2019-2s - Teste")
  menu = menu_geral()
  info = elem_texto("<i>Data de Hoje</i><br/><b>" + data + "</b><br/>Figo","Courier","18px","5px","center",cor_texto,cor_fundo)
  meio = caixa(info,"50%","100px", 0.5,0.5, 0.5,0.5, cor_bloco)
  roda = rodape()
  return cabe + menu + meio + roda
  
def cabecalho(title):
  return \
    "<!doctype html>\n" + \
    "<html>\n" + \
    "<head>\n" + \
    "<meta charset=\"UTF-8\"/>\n" + \
    "<title>" + title + "</title>\n" + \
    "</head>\n" + \
    "<body style=\"bacground-color:'#eeeeee'\">\n" + \
    "<h1>" + title + "</h1>"
  
def rodape():
  nowraw = datetime.now(timezone.utc)
  nowfmt = nowraw.strftime("%Y-%m-%d %H:%M:%S %z")
  return \
    "<small><p>\n" + \
    "Page created on " + nowfmt + "\n" + \
    "</p></small>\n" + \
    "</body>\n" + \
    "</html>\n"
   
def menu_geral():
  return \
    "<nav>\n" + \
    "  " + botao_do_menu("Cique Aqui") + "\n" + \
    "  " + botao_do_menu("Não, Clique Aqui!") + "\n" + \
    "  " + botao_do_menu("Não Clique Aqui") + "\n" + \
    "</nav>"
   
def botao_do_menu(texto): 
  """Função interna: retorna HTML de um botão do menu."""
  fam_fonte = "Courier"
  tam_fonte = "18px"
  cor_fundo = "#fff888"
  return \
    "<span style=\"\n" + \
    "  display: inline-block;\n" + \
    "  font-family:" + fam_fonte + ";\n" + \
    "  font-size:" + tam_fonte + ";\n" + \
    "  padding: 5px;\n" + \
    "  background-color:" + cor_fundo + ";\n" + \
    "  text-align: center;\n" + \
    "\">\n" + \
    "  <button\n" + \
    "    type=\"button\"\n" + \
    "    onclick=\"alert('" + texto + "')\"\n" + \
    "  >" + texto + "</button>\n" + \
    "</span>"
 
def elem_texto(texto,fam_fonte,tam_fonte,pad,halign,cor_texto,cor_fundo):
  return \
    "<span style=\"\n" + \
    "  display: inline-block;\n" + \
    ( "  font-family:" + fam_fonte + ";\n" if fam_fonte != None else "") + \
    ( "  font-size:" + tam_fonte + ";\n" if tam_fonte != None else "") + \
    ( "  padding:" + pad + ";\n" if pad != None else "") + \
    ( "  background-color:" + cor_fundo + ";\n" if cor_fundo != None else "") + \
    ( "  text-color:" + cor_texto + ";\n" if cor_texto != None else "") + \
    ( "  text-align:" + halign + ";\n" if halign != None else "") + \
    "\">" + texto + "</span>"

def caixa(item,largura,altura,href,halign,vref,valign,cor_fundo):
  return \
    "<span style=\"\n" + \
    "  display: inline-block;\n" + \
    "  box-sizing: content-box;\n" + \
    "  position: absolute;\n" + \
    ( "  background-color: " + cor_fundo + ";\n" if cor_fundo != None else "" ) + \
    ( "  width: " + largura + ";\n" if largura != None else "" ) + \
    ( "  height: " + altura + ";\n" if altura != None else "" ) + \
    "  \">\n" + \
    "    <span style=\"\n" + \
    "    display: inline-block;\n" + \
    "    box-sizing: content-box;\n" + \
    "    position: relative;\n" + \
    "    left: " + ("%.2f" % (halign*100)) + "%;\n" + \
    "    top: " + ("%.2f" % ((1-valign)*100)) + "%;\n" + \
    "    transform: translate(" + ("%.2f" % (-href*100)) + "%," + ("%.2f" % (-(1-vref)*100)) + "%);\n" + \
    "    \">" + item + "</span>\n" + \
    "</span>"
