<template>
  <label
    class="radio_text"
    :class="[
      isDisabled && 'disabled'
    ]"
  >
    <input
      class="radioInput"
      type="radio"
      :checked="isChecked"
      :disabled="isDisabled"
      :name="name"
      @change="onChange"
    >
    <span class="radioLabel">
      {{ label }}
    </span>
  </label>
</template>

<script>
export default {
  name: 'Radio',
  props: {
    value: {
      type: [String, Number],
    },
    name: {
      type: String,
    },
    label: {
      type: String,
    },
    isChecked: {
      type: Boolean,
      default: false,
    },
    isDisabled: {
      type: Boolean,
      default: false,
    },
    onChange: {
      type: Function,
      default: function() {},
    },
  },
}
</script>

<style lang="scss" scoped>
@import '../const/variable.scss';

/*Radio Check*/
label.radio_text {
  position: relative;
  cursor: pointer;
  display: inline-block;
  overflow: hidden;
  box-sizing: border-box;
  min-height: calc(18px + 5px);
  margin-right: 10px;
  padding-left: calc(18px + 5px);
  line-height: calc(18px + 5px);
}
label.disabled {
  cursor: default;
  opacity: 0.4;
}

/** input **/
label.radio_text input[type='radio'] {
  -moz-appearance: none;
  -webkit-appearance: none;
  position: absolute;
  z-index: 2;
  margin: 0px;
  box-sizing: border-box;
  outline: none;
  left: 0;
  width: 18px;
  height: 18px;
  top: 0px;
  bottom: 0px;
  margin-top: auto;
  margin-bottom: auto;
  border-radius: 100%;

  &:before,
  &:after {
    content: '';
    position: absolute;
    box-sizing: border-box;
    top: 0px;
    bottom: 0px;
    margin-top: auto;
    margin-bottom: auto;
    border-radius: 100%;
  }

  &:before {
    width: 18px;
    height: 18px;
    border: 1px solid palette(gray, base);
    left: 0px;
    z-index: 3;
  }

  &:after {
    width: 10px;
    height: 10px;
    left: calc(18px / 2 - 10px / 2);
    background-color: palette(blue, base);
    transform: scale(0);
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    z-index: 1;
  }

  &:hover {
    &:before {
      border: 1px solid palette(blue, base);
    }
  }
  &:checked {
    box-shadow: none;
    &:after {
      transform: scale(1);
    }
  }
  &:disabled {
    &:hover {
      &:before {
        border: 1px solid palette(gray, base);
      }
    }
  }
}
</style>
