<script setup lang="ts">
const modelValue = defineModel<number>({ default: 0 })

const props = defineProps<{
  title: string
  min: number
  max: number
}>()

function onInput(ev: Event) {
  const target = ev.target as HTMLInputElement
  modelValue.value = Number(target.value)
}
</script>

<template>
  <div>
    <h2>{{ props.title }}</h2>
    <div class="value">{{ modelValue }}</div>
    <input
      type="range"
      :min="props.min"
      :max="props.max"
      :value="modelValue"
      @input="onInput"
    />
    <div class="scale">
      <span>{{ props.min }}</span>
      <span>{{ props.max }}</span>
    </div>
  </div>
</template>

<style scoped>
h2 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.value {
  text-align: center;
  font-size: 2rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: #111827;
}

input[type='range'] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: #e5e7eb;
  outline: none;
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #f97316;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  margin-top: -9px;
}

input[type='range']::-moz-range-thumb {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  border: 2px solid #f97316;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  cursor: pointer;
}

.scale {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: #6b7280;
  margin-top: 0.25rem;
}
</style>
