/*! bxs-vue-ui v3.3.0 */
import '../utils/entry-virtual.js';
import { C as create, _ as __vue_normalize__ } from '../utils/normalize-component.js';
import '../utils/sloppy-array-method.js';
import { _ as _indexOfInstanceProperty } from '../utils/index-of.js';
import Icon from '../icon/index.js';
import '../utils/sloppy-array-method2.js';
import '../utils/es.array.join.js';
import Button from '../button/index.js';

var _components;
var script = create({
  name: 'radio',
  components: (_components = {}, _components[Icon.name] = Icon, _components[Button.name] = Button, _components),
  props: {
    name: null,
    value: null,
    type: {
      type: String,
      default: 'icon',
      validator: function validator(str) {
        var _context;

        return _indexOfInstanceProperty(_context = ['icon', 'button']).call(_context, str) !== -1;
      }
    },
    selectColor: {
      type: String,
      default: 'primary'
    },
    disabled: Boolean,
    labelDisabled: Boolean,
    // 即将废弃
    labelPosition: String
  },
  data: function data() {
    return {
      parent: null,
      isCellParent: false
    };
  },
  computed: {
    currentValue: {
      get: function get() {
        return this.parent ? this.parent.value : this.value;
      },
      set: function set(val) {
        this.parent.$emit('input', val);
      }
    },
    isDisabled: function isDisabled() {
      return this.parent ? this.parent.disabled || this.disabled : this.disabled;
    },
    isLabelDisabled: function isLabelDisabled() {
      return this.parent ? this.parent.disabled || this.disabled || this.labelDisabled : this.disabled;
    },
    icon: function icon() {
      return this.name === this.currentValue ? "circle-dot bx-radio-color-" + this.bColor : 'circle';
    },
    cellIcon: function cellIcon() {
      return this.name === this.currentValue ? 'check' : '';
    },
    bColor: function bColor() {
      return this.parent ? this.parent.selectColor || this.selectColor : this.selectColor;
    },
    btnType: function btnType() {
      return this.name === this.currentValue ? this.bColor : 'assist';
    }
  },
  created: function created() {
    this.parent = this.findParent('bxs-radio-group');
    this.isCellParent = this.findParent('bxs-cell');
  },
  methods: {
    handleClick: function handleClick(label) {
      if (this.isDisabled || label === 'label' && this.isLabelDisabled) {
        return;
      }

      this.currentValue = this.name;
    },
    findParent: function findParent(name) {
      var parent = this.$parent;

      while (parent) {
        if (parent.$options.name === name) {
          break;
        }

        parent = parent.$parent;
      }

      return parent;
    }
  }
});

/* script */
var __vue_script__ = script;
/* template */

var __vue_render__ = function __vue_render__() {
  var _vm = this;

  var _h = _vm.$createElement;

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

  return _vm.type === 'icon' ? _c('div', {
    class: ['bx-radio-warp']
  }, [_c('span', {
    staticClass: "bx-radio-icon-warp",
    on: {
      "click": function click($event) {
        _vm.handleClick('radio');
      }
    }
  }, [_vm.isCellParent ? _c('bxs-icon', {
    attrs: {
      "color": _vm.isDisabled ? '#ccc' : '',
      "name": _vm.cellIcon
    }
  }) : _c('bxs-icon', {
    attrs: {
      "color": _vm.isDisabled ? '#ccc' : '',
      "name": _vm.icon
    }
  })], 1), _c('span', {
    staticClass: "bx-radio-text",
    class: [{
      'bx-radio-content--disable': _vm.isDisabled || _vm.isLabelDisabled
    }, _vm.labelPosition],
    on: {
      "click": function click($event) {
        _vm.handleClick('label');
      }
    }
  }, [_vm._t("default")], 2)]) : _vm.type === 'button' ? _c('div', {
    class: ['bx-radio-warp']
  }, [_c('bxs-button', {
    class: [{
      'bx-radio-content--disable': _vm.isDisabled
    }],
    attrs: {
      "plain": "",
      "size": "small",
      "type": _vm.btnType,
      "disabled": _vm.isDisabled
    },
    on: {
      "click": function click($event) {
        _vm.handleClick('radio');
      }
    }
  }, [_vm._t("default")], 2)], 1) : _vm._e();
};

var __vue_staticRenderFns__ = [];
/* style */

var __vue_inject_styles__ = undefined;
/* scoped */

var __vue_scope_id__ = undefined;
/* module identifier */

var __vue_module_identifier__ = undefined;
/* functional template */

var __vue_is_functional_template__ = false;
/* style inject */

/* style inject SSR */

var index = __vue_normalize__({
  render: __vue_render__,
  staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, undefined, undefined);

export default index;
