# Mixins & constants {{{
$title = (title, icon, variant = \outline) ->
  h3 ->
    img class: \icon alt: '' src: @lib.icon variant, icon
    $ $i18n[title]

$url = (url, scheme, alt, icon, variant = \outline) ->
  return unless url
  div {class: \url} ->
    img class: \icon, alt: $i18n[alt], src: @lib.icon variant, icon
    a {rel: \me href: scheme + url} @lib.strip url

$keywords = (keywords) ->
  if keywords?.length > 0
    div {class: \keywords} ->
      for let keyword in keywords
        mark keyword

$highlights = (highlights) ->
  if highlights?.length > 0
    ul {class: \highlights} ->
      for let highlight in highlights
        li highlight

$dates = ({start-date, end-date}, format = {}) ->
  start-fmt = @lib.format start-date, $lang, format
  time {datetime: start-date} start-fmt
  if end-date
    end-fmt = @lib.format end-date, $lang, format
    unless start-fmt == end-fmt
      time {datetime: end-date} end-fmt
  else
    span $i18n.\Present

const $size = @resume.meta?.\x-size || \10pt

const $lang = @resume.meta?.\x-lang || \en

const $dir = new Intl.Locale($lang).text-info.direction

const $i18n = @lib.i18n $lang

const $twitter = @resume.basics.profiles \
  ?.find(-> it.network.to-lower-case! == \twitter) \
  ?.username?.replace(/^[^@]/, \@$&)
# }}}

doctype \html
html {lang: $lang, dir: $dir} ->
  head ->
    meta charset: \UTF-8
    meta name: \viewport content: 'width=device-width,initial-scale=1'
    if @resume.meta?.last-modified
      meta \http-equiv : \Last-Modified content: new Date(@resume.meta.last-modified).toUTCString!
    meta name: \generator content: "#{@name} v#{@version}"
    meta name: \author content: @resume.basics.name
    if @resume.basics.summary
      meta name: \description content: @resume.basics.summary
    meta property: \og:site_name content: @resume.basics.name
    if @resume.basics.label
      meta property: \og:title content: @resume.basics.label
    if @resume.basics.summary
      meta property: \og:description content: @resume.basics.summary
    if @resume.basics.image
      meta property: \og:image content: @resume.basics.image
    if @resume.meta?.\x-lang
      meta property: \og:locale content: @resume.meta.'x-lang'.replace \- \_
    meta name: \twitter:site content: $twitter if $twitter
    meta name: \twitter:card content: \summary
    if @resume.meta?.version
      meta name: \version content: @resume.meta.version
    if @resume.meta?.canonical
      link rel: \alternate type: \application/json title: \resume.json href: @resume.meta.canonical
    if @resume.basics.image
      link rel: 'shortcut icon', type: @lib.mime(@resume.basics.image), href: @resume.basics.image
    link rel: \stylesheet type: \text/css href: 'https://use.typekit.net/wav6afv.css'
    style ":root{font-size:#{$size}}#{@style}"
    title @resume.basics.name
  body ->
    header {class: \flex} ->
      section ->
        h1 {id: \name} @resume.basics.name
        if @resume.basics.label
          h2 {id: \label} @resume.basics.label
      if @resume.basics.image
        section {id: \image} ->
          img alt: $i18n.\Photo, src: @resume.basics.image
    main ->
      article {id: \about} ->
        $title 'Personal Info' \identification
        if @resume.basics.summary
          p {id: \summary class: \wrap} @resume.basics.summary
        address {class: \flex} ->
          section {id: \contact} ->
            $url @resume.basics.url, '', \Website, \globe-alt
            $url @resume.basics.email, \mailto:, \E-mail, \envelope
            $url @resume.basics.phone, \tel:, \Phone, \phone
            if @resume.basics.location
              div ->
                img class: \icon, alt: $i18n.\Address, src: @lib.icon \outline \map-pin
                span @lib.address @resume.basics.location
          if @resume.basics.profiles?.length > 0
            section {id: \profiles} ->
              for let profile in @resume.basics.profiles
                div {class: \brand} ->
                  img {class: \icon, alt: profile.network, src: @lib.brand profile.network}
                  if profile.url
                    a {rel: \me href: profile.url} profile.username
                  else
                    span profile.username
      if @resume.work?.length > 0
        article {id: \work} ->
          $title 'Work Experience' \building-office-2
          for let work in @resume.work
            # TODO: support description
            section {class: 'work details'} ->
              div ->
                strong work.position
                if @lib.any-of work, <[startDate endDate]>
                  span {class: \float} ->
                    $dates work{start-date, end-date}
              div ->
                strong ->
                  if work.url
                    a {href: work.url} work.name
                  else
                    span work.name
                b {class: \float} work.location if work.location
              p {class: \wrap} work.summary if work.summary
              $highlights work.highlights
      if @resume.education?.length > 0
        article {id: \education} ->
          $title \Education \academic-cap
          for let education in @resume.education
            section {class: 'education details'} ->
              div ->
                strong ->
                  if education.url
                    a {href: education.url} education.area
                  else
                    span education.area
                if @lib.any-of education, <[startDate endDate]>
                  span {class: \float} ->
                    $dates education{start-date, end-date}
              div ->
                strong education.institution
                b {class: \float} education.study-type
              if education.score
                div {class: \grade} ->
                  b "#{$i18n.\Grade}: "
                  $ education.score
              if education.courses?.length > 0
                div {class: \courses} ->
                  b "#{$i18n.'Notable Courses'}:"
                  ul ->
                    for let course in education.courses
                      li course
      if @resume.volunteer?.length > 0
        article {id: \volunteer} ->
          $title 'Volunteer Work' \lifebuoy
          for let volunteer in @resume.volunteer
            section {class: 'volunteer details'} ->
              div ->
                strong ->
                  if volunteer.url
                    a {href: volunteer.url} volunteer.summary
                  else
                    span volunteer.summary
                if @lib.any-of volunteer, <[startDate endDate]>
                  span {class: \float} ->
                    $dates volunteer{start-date, end-date}, day: \numeric
              div ->
                strong volunteer.organization
                b {class: \float} volunteer.position
              $highlights volunteer.highlights
      if @resume.projects?.length > 0
        article {id: \projects} ->
          $title \Projects \archive-box
          for let project in @resume.projects
            # TODO: support type
            section {class: 'project details'} ->
              div ->
                strong ->
                  if project.url
                    a {href: project.url} project.name
                  else
                    span project.name
                if @lib.any-of project, <[startDate endDate]>
                  span {class: \float} ->
                    $dates project{start-date, end-date}, day: \numeric
              if project.roles?.length > 0
                div ->
                  strong project.roles.join ', '
                  b {class: \float} project.entity if project.entity
              div {class: \wrap} project.description if project.description
              $highlights project.highlights
              $keywords project.keywords
      if @resume.publications?.length > 0
        article {id: \publications, class: \flex} ->
          $title \Publications \document-text
          for let publication in @resume.publications
            section {class: \publication} ->
              div ->
                strong ->
                  if publication.website
                    a {href: publication.website} publication.name
                  else
                    span publication.name
              div {class: \sep} ->
                b publication.publisher
                time {datetime: publication.release-date} do
                  @lib.format publication.release-date, $lang, month: \short
              p {class: \wrap} publication.summary if publication.summary
      if @resume.certificates?.length > 0
        article {id: \certificates} ->
          $title \Certifications \check-badge
          for let certificate in @resume.certificates
            section {class: \certificate} ->
              div ->
                strong ->
                  if certificate.url
                    a {href: certificate.url} certificate.name
                  else
                    span certificate.name
              div {class: \sep} ->
                b certificate.issuer
                time {datetime: certificate.date} do
                  @lib.format certificate.date, $lang, month: \short
      if @resume.skills?.length > 0
        article {id: \skills class: \flex} ->
          $title \Skills \wrench-screwdriver
          for let skill in @resume.skills
            section {class: \skill} ->
              strong skill.name
              div {title: skill.level} ->
                progress {max: 100 value: @lib.skill skill.level}
              $keywords skill.keywords
      if @resume.languages?.length > 0
        article {id: \languages class: \flex} ->
          $title \Languages \language
          for let language in @resume.languages
            section {class: \language} ->
              strong language.language
              div {class: \wrap} language.fluency
      if @resume.awards?.length > 0
        article {id: \awards, class: \flex} ->
          $title \Awards \trophy
          for let award in @resume.awards
            section {class: \award} ->
              div ->
                strong award.title
              div {class: \sep} ->
                b award.awarder
                if award.date
                  time {datetime: award.date} do
                    @lib.format award.date, $lang, month: \short
                else
                  span \N/A
              p {class: \wrap} award.summary if award.summary
      if @resume.interests?.length > 0
        article {id: \interests class: \flex} ->
          $title \Interests \heart
          for let interest in @resume.interests
            section {class: \interest} ->
              strong interest.name
              $keywords interest.keywords
      if @resume.references?.length > 0
        article {id: \references} ->
          $title \References \hand-thumb-up
          for let reference in @resume.references
            section {class: \reference} ->
              blockquote {class: \wrap} reference.reference
              b reference.name

# vim:ft=livescript:
