<script setup lang="ts">


interface Props {
  id: string
  value: string
  text: string
  icon?: Component | null
  modelValue?: string
  name?: string
}

const props = withDefaults(defineProps<Props>(), {
  name: 'radio-group'
})

const emit = defineEmits(['update:modelValue'])

const isSelected = computed(() => props.modelValue === props.value)

function handleChange() {
  emit('update:modelValue', props.value)
}
</script>

<template>
  <div class="radio-wrapper">
    <input 
      type="radio" 
      :id="props.id" 
      :name="props.name"
      :value="props.value"
      :checked="isSelected"
      @change="handleChange"
      class="radio-input"
    >
    <label 
      :for="props.id" 
      class="radio-label"
      :class="{ 'radio-label-selected': isSelected }"
    >
      <span v-if="isSelected" class="gradient-border"></span>
      
      <div class="radio-content">
        <component v-if="icon" :is="icon" class="radio-icon" />
        <span class="radio-text dark-text">{{ text }}</span>
      </div>
      
      <div class="radio-indicator">
        <div v-if="isSelected" class="radio-dot"></div>
      </div>
    </label>
  </div>
</template>

<style scoped>
.radio-wrapper {
  width: 100%;
}

.radio-input {
  display: none;
}

.radio-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid #4b5563;
  background: transparent;
  transition: all 0.3s ease;
  height: 60px;
  width: 100%;
  position: relative;
}

.radio-label:hover {
  border-color: #6b7280;
}

.radio-content {
  display: flex;
  align-items: center;
  gap: 12px;
  z-index: 1;
}

.radio-icon {
  width: 30px;
  height: 30px;

}

.radio-text {

  font-size: 14px;
  font-weight: 500;
}
.radio-label-selected {
  border: 2px solid transparent;
  background: linear-gradient(
    90deg,
    oklch(0.7352 0.1277 211.3 / 12%) 0%,
    oklch(0.6572 0.237 316.56 / 12%) 100%
  );
}

.gradient-border {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 8px;
  padding: 2px;
  background: linear-gradient(
    90deg,
    oklch(0.7352 0.1277 211.3) 0%,
    oklch(0.6572 0.237 316.56) 100%
  );
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}
</style>