<template>
  <div class="button-container">
    <button :class="['circular-button', { selected: isSelected }]" @click="toggleSelection" type="button" role="switch" :aria-checked="isSelected">
      <span class="inner-circle"></span>
    </button>
  </div>
</template>

<script setup lang="ts">
const props = defineProps<{
  modelValue?: boolean
}>()

const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
}>()

const isSelected = computed({
  get: () => props.modelValue ?? false,
  set: (value) => emit('update:modelValue', value),
})
const toggleSelection = () => {
  isSelected.value = !isSelected.value
}
</script>

<style scoped>
.circular-button {
  position: relative;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 4px solid #d1d5db;
  background: transparent;
  padding: 0;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.inner-circle {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background-color: transparent;
  transition: all 0.2s ease;
}

.circular-button.selected .inner-circle {
  background-color: #0068ff;
}

/* 无障碍焦点样式 */
.circular-button:focus {
  outline: none;
}

/* 按下状态 */
.circular-button:active {
  transform: scale(0.95);
}
</style>
