<template>
  <div class="pui-label" @click="activate">
    <div
      :disabled="disabled"
      class="pui-radio"
      :class="[type, size, {
        'checked': computedValue === nativeValue,
      }]"
    >
      <i class="pui-mark"></i>
    </div>
    <span v-if="label">{{ label }}</span>
  </div>
</template>

<script>
export default {
  name: "PRadio",
  props: {
    type: String,
    label: String,
    size: String,
    value: null,
    nativeValue: null,
    disabled: Boolean,
  },
  data() {
    return {
      newValue: this.value
    }
  },
  methods: {
    activate() {
      if (!this.disabled) {
        this.computedValue = this.nativeValue
      }
    }
  },
  computed: {
    computedValue: {
      get() {
        return this.newValue
      },
      set(value) {
        this.newValue = value
        this.$emit('input', value)
      }
    }
  },
  watch: {
    value(value) {
      this.newValue = value
    }
  },
}
</script>