<template>
  <div data-name="endgame1_intro" class="page">

    <div class="navbar">
      <div class="navbar-inner">
        <div class="title">{{ $root.appdict.endgame1_title }}</div>
        <div class="right"><i class="fas fa-wifi" style="margin-right: 0.5rem"></i> http://{{publicurl}}</div>
      </div>
    </div>

    <div class="page-content">

      <div class="block-title">{{ $root.appdict.endgame1_title }}</div>
      <div class="block">

        <div class="row">
          <div class="col-40">
            {{ $root.appdict.endgame1_info }}
          </div>
          <div class="col-60">
            {{ screenshot }}
          </div>

        </div>
      </div>

      <div class="block block-strong">
        <div class="row">
          <div class="col-55">
            <span id="timer-output"></span>
          </div>
          <div class="col-30">
            <button @click="toggleTimer" id="toggleTimer-button"
              class="button button-large button-outline">{{ $root.appdict.label_pausetimer }}</button>
          </div>
          <div class="col-15">
            <button @click="skipToNext" class="button button-large button-outline">{{ $root.appdict.btn_skip }}</button>
          </div>
        </div>
      </div>

    </div>

  </div>
</template>


<style>

</style>


<script>
  // script must return component object
  return {
    data: function () {
      return {
        publicurl: ui.publicUrl,
        screenshot: ui.tmp.screenShot
      }
    },
    methods: {
      toggleTimer: function () {
        ui.timerPause = !ui.timerPause
        if (ui.timerPause) {
          $$("#toggleTimer-button").html(`<i class="fas fa-play-circle"></i> ${framework.data.appdict.label_resumetimer}`)
        } else {
          $$("#toggleTimer-button").html(`<i class="fas fa-pause-circle"></i> ${framework.data.appdict.label_pausetimer}`)
        }
      },
      skipToNext: function () {
        ui.fn.nextPhase()
      }
    },
    on: {
      pageAfterIn: function () {

        ui.timer = 7
        ui.timerPause = false

        ui.lastUpdate = Date.now()
        ui.timer += 0.9

        function updatePage() {
          let timerVal = ui.fn.timerUpdate()
          $$("#timer-output").html(`${framework.data.appdict.label_phasetimer} <strong>${timerVal}</strong>`)
          if (timerVal === 0 && !ui.timerPause) ui.fn.nextPhase()
        }

        updatePage()
        ipcRenderer.send('ipcF2M_setGameState', 'Endgame1')



        ui.update = setInterval(updatePage, 500)
        ui.shotUpdate = setInterval(ui.fn.updateScreenShot, 5000)

      },
    }
  }
</script>