<!--
 * 转轮游戏
-->
<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: #f2bdd0">
          <span>100</span>
        </div>
        <div class="number" style="--i: 2; --clr: #f0f4c1"><span>1</span></div>
        <div class="number" style="--i: 3; --clr: #cccc99"><span>50</span></div>
        <div class="number" style="--i: 4; --clr: #cccccc"><span>0</span></div>
        <div class="number" style="--i: 5; --clr: #cb7575">
          <span>1000</span>
        </div>
        <div class="number" style="--i: 6; --clr: #ecb83c"><span>10</span></div>
        <div class="number" style="--i: 7; --clr: #d3e397"><span>5</span></div>
        <div class="number" style="--i: 8; --clr: #f8dcdc"><span>20</span></div>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.box {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #333;
}
.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(0, 0, 0, 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: #333;
    border-radius: 50%;
    box-shadow: 0 0 0 5px #333, 0 0 0 15px #fff, 0 0 0 18px #111;
    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>
