<script setup lang="ts">
import { reactive, ref } from 'vue';
import ProgressBar from './components/ProgressBar.vue'
import { watch } from 'vue';

const progressBarRef = ref<InstanceType<typeof ProgressBar>>()
// 每次增加或减少的值
const step = 100
// 最大值
const max = 1000
const options = reactive({
  data: 362,
  maxValue: max,
  lineWidth: 10,
  radius: 50,
  // 颜色紫色蓝色绿色红色
  color: ['	#66DD00', '#0066FF ', '#A500CC '],
  text: {
    size: 50,        // 自定义字体大小
    color: '#666',   // 自定义字体颜色
  }
})

watch(() => options.data, (val) => {
  if (val > max) {
    options.data = max
  }
})

function add() {
  if (options.data < max) {
    options.data += step;
  }
}

function minus() {
  if (options.data > 0) {
    options.data -= step;
  }
}
</script>

<template>
  <div class="canvas-container">
    <ProgressBar ref="progressBarRef" :options="options" />
  </div>
  <div class="button-group">
    <div class="button" @click="add">+{{ step }}</div>
    <div class="button" @click="minus">-{{ step }}</div>
  </div>
</template>

<style>
.canvas-container {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.button-group {
  margin-top: 20px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.button {
  cursor: pointer;
  min-width: 100px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  padding: 0 20px;
  border-radius: 20px;
  background: #fff;
  color: #666;
  font-size: 16px;
  font-weight: 500;
  user-select: none;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  border: 1px solid #eee;
}

.button:hover {
  background: #f5f5f5;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
</style>
