-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 + '/statics/images/images/footer-instagram-icon.png'
- var imgtwitter = baseurl + '/statics/images/images/footer-twitter-icon.png'
- var imgyoutube = baseurl + '/statics/images/images/footer-youtube-icon.png'
- var imgfb = baseurl + '/statics/images/images/footer-facebook-icon.png'
- var baseimg = baseurl + '/statics/'
doctype html
html
  head
    title Calendario Eventi

    //- import css/scss stylesheets
    //- these file names will be replace by gulp with proper css file paths
    link(rel="stylesheet", href="../sass/basic.scss")
    link(rel="stylesheet", href="../sass/one/styles.scss")

    //- embdedded css allowed, but not sass
    style.
      .red {
        background-color: #E84C50;
      }

      .full-width {
        width: 100%;
      }
  body(yahoofix)
    span(id='body_style', style='display:block')
      table(class="preheader", cellpadding="0", cellspacing="0", width="100%")
        tr
          td.webversion
            p non vedi le immagini?&nbsp;
              a(href=urlcal) Apri il Calendario

      table(class="topHeader", cellpadding="0", cellspacing="0", width="100%")
        tr
          td
            table(cellpadding="0", cellspacing="0", align="center", summary="")
              tr
                td.logoContainer
                  a(href=baseurl, title='logo')
                    img.logo(src=baseurl+"/statics/images/logo.png", height=dataemail.height_logo)

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

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

      - if (dataemail.templ.content)
        table(cellpadding="0", cellspacing="0", width="95%", align="center")
          tr
            td(class="textIniContainer", valign="top")
              p!=dataemail.templ.content
              - if (dataemail.templ.img)
                img(src=baseimg + dataemail.templ.img, alt="", class="myimg")
              - if (dataemail.templ.content2)
                p!=dataemail.templ.content2
                  - if (dataemail.templ.img2)
                    img(src=baseimg + dataemail.templ.img2, alt="", class="myimg")

      table(cellpadding="0", cellspacing="0", width="640", align="center")
        - if (dataemail.templ.options.includes('SHOW_EVENTS'))
          tr
            td(class="whitespace", height="10")
              p &nbsp;
          tr
            td(class="emailContainer", valign="top")

              each event in arrevents
                - var urlevent = baseurl + '/event/' + event.typol + '?eventid=' + event._id
                - var imgev = event.img_small
                - var mydate = prettyDate(event.dateTimeStart)
                unless (imgev)
                  - imgev = event.img
                - var teacher1 = ''
                - var teacher2 = ''
                - var teacher3 = ''
                - var teacher4 = ''
                - var contrib = ''
                - var myclteach = 'q-chip'
                - if (event.op1[0] && event.op1[0].username !== 'nessuno')
                  - teacher1 = event.op1[0].name + ' ' + event.op1[0].surname
                - if ((event.op2[0] && event.op2[0].username !== 'nessuno'))
                  - teacher2 = event.op2[0].name + ' ' + event.op2[0].surname
                  - myclteach = 'q-chip2'
                - if (event.op3[0] && event.op3[0].username !== 'nessuno')
                  - teacher3 = "<br>" . event.op3[0].name + ' ' + event.op3[0].surname
                - if (event.op4[0] && event.op4[0].username !== 'nessuno')
                  - teacher4 = "<br>" . event.op4[0].name + ' ' + event.op4[0].surname

                - if (event.contrib[0])
                  - contrib = event.contrib[0].label
                  - if (event.contrib[0].showprice)
                    - contrib += ' ' + event.price + ' €'


                table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
                  tr
                    td(class="column sectionArticleImage", valign="top")
                      table(cellpadding="0", cellspacing="0", summary="", border="0")
                        - if (event.news)
                          tr
                            td
                              p(class="q-chip row inline no-wrap items-center cltexth5 chipnews shadow-5 glossy text-right bg-red text-white") Novità
                        tr
                          td
                            img(src=baseimg + imgev, alt="", width="150")
                            p(class="teacher") #{teacher1} <br> #{teacher2} #{teacher3} #{teacher4}
                    td(class="column", valign="top")

                      table(cellpadding="0", cellspacing="0", summary="", border="0")
                        tr
                          td(class="sectionContentTitle boldhigh", valign="top")
                            p #{event.title}
                        tr
                          td(class="sectionContentSubTitle", valign="top")
                            p(class="q-chip row inline no-wrap items-center cltexth5 chipnews shadow-5 glossy text-right bg-blue text-white")  #{mydate}
                        tr
                          td(class="sectionContent", valign="top")
                            p!= event.details
                            p.contrib= contrib
                        tr
                          td(class="buttonContainer")
                            table(width="50%", cellpadding="0", cellspacing="0", summary="", border="0")
                              tr
                                td(class="button hoverLink")
                                  a(href=urlevent, title='Evento', target='_blank') Apri l'Evento

            tr
              table(cellpadding="0", cellspacing="0", summary="", border="0", align="center", class="")
                tr
                  td(class="whitespace", height="10")
                    p &nbsp;
                tr
                  td.center_img(class="button2 hoverLink")
                    a(href=urlcal, title='Calendario Eventi', target='_blank') Calendario Eventi
                tr
                  td(class="whitespace", height="10")
                    p &nbsp;

        - if (dataemail.templ.options.includes('SHOW_DISC'))
          tr
            td(class="whitespace bg-white", height="20")
              p(class="bg-white") &nbsp;
          tr
            td(class="center")
              p(class="cltitle_disc") #{dataemail.disc_title}
          tr
            td(class="discContainer", valign="top")

              each disc in dataemail.arrdiscipline
                - var urldisc = baseurl + disc.linkpage
                - var imgdisc = disc.img_small
                unless (imgdisc)
                  - imgdisc = disc.img

                table(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
                  tr
                    td(class="column sectionArticleImage", valign="top")
                      table(cellpadding="0", cellspacing="0", summary="", border="0")
                        tr
                          td
                            img(src=baseimg + imgdisc, alt="", width="150")
                    td(class="column", valign="top")

                      table(cellpadding="0", cellspacing="0", summary="", border="0")
                        tr
                          td(class="sectionContentTitle boldhigh center LinkDisc", valign="top")
                            a(href=urldisc, title='Disciplina', target='_blank')
                              p(class="q-chip row inline no-wrap items-center cltexth4 chipnews shadow-5 glossy text-right text-white pDisc", style=`background-color: `+disc.color)  #{disc.label}
                        tr
                          td(class="sectionContent", valign="top")
                            p!= disc.description

            tr
              td(class="whitespace", height="20")
                p &nbsp;

        - if (dataemail.content_after_events)
          tr
            table(cellpadding="0", cellspacing="0", summary="", border="0")
              tr
                td.testomail
                  p!=dataemail.content_after_events
              tr
                td(class="whitespace", height="20")
                  p &nbsp;

        tr
          td(class="whitespace", height="20")
            p &nbsp;

        // Social Media
        table.socialMedia(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
          tr
            td(class="whitespace", height="5")
              p &nbsp;
          tr
            td
              table(width="120", cellpadding="0", cellspacing="0", summary="", border="0", align="center")
                tr
                  - if (dataemail.urlinstagram)
                    td(width="32", align="center")
                      a(href=dataemail.urlinstagram, title='Instagram')
                        img(src=imginstagram, alt="Instagram", width="29")
                  - if (dataemail.urltwitter)
                    td(width="32", align="center")
                      a(href=dataemail.urltwitter, title='Twitter')
                        img(src=imgtwitter, alt="Twitter", width="29")
                  - if (dataemail.urlfb)
                    td(width="32", align="center")
                      a(href=dataemail.urlfb, title='Facebook')
                        img(src=imgfb, alt="Facebook", width="29")
                  - if (dataemail.urlyoutube)
                    td(width="32", align="center")
                      a(href=dataemail.urlyoutube, title='YouTube')
                        img(src=imgyoutube, alt="YouTube", width="29")

          tr
            td(class="whitespace", height="5")
              p &nbsp;

        // Footer
        table.footer(cellpadding="0", cellspacing="0", width="100%", summary="", border="0", align="center")
          tr
            td(class="whitespace", height="10")
              p &nbsp;
          tr
            td.firma
              p!= dataemail.firma

          tr
            td.disclaimer
              p!= dataemail.disclaimer_out

          tr
            td.bottom
              p!= dataemail.disc_bottom_out

          tr
            td(class="whitespace", height="10")
              p &nbsp;
