<template>
  <div class="monitor-title">
    <!-- <span v-if="!hideDate" class="moment date" @mouseenter="openDatePicker = true" @mouseleave="openDatePicker = false">
      <DatePicker @on-change="handleDateChange" :value="curDate" :options="options" class="date-picker" :open="editable && openDatePicker" type="date">
        <span>{{curDate}}</span>
      </DatePicker>
    </span> -->
    <div class="btn back" @click="closePage" />
    <div class="btn close" @click="closePage" />
    <span v-if="!hideTime" class="moment time">
      <!-- <span class="switch"><img src="@/assets/images/switch.png"/> 切换街道</span> -->
      {{curDate}} {{time}}
    </span>
    <img :src="bgImg" draggable="false"/>
    <p :style="style"><slot /></p>
  </div>
</template>

<script>
export default {
  name: 'MonitorTitle',
  props: {
    bgImg: {
      type: String,
    },
    hideDate: {
      type: Boolean,
      default: false,
    },
    hideTime: {
      type: Boolean,
      default: false,
    },
    editable: {
      type: Boolean,
      default: false,
    },
    color: {
      type: String,
    },
    size: {
      type: String,
      default: '0.2rem',
    },
  },
  data() {
    return {
      openDatePicker: false,
      timer: null,
      time: null,
      style: {},
    }
  },
  mounted() {
    if (!this.hideTime) {
      this.timer = setInterval(() => {
        this.time = `${this.$moment().format('dddd')} ${this.$moment().format('LTS')}`
      }, 1000)
    }
    // if (this.color) {
    //   this.style = {
    //     'text-shadow': `0 0.02rem 0.04rem ${this.color}`,
    //     'color': this.color,
    //     'background-image': `linear-gradient(to bottom, #fff, ${this.color})`
    //   }
    // }
    this.style = {...this.style, 'font-size': this.size}
  },
  beforeDestroy() {
    clearInterval(this.timer)
    this.timer = null
  },
  computed: {
    curDate() {
      const date = this.$store.state.curDate
      return date ? this.$moment(date).format('YYYY-MM-DD') : this.$moment().format('YYYY-MM-DD')
    },
    options() {
      return {
        disabledDate: (date) => {
          return this.$moment(date).isAfter(this.$moment())
        }
      }
    }
  },
  methods: {
    handleDateChange(date) {
      this.$store.commit('SET_CURDATE', date)
      this.openDatePicker = false
    },
    // toAli() {
    //   window.location = 'http://10.89.1.208/share/ypdp'
    // },
    closePage() {
      window.close()
    },
  }
}
</script>

<style lang="stylus" scoped>
.monitor-title
  display flex
  align-items center
  justify-content center
  position relative
  background-size cover
  background-position center
  // font-family $font-pang
  font-weight bold
  >.btn
    position absolute
    width .2rem
    height @width
    top .05rem
    cursor pointer
    z-index 999
    background-size 100% 100%
    transition background-image .3s ease-in-out
    &.back
      left .1rem
      background-image url(../../../assets/images/back.png)
      &:hover
        background-image url(../../../assets/images/back-on.png)
    &.close
      right .1rem
      background-image url(../../../assets/images/close.png)
      &:hover
        background-image url(../../../assets/images/close-on.png)
  .switch
    color #5BD5FF
    margin-right .1rem
    cursor pointer
    img
      width .12rem
      vertical-align middle
  .moment
    z-index 100
    position absolute
    font-size 0.12rem
    color #fff
    // width 1.5rem
    top 25%
    // &.date
      // right 15%
    &.time
      // right 15%
      left 0
      right 0
      margin 0 auto
      text-align center
      transform translateX(20%)
  >img
    position absolute
    width 100%
    height 100%
    top 0
    left 0
    // animation shine 2.5s linear reverse infinite
  >p
    // text-shadow 0 0.02rem 0.04rem #B3EBFF
    background-clip text
    -webkit-background-clip text
    // color #B3EBFF
    -webkit-text-fill-color transparent
    background-image linear-gradient(to bottom, #fff, #B3EBFF)
    z-index 99
    letter-spacing .05rem
// @keyframes shine {
//   0% {
//     opacity 1
//   }
//   50% {
//     opacity 0.7
//   }
//   100% {
//     opacity 1
//   }
// }
</style>
