<template>
  <div class="dashboard-header" :style="{ height }">
    <div v-if="leftShow" class="dashboard-header-left">
      {{ leftContent }}
      <div>{{ nickname }}</div>
    </div>

    <div class="dashboard-header-content" :style="contentStyle">
      {{ content }}
    </div>
    <div v-if="rightShow" class="dashboard-header-right text-right">
      {{ rightContent }}
    </div>
  </div>
</template>

<script>
import dayjs from "dayjs";

import { mapGetters } from "vuex";
export default {
  props: {
    content: {
      type: String,
      default: "",
    },
    height: {
      type: String,
      default: "3vh",
    },
    // 是否展示左侧按钮
    leftShow: {
      type: Boolean,
      default: true,
    },
    // 是否展示右侧按钮
    rightShow: {
      type: Boolean,
      default: true,
    },
    contentStyle: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      timer: null,
      leftContent: dayjs().format("今天是YYYY年MM月DD日"),
      rightContent: dayjs().format("当前时间HH:mm:ss"),
    };
  },
  computed: {
    ...mapGetters(["nickname"]),
  },
  created() {
    this.initTimer();
  },
  beforeDestroy() {
    clearInterval(this.timer);
    this.timer = null;
  },
  methods: {
    initTimer() {
      clearInterval(this.timer);
      this.timer = setInterval(() => {
        this.leftContent = dayjs().format("今天是YYYY年MM月DD日");
        this.rightContent = dayjs().format("当前时间: HH:mm:ss");
      }, 1000);
    },
  },
};
</script>

<style lang="scss" scoped>
.dashboard-header {
  display: flex;
  align-items: center;
  &-content {
    font-weight: bold;
    font-size: 3.5rem;
    flex: 1;
    text-align: center;
    color: #daf9ff;
    text-shadow: rgba(22, 214, 255, 0.9) 0 0 20px;
  }
  &-left,
  &-right {
    flex-shrink: 0;
    flex-grow: 0;
    color: rgba(22, 214, 255, 0.9);
    text-shadow: 0 0 5px rgb(22 214 255 / 90%);
    font-size: 1.3rem;
  }
}

/* 手机尺寸样式 */
@media screen and (max-width: 600px) {
  .dashboard-header {
    &-content {
      font-size: 1.9rem; /* 减小字体大小 */
    }
    &-left,
    &-right {
      font-size: 1rem; /* 减小字体大小 */
    }
  }
}
</style>
