<template>
  <div class="c-device-dashboard-header">
    <div class="c-device-dashboard-header__name u-bold">{{ title }}</div>
    <div class="l-flex c-device-dashboard-header__wrapper">
      <div class="c-device-dashboard-header__time">{{ now }}</div>
      <div
        class="u-pointer"
        @click="onExit"
      >
        退出
      </div>
    </div>
  </div>
</template>

<script>
import { parseTime } from '@/utils'

export default {
  data () {
    return {
      title: process.env.VUE_APP_NAME,
      now: ''
    }
  },
  created () {
    this.getCurrentTime()
    this.$timer = setInterval(this.getCurrentTime, 500)
  },
  beforeDestroy () {
    clearInterval(this.$timer)
  },
  methods: {
    getCurrentTime () {
      this.now = parseTime(new Date(), '{y}/{m}/{d}   {h}:{i}')
    },
    onExit () {
      this.$router.replace({
        name: 'device-detail'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.c-device-dashboard-header {
  position: relative;
  height: 54px;
  padding-top: 4px;
  color: #fff;
  font-size: 24px;
  text-align: center;
  background: url("~@/assets/line.png") 0 16px / 100% 38px no-repeat;

  &__name {
    letter-spacing: 0.2em;
  }

  &__wrapper {
    position: absolute;
    top: 8px;
    right: 16px;
    font-size: 16px;
    line-height: 24px;
  }

  &__time {
    margin-right: 32px;
    white-space: pre;
  }
}
</style>
