<!--
 * 转轮游戏
-->
<script setup lang="ts">
import { ref } from 'vue';

const wheelRef = ref<any>(null);
const val = ref(Math.ceil(Math.random() * 3600));

function spinClick() {
  wheelRef.value.style.transform = `rotate(${val.value}deg)`;
  val.value += Math.ceil(Math.random() * 3600);
}
</script>
<template>
  <div class="box fit">
    <div class="container">
      <div class="spin-btn" @click="spinClick">开始</div>
      <div class="wheel" ref="wheelRef">
        <div class="number" style="--i: 1; --clr: #feb54a">
          <span>100</span>
        </div>
        <div class="number" style="--i: 2; --clr: #d1e94a"><span>1</span></div>
        <div class="number" style="--i: 3; --clr: #96dea6"><span>50</span></div>
        <div class="number" style="--i: 4; --clr: #80dbe6"><span>0</span></div>
        <div class="number" style="--i: 5; --clr: #7478a8">
          <span>1000</span>
        </div>
        <div class="number" style="--i: 6; --clr: #c06d99"><span>10</span></div>
        <div class="number" style="--i: 7; --clr: #f5869e"><span>5</span></div>
        <div class="number" style="--i: 8; --clr: #ff6747"><span>20</span></div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  // background-color: #333;
  background-color: #fff;
}
.container {
  position: relative;
  width: 400px;
  height: 400px;
  display: flex;
  justify-content: center;
  align-items: center;

  .spin-btn {
    position: absolute;
    width: 60px;
    height: 60px;
    background-color: #fff;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: 600;
    color: #333;
    letter-spacing: 0.1em;
    border: 4px solid rgba(152, 215, 93, 0.75);
    cursor: pointer;
    user-select: none;
    z-index: 10;

    &::before {
      content: '';
      position: absolute;
      width: 20px;
      height: 30px;
      background-color: #fff;
      top: -28px;
      clip-path: polygon(50% 0%, 15% 100%, 85% 100%);
    }
  }

  .wheel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-color: #fff;
    border-radius: 50%;
    box-shadow: 0 0 0 4px #fff, 0 0 0 12px #e1f1a8, 0 0 0 18px #97d75d;
    transition: transform 5s ease-in-out;

    .number {
      position: absolute;
      width: 50%;
      height: 50%;
      background-color: var(--clr);
      transform-origin: bottom right;
      transform: rotate(calc(45deg * var(--i)));
      clip-path: polygon(0 0, 56% 0, 100% 100%, 0 56%);
      display: flex;
      justify-content: center;
      align-items: center;
      user-select: none;
      span {
        position: relative;
        transform: rotate(45deg);
        font-size: 2em;
        font-weight: 700;
        color: #fff;
        text-shadow: 3px 5px 2px rgba(0, 0, 0, 0.15);
        &::after {
          content: '¥';
          position: absolute;
          top: 5px;
          font-size: 0.75em;
          font-weight: 500;
        }
      }
    }
  }
}
</style>
