<template>
  <div class="waiting-processing region-card" :data-language="language">
    <div class="card">
      <div class="title">{{ $t('pages.dashboard.systemTime.title') }}</div>
      <div class="system-date">
        <div>{{ $t('pages.dashboard.systemTime.timezone') }}: {{ nowDateTimeZone }}</div>
        <p>{{ $t('pages.dashboard.systemTime.time') }}: {{ nowDateTime | dateFormat }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getCurrentTimeZone } from '@/lang'

export default {
  name: 'AccountInfo',
  data() {
    return {
      nowDateTime: new Date(),
      nowDateTimeZone: getCurrentTimeZone(),
      timeIndexInterval: null
    }
  },
  computed: {
    ...mapGetters(['language'])
  },
  created() {
    if (this.timeIndexInterval) {
      clearInterval(this.timeIndexInterval)
    }

    this.timeIndexInterval = setInterval(() => {
      this.nowDateTime = new Date()
    }, 1000)
  },
  beforeDestroy() {
    if (this.timeIndexInterval) {
      clearInterval(this.timeIndexInterval)
      this.timeIndexInterval = null
    }
  }
}
</script>
