<template>
  <Dialog
    ref="dialog"
    width="502px"
    height="300px"
  >
    <img v-audio class="close btn" src="https://kuawai.s3.ap-east-1.amazonaws.com/resource/assets/Textures/second/Rectangle%201175%20copy.png" alt="" @click="visible = false">
    <div class="bg"/>
    <div class="content">
      <div class="title">{{ title }}</div>
      <div class="message">
        <div class="info"><strong>Jackpot</strong>: {{ data.levelName }}</div>
        <div class="info"><strong>Amount</strong>:
          <img v-if="data.creditType === 1" class="red-coin" src="https://kuawai.s3.ap-east-1.amazonaws.com/temp/header/gold-coin.png" alt="">
          <img v-if="data.creditType === 2" class="red-coin" src="https://kuawai.s3.ap-east-1.amazonaws.com/temp/header/red-coin.png" alt="">
          {{ data.amount }}
        </div>
        <div style="margin-top: 30px;">
          <template v-if="selfWin">
            <div class="p">
              ${{ data.amount }} credits has been added to your account.
            </div>
          </template>
          <template v-else>
            <div class="p">
              Another {{ data.levelName }} Jackpot has just been WON! Congratulations to Player {{ data.nickName }} for winning ${{ data.amount }} credits!!
            </div>
          </template>
          <div class="p">
            {{ data.levelName }} Jackpot has been reset.
          </div>
        </div>
      </div>
      <div class="footer-tip">
        <div>Location No: {{ data.egmId }} - {{ data.egmName }}</div>
        <div>Time: {{ data.winTime | filterTime }}</div>
      </div>
    </div>
  </Dialog>
</template>

<script>
import Dialog from '@/components/dialog/index'
import { mapState } from 'vuex'
import dayjs from 'dayjs'
export default {
  components: {
    Dialog,
  },
  filters: {
    filterTime(value) {
      return dayjs(value).format('YYYY-MMMM-DD HH:mm:ss')
    },
  },
  props: {
    message: {
      type: String,
      default: '',
    },
    tip: {
      type: String,
      default: '',
    },
    data: {
      type: Object,
      default: () => {
        return {}
      },
    },
  },
  data() {
    return {
      visible: false,
    }
  },
  computed: {
    ...mapState([
      'zoom',
      'userInfo',
    ]),
    // 自己赢得
    selfWin() {
      const { data, userInfo } = this
      return data.playerId === userInfo.id
    },
    title() {
      const { data, selfWin } = this
      const title = selfWin ? 'You are the Jackpot Winner!' : 'A Jackpot Is Won!'
      return title
    },
  },
  watch: {
    visible(value) {
      if (value) {
        this.$refs.dialog.show()
      } else {
        this.$refs.dialog.close()
      }
    },
  },
  methods: {
    confirm() {
      this.$emit('confirm')
      this.visible = false
    },
    show() {
      this.visible = true
    },
  },
}
</script>

<style lang="scss" scoped>
.bg {
  background-size: 100% 100%;
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
  top: 0;
  left: 0;
  border-radius: 12px;
  background: linear-gradient(30deg,#6d542c,#b78e47, #6d542c);
}
.close {
  position: absolute;
  right: -20px;
  top: -16px;
  width: 38px;
  z-index: 10;
}
.content {
  position: relative;
  z-index: 2;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-direction: column;
  .title {
    text-align: center;
    font-size: 28px;
    font-weight: bold;
    color: #241804;
    margin-top: 30px;
  }
  .message {
    color: #241804;
    padding: 16px 38px;
    flex: 1;
    .info {
      margin: 8px;
    }
    .red-coin {
      width: 50px;
      margin-block: -24px;
      margin-left: -4px;
    }
    .p {
      margin-top: 10px;
    }
  }
  .footer-tip {
    line-height: 18px;
    text-align: right;
    padding: 4px 16px;
    font-size: 12px;
    color: #241804;
  }
}
/deep/ .game-dialog {
  position: relative;
  background: transparent;
  height: 320px;
  padding: 0;
  .el-dialog__header {
    padding: 0;
  }
  .el-dialog__body {
    max-height: inherit;
    padding: 0;
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
  }
}
</style>
