include ../components/library
include ../components/page-sidebar
include ../user/components/profile-icon
doctype html
html(lang='en')
  - var DEFAULT_THEME = 'dtp-light';
  head
    meta(charset='UTF-8')
    meta(name='viewport', content='width=device-width, initial-scale=1.0')
    meta(name='description', content= pageDescription || siteDescription)

    title= pageTitle ? `${pageTitle} | ${site.name}` : site.name

    meta(name="robots", content= "index,follow")
    meta(name="googlebot", content= "index,follow")
    meta(name="theme-color", content="#4a4a4a")
    meta(name="apple-mobile-web-app-status-bar-style", content="black-translucent")

    block css

      link(rel='stylesheet', href=`/fontawesome/css/all.min.css?v=${pkg.version}`)
      link(rel='stylesheet', href=`/pretty-checkbox/pretty-checkbox.min.css?v=${pkg.version}`)

      block vendorcss

      link(rel='stylesheet', href=`/dist/css/${user ? (user.theme || DEFAULT_THEME) : DEFAULT_THEME}.css?v=${pkg.version}`)
  
    block js
      script(src=`/uikit/js/uikit.min.js?v=${pkg.version}`)
      script(src=`/uikit/js/uikit-icons.min.js?v=${pkg.version}`)
      //- script(src=`/fontawesome/js/fontawesome.min.js?v=${pkg.version}`)

    block pwa-support
      include ../components/pwa-support
    
    block social-card
      include ../components/social-card/twitter
      include ../components/social-card/facebook

    block view-header

    script.

      function onImageLoadError (event) {
        const imageType = event.currentTarget.getAttribute('data-image-type') || 'thumb';
        console.error('image error', imageType, event);
        switch (imageType) {
          case 'profile':
            event.currentTarget.setAttribute('src', '/img/default-member.png');
            break;
          case 'thumb':
            event.currentTarget.setAttribute('src', '/img/default-poster.jpg');
            break;
        }
      }

  body.dtp(class= user ? user.theme : DEFAULT_THEME, data-dtp-env= process.env.NODE_ENV, data-dtp-domain= site.domainKey, data-current-view= currentView)

    include ../components/site-link

    block view-globals

    block content-container
      block content

    block page-footer
      include ../components/page-footer

    block dtp-navbar
      include ../components/navbar

    block view-title

    block dtp-off-canvas
      include ../components/off-canvas

    block clientjs
      if user
        -
          var safeUser = {
            _id: user._id,
            created: user.created,
            username: user.username,
            username_lc: user.username_lc,
            displayName: user.displayName,
          };

      script(src=`/moment/moment.min.js?v=${pkg.version}`)
      script(src=`/numeral/numeral.min.js?v=${pkg.version}`)
      script(src=`/socket.io/socket.io.js?v=${pkg.version}`)

      if process.env.NODE_ENV !== 'production'
        script(src="https://localhost:3310/browser-sync/browser-sync-client.js?v=2.27.7")

      block vendorjs

      script.
        window.dtp = window.dtp || { };

      if user
        script.
          window.dtp.user = !{JSON.stringify(safeUser, null, 2)};
          window.dtp.domain = !{JSON.stringify(site.domain)};
          window.dtp.env = !{JSON.stringify(env.NODE_ENV)};

      if room
        script.
          dtp.room = !{JSON.stringify(room || null)};

      if DTP_SCRIPT_DEBUG
        script(src=`/dist/js/dtpsites-app.js?v=${pkg.version}`, type="module")
      else
        script(src=`/dist/js/dtpsites-app.min.js?v=${pkg.version}`, type="module")
      
      if user && user.flags.isAdmin
        if DTP_SCRIPT_DEBUG
          script(src=`/dist/js/dtpsites-admin.js?v=${pkg.version}`, type="module")
        else
          script(src=`/dist/js/dtpsites-admin.min.js?v=${pkg.version}`, type="module")

    block viewjs