<template>
  <div class="dv-timer-viewer" :class="{ isLoading: isLoading }">
    <div class="dv-timer-viewer-container">
      <span>{{title}}: {{time}}</span>
      <icon class="dv-timer-viewer-loading" name="loading" v-if="isLoading"></icon>
      <div class="dv-timer-viewer-refresh-icon-wrap" @click="refreshTime" v-else>
        <icon class="dv-timer-viewer-refresh-icon" name="refresh"></icon>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'DvTimeViewer',
    props: {
      isLoading: {
        type: Boolean,
        default: false
      },
      title: {
        type: String,
        default: '当前'
      },
      value: null
    },
    data () {
      return {
        time: this.value
      };
    },
    watch: {
      value(value) {
        this.time = value;
      }
    },
    methods: {
      refreshTime () {
        this.$emit('refreshTime', this.time);
      },
      initializeTime (time) {
        this.time = time;
      },
      setTime (time) {
        this.time = time;
      }
    }
  };
</script>
