"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _create = _interopRequireDefault(require("../utils/create"));

var _findParent = _interopRequireDefault(require("../mixins/find-parent"));

var _unit = require("../utils/format/unit");

var _default = (0, _create.default)({
  render: function render() {
    var _vm = this;

    var _h = _vm.$createElement;

    var _c = _vm._self._c || _h;

    return _c('div', {
      class: _vm.b(_vm.direction)
    }, [_c('div', {
      class: _vm.b('icon', [_vm.shape, {
        disabled: _vm.isDisabled,
        checked: _vm.checked
      }]),
      style: {
        fontSize: _vm.addUnits(_vm.iconSizeC)
      },
      on: {
        "click": function click($event) {
          $event.stopPropagation();
          return _vm.onClickLabel($event);
        }
      }
    }, [_vm._t("icon", [_c('icon', {
      style: _vm.iconStyle,
      attrs: {
        "name": "check"
      }
    })], {
      "checked": _vm.checked
    })], 2), _vm.$slots.default ? _c('span', {
      class: _vm.b('label', [{
        disabled: _vm.isDisabled
      }]),
      on: {
        "click": function click($event) {
          return _vm.onClickLabel('label');
        }
      }
    }, [_vm._t("default")], 2) : _vm._e()]);
  },
  name: 'radio',
  mixins: [_findParent.default],
  props: {
    name: null,
    value: null,
    disabled: Boolean,
    checkedColor: String,
    iconSize: [Number, String],
    labelDisabled: Boolean,
    shape: {
      type: String,
      default: 'round'
    }
  },
  computed: {
    iconSizeC: function iconSizeC() {
      return this.parent && this.parent.iconSize || this.iconSize;
    },
    currentValue: {
      get: function get() {
        return this.parent ? this.parent.value : this.value;
      },
      set: function set(val) {
        (this.parent || this).$emit('input', val);
      }
    },
    checked: function checked() {
      return this.currentValue === this.name;
    },
    isDisabled: function isDisabled() {
      return this.parent && this.parent.disabled || this.disabled;
    },
    iconStyle: function iconStyle() {
      var checkedColor = this.parent && this.parent.checkedColor || this.checkedColor;

      if (checkedColor && this.checked && !this.isDisabled) {
        return {
          borderColor: checkedColor,
          backgroundColor: checkedColor
        };
      }
    },
    direction: function direction() {
      return this.parent && this.parent.direction || null;
    }
  },
  created: function created() {
    this.findParent('vm-radio-group');
  },
  methods: {
    addUnits: function addUnits(val) {
      return (0, _unit.addUnit)(val);
    },
    onClickLabel: function onClickLabel(target) {
      this.$emit('click');

      if (!this.isDisabled && !(target === 'label' && this.labelDisabled)) {
        this.currentValue = this.name;
      }
    }
  }
});

exports.default = _default;