<template>
  <div class="previewBox">
    <el-row>
      <el-col :span="16" class="headerBox">
        <svg-icon icon-class="defaultPeople" class-name="headerImg" />
        <span class="headerAuthor">{{ info.author }}</span>
      </el-col>
      <el-col :span="8" class="time">{{ showTime }}</el-col>
    </el-row>
    <p class="title">{{ info.title }}</p>
    <div class="contents" v-html="info.contents" />
  </div>
</template>
<script>
export default {
  props: {
    info: {
      type: Object,
      default: () => {
        return {
          author: '',
          created_at: '',
          title: '',
          contents: ''
        }
      }
    }
  },
  computed: {
    showTime() {
      if (!this.info.created_at) {
        return '之前发布'
      }
      let str = ''
      const nowTime = Date.now()
      const createTime = new Date(this.info.created_at).getTime()
      const num = Math.floor((nowTime - createTime) / 1000 / 60)
      switch (num) {
        case num < 15:
          str = '刚刚发布'
          break
        case num > 15 && num < 30:
          str = '15分钟前发布'
          break
        case num > 30 && num < 60:
          str = '30分钟前发布'
          break
        case num > 60 && num < 180:
          str = '1小时前发布'
          break
        case num > 180 && num < 540:
          str = '3小时前发布'
          break
        case num > 540 && num < 1440:
          str = '1天前发布'
          break
        default:
          str = '刚刚发布'
      }
      return str
    }
  }
}
</script>

<style lang="scss" scoped>
  .previewBox{
    .headerBox{
      display: flex;
      justify-content: flex-start;
      align-items: center;
    }
    .headerImg{
      display: block;
      width: 40px;
      height: 40px;
      border-radius: 50%;
      margin-right: 10px;
    }
    .headerAuthor{
      font-size: 16px;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      &::after{
        content: "官方";
        display: block;
        font-size: 10px;
        background-color: #F76454;
        width: 32px;
        height: 16px;
        line-height: 16px;
        text-align: center;
        color: #ffffff;
        border-radius: 4px;
        padding: 1px 4px;
        transform: scale(0.9);
        margin-left: 10px;
      }
    }

    .time{
      line-height: 40px;
      text-align: right;
      color: #F76454;
    }

    .title{
      font-size: 16px;
      color: #333333;
      margin: 10px 0;
    }

    .contents{
      img {
        display: block;
        width: 100%;
        height: auto;
      }
      p{
        margin: 0;
        line-height: 30px;
      }
    }
  }
</style>

<style lang="scss">
  .previewBox{
    video{
      display: block;
      width: 100%;
    }
    img {
      display: block;
      width: 100%;
      height: auto;
      margin: 10px 0;
    }
    ul, ol{
      padding: 10px;
    }
    p, li, section, span, li {
      line-height: 30px;
    }
  }
</style>
