-function prettyDate(dateString){
  //if it's already a date object and not a string you don't need this line:
  -var date = new Date(dateString);
  -var d = date.getDate();
  -var monthNames = [ "Gen", "Feb", "Mar", "Apr", "Mag", "Giu", "Lug", "Ago", "Set", "Ott", "Nov", "Dic" ];
  -var monthDays = ["Domenica", "Lunedì", "Martedì", "Mercoledì", "Giovedì", "Venerdì", "Sabato"];
  -var m = monthNames[date.getMonth()];
  -var y = date.getFullYear();
  -var day = monthDays[date.getDay()];
  -return day+ ' '+d+' '+m+' '+y;
-}

- var urlcal = baseurl + '/calendario-eventi/'
- var imginstagram = baseurl + '/images/images/footer-instagram-icon.png'
- var imgtwitter = baseurl + '/images/images/footer-twitter-icon.png'
- var imgyoutube = baseurl + '/images/images/footer-youtube-icon.png'
- var imgfb = baseurl + '/images/images/footer-facebook-icon.png'
- var baseimg = baseurl + '/'
doctype html
html
  head
    meta(charset="utf-8")
    meta(name="viewport", content="width=device-width, initial-scale=1")
    title= dataemail.title || "Email"
    style.
      /* embedded CSS */
      body { margin:0; padding:0; background:#E9F2F9; font-family:Tahoma, Geneva, sans-serif; color:#5b656e; }
      a { color:#09c; text-decoration:none; }
      table, td { border-collapse:collapse; }
      h1,h2,h3,p { margin:0; padding:0; }

      .logoContainer { text-align:center; padding:20px 0; }
      .logoContainer img { max-width:200px; }

      .testomail { padding:10px; font-size:0.75rem; line-height:1.4; }

      .clpromo {
        background-color:orange;
        text-align:center;
        font-size:1rem;
        padding:10px;
        color:#fff;
        font-weight:bold;
      }

      .emailContainer {
        background:#fff;
        border-radius:10px;
        padding:20px;
        margin:20px auto;
      }

      .sectionArticleImage img {
        max-width:150px;
        border:1px solid #ccc;
        display:block;
        margin-bottom:10px;
      }

      .teacher {
        font-style:italic;
        font-size:0.75rem;
        color:#555;
      }

      .contrib {
        font-size:0.75rem;
        font-weight:bold;
        color:#333;
      }

      .button a {
        display:inline-block;
        padding:10px 20px;
        background:#f75666;
        color:#fff !important;
        text-decoration:none;
        border-radius:10px;
        font-size:13px;
      }

      .button2 a {
        display:block;
        padding:12px 20px;
        background:#0000ff;
        color:#fff !important;
        text-decoration:none;
        border-radius:10px;
        font-size:1.15rem;
      }

      .center_img img {
        display:block;
        margin:0 auto;
      }

      .discContainer {
        background:#fff;
        border-radius:10px;
        padding:20px;
        margin:20px auto;
      }

      .LinkDisc a {
        text-decoration:none;
      }

      .pDisc:hover {
        background:#5c8ef4 !important;
        color:#fff !important;
      }

      .pDisc {
        padding:5px 10px;
        border-radius:10px;
        display:inline-block;
      }

      .socialMedia {
        background:#8bafcb;
        text-align:center;
        padding:10px 0;
      }

      .socialMedia img {
        width:29px;
        height:auto;
        border:0;
      }

      .firma-container {
        background:#ffffff;
        padding:15px;
        text-align:center;
        border-top:1px solid #e0e0e0;
        font-size:0.85rem;
        color:#313a42;
      }

      .disclaimer-container {
        background:#f9f9f9;
        padding:15px;
        text-align:center;
        font-size:0.75rem;
        color:#666;
        border-top:1px solid #eee;
        border-bottom:1px solid #eee;
      }

      .bottom-container {
        background:#e9f2f9;
        padding:15px;
        text-align:center;
        font-size:0.7rem;
        color:#999;
      }

      .whitespace {
      }

      @media only screen and (max-width:480px) {
        .button a, .button2 a {
          font-size:1rem !important;
          width:100%;
        }
        .sectionArticleImage,
        .column {
          width:100% !important;
          display:block !important;
        }
      }
  body(yahoofix)
    span#body_style(style='display:block')
      // Header
      table(width="100%", cellpadding="0", cellspacing="0", align="center")
        tr
          td.logoContainer
            a(href=baseurl)
              img.logo(src=baseurl+"/images/logo.png", alt="Logo")

        if dataemail.templ.testoheadermail_out
          tr
            td.testomail
              p!= dataemail.templ.testoheadermail_out

        if dataemail.templ.options.includes('SHOW_PROMO')
          tr
            td.clpromo
              p!= dataemail.textpromo

        // Main Content
        if dataemail.templ.content
          tr
            td.emailContainer
              p!=dataemail.templ.content
              if dataemail.templ.img
                img(src=baseimg + dataemail.templ.img, class="center_img")
              if dataemail.templ.content2
                p!=dataemail.templ.content2
                if dataemail.templ.img2
                  img(src=baseimg + dataemail.templ.img2, class="center_img")

        // Events
        if dataemail.templ.options.includes('SHOW_EVENTS')
          each event in arrevents
            tr
              td.emailContainer
                table(width="100%", cellpadding="0", cellspacing="0")
                  tr
                    td.column.sectionArticleImage(width="150")
                      if event.news
                        p.q-chip.bg-red.text-white Novità
                      img(src=baseimg + (event.img_small || event.img), alt=event.title)
                      p.teacher= event.op1[0].name + ' ' + event.op1[0].surname
                    td.column
                      h2.sectionContentTitle= event.title
                      p.sectionContentSubTitle= prettyDate(event.dateTimeStart)
                      p.sectionContent!= event.details
                      if event.contrib.length
                        p.contrib= event.contrib[0].label + (event.contrib[0].showprice ? ' ' + event.price + ' €' : '')
                      table.buttonContainer
                        tr
                          td.button
                            a(href=baseurl + '/event/' + event.typol + '?eventid=' + event._id, target="_blank") Apri l'Evento

          tr
            td.center_img
              a.button2(href=urlcal, target="_blank") Calendario Eventi

        // Disciplines
        if dataemail.templ.options.includes('SHOW_DISC')
          tr
            td.center
              h2.cltitle_disc= dataemail.disc_title
          each disc in dataemail.arrdiscipline
            tr
              td.discContainer
                table(width="100%", cellpadding="0", cellspacing="0")
                  tr
                    td.column.sectionArticleImage(width="150")
                      img(src=baseimg + (disc.img_small || disc.img), alt=disc.label)
                    td.column
                      p.LinkDisc
                        a(href=baseurl + disc.linkpage, target="_blank")
                          span.pDisc(style=`background-color:`+disc.color)= disc.label
                      p.sectionContent!= disc.description

        // Additional Content
        if dataemail.content_after_events
          tr
            td.testomail
              p!=dataemail.content_after_events

        // Social Media
        tr
          td.socialMedia
            table(width="120", align="center", cellpadding="0", cellspacing="0")
              if dataemail.urlinstagram
                td
                  a(href=dataemail.urlinstagram)
                    img(src=imginstagram, alt="Instagram")
              if dataemail.urltwitter
                td
                  a(href=dataemail.urltwitter)
                    img(src=imgtwitter, alt="Twitter")
              if dataemail.urlfb
                td
                  a(href=dataemail.urlfb)
                    img(src=imgfb, alt="Facebook")
              if dataemail.urlyoutube
                td
                  a(href=dataemail.urlyoutube)
                    img(src=imgyoutube, alt="YouTube")

        // Footer
        tr
          td.firma-container
            p!= dataemail.firma
        tr
          td.disclaimer-container
            p!= dataemail.disclaimer_out
        tr
          td.bottom-container
            p!= dataemail.disc_bottom_out