<template>
  <div class="data-box">
    <div class="box-border">
      <div :id="blinkId" class="box-title-wrapper">
        <div class="box-title" :style="titleStyle">{{ titleName }}</div>
      </div>
      <div class="box-content-wrapper">
        <div class="box-content">
          <slot/>
        </div>
      </div>
    </div>
    </div>
</template>

<script>
export default {
  name: 'DataBox',
  props: {
    titleName: {
      type: String,
      default: '261工房'
    },
    type: {
      type: String,
      default: 'realtime'
    }
  },
  data() {
    return {
    }
  },
  computed: {
    titleStyle() {
      const titleStyle = {}
      switch (this.type) {
        case 'analysis':
          titleStyle.background = 'url(' + require('@/assets/images/data/analysis.png/') + ') no-repeat center center'
          titleStyle.backgroundSize = '100% 100%'
          titleStyle.width = '316px'
          titleStyle.height = '60px'
          break
        case 'realtime':
          titleStyle.background = 'url(' + require('@/assets/images/data/realtime.png/') + ') no-repeat center center'
          titleStyle.backgroundSize = '100% 100%'
          titleStyle.width = '396px'
          titleStyle.height = '60px'
          break
        case 'warn':
          titleStyle.background = 'url(' + require('@/assets/images/data/warn.png/') + ') no-repeat center center'
          titleStyle.backgroundSize = '100% 100%'
          titleStyle.width = '316px'
          titleStyle.height = '60px'
          break
        case 'workshop':
          titleStyle.background = 'url(' + require('@/assets/images/data/workshop.png/') + ') no-repeat center center'
          titleStyle.backgroundSize = '100% 100%'
          titleStyle.width = '316px'
          titleStyle.height = '60px'
          break
      }
      return titleStyle
    },
    blinkId() {
      return this.type + '-' + 'blink'
    }
  },
  methods: {
    setAlertState(active) {
      const alertOverlay = document.getElementById('warn-blink')
      if (alertOverlay) {
        if (active) {
          alertOverlay.classList.add('alert-active')
        } else {
          alertOverlay.classList.remove('alert-active')
        }
      }
    },
  },
}
</script>

<style lang="less" scoped>
.data-box {
  height: 100%;
  width: 100%;

  .box-border {
    clip-path: polygon(20px 0, calc(100% - 20px) 0, 100% 20px, 100% calc(100% - 20px), calc(100% - 20px) 100%, 20px 100%, 0 calc(100% - 20px), 0 20px);
    box-shadow: #194364 10px 10px 60px 30px inset;
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;

    .box-title-wrapper {
      display: flex;
      justify-content: center;

      .box-title {
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        margin-bottom: 8px;
      }
    }

    .box-content-wrapper {
      flex: 1;
      margin-bottom: 20px;
      position: relative;

      .box-content {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 100%;
        overflow: auto;
      }
    }
  }

  .alert-active {
    animation: blink 1s infinite;
  }

  @keyframes blink {
    0% {
      opacity: 0;
    }
    50% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
}

// 1、/*滚动条样式*/
div::-webkit-scrollbar { /*滚动条整体样式*/
  width: 5px; /*高宽分别对应横竖滚动条的尺寸*/
  height: 5px;
}

div::-webkit-scrollbar-thumb { /*滚动条里面小方块*/
  border-radius: 5px;
  -webkit-box-shadow: inset 0 0 5px #fafafa;
  //background: rgba(0,0,0,.075);
  background: #999999;
}

div::-webkit-scrollbar-track { /*滚动条里面轨道*/
  -webkit-box-shadow: inset 0 0 5px #fafafa;
  border-radius: 0;
  background: #ececec;
}

</style>
