<script setup lang="ts">
const { isActive: isCounting, remaining: countdownTime, start: startCountdown } = useCountdown($__DEV__ ? 3 : 60);

const isSending = ref(false);
const sendSms = async () => {
  console.debug('[sendSms]');
  isSending.value = true;
  try {
    await new Promise((resolve) => setTimeout(resolve, 1000));
    startCountdown();
    ToastService.add({ detail: '验证码发送成功', life: 3000, severity: 'info', summary: '提示' });
  } finally {
    isSending.value = false;
  }
};
</script>

<template>
  <AButton ghost type="primary" @click="sendSms" :loading="isSending" :disabled="isSending || isCounting">
    发送验证码{{ isCounting ? `(${countdownTime}s)` : '' }}
  </AButton>
</template>
