<template>
  <transition :name="transition">
    <div v-show="show && !!content" :class="[c(),cusClass]">
      <div :class="c('wrap')">
        <div :class="c('img')">
          <img src="./warning@2x.png" style="width: 18px">
        </div>
        <div :class="c('content')">{{ content }}</div>
        <div :class="c('cross-area')" @click="close">
          <a :class="c('cross')" href="javascript:void(0)"/>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import {base, prefix} from '../../common/mixins'

const directions = ['up', 'left', 'right', 'down']

export default {
  name: 'TopTip',
  mixins: [base, prefix],
  props: {
    value: {
      type: Boolean,
      default: false,
    },
    content: {
      type: String,
      default: '',
    },
    entryDirection: {
      type: String,
      default: 'left',
    },
    cusClass: {
      type: String,
      default: '',
    },
  },
  data () {
    return {
      show: false,
    }
  },
  computed: {
    transition () {
      return directions.includes(this.entryDirection)
        ? this.b(`slide-in-${this.entryDirection}`)
        : this.b('slide-in-left')
    },
  },
  watch: {
    value (val) {
      this.show = val
    },
  },
  created () {
    if (this.value) {
      this.show = this.value
    }
  },
  methods: {
    close () {
      this.$emit('input', false)
    },
  },
}
</script>

<style lang="less">

  @topTipFontColor: #999;
  @topTipBackgroundColor: #fff8dc;
  @topTipCrossColor: #6d7a80;

  .crossLineRotate(@d) {
    width: 2px;
    height: 14px;
    display: block;
    transform: rotateZ(@d);
    background-color: @topTipCrossColor;
  }

  .hls-top-tip {
    text-align: center;

    &-wrap {
      position: relative;
      padding: 8px 32px 8px 15px;
      font-size: 14px;
      color: @topTipFontColor;
      background-color: @topTipBackgroundColor;
    }

    &-img{
      width: 13px;
      height: 100%;
      position: absolute;
      top: 0;
      display: -webkit-box;
      display: -webkit-flex;
      display: flex;
      -webkit-box-pack: center;
      -webkit-justify-content: center;
      justify-content: center;
      -webkit-box-align: center;
      -webkit-align-items: center;
      align-items: center;
    }

    &-content {
      word-break: break-word;
      margin-left: 26px;
      text-align: left;
    }

    &-cross-area {
      width: 32px;
      height: 100%;
      position: absolute;
      top: 0;
      right: 0;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    &-cross {
      .crossLineRotate(45deg);

      &:before {
        content: '';
        .crossLineRotate(-90deg);
      }
    }
  }
</style>