"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _defineProperty2=require("babel-runtime/helpers/defineProperty"),_defineProperty3=_interopRequireDefault(_defineProperty2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_propTypes=require("prop-types"),PropTypes=_interopRequireWildcard(_propTypes),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_shallowequal=require("shallowequal"),_shallowequal2=_interopRequireDefault(_shallowequal),_radio=require("./radio"),_radio2=_interopRequireDefault(_radio);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var a={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(a[r]=e[r]);return a.default=e,a}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getCheckedValue(e){var a=null,r=!1;return React.Children.forEach(e,function(e){e&&e.props&&e.props.checked&&(a=e.props.value,r=!0)}),r?{value:a}:void 0}var RadioGroup=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var l=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));l.onRadioChange=function(e){var a=l.state.value,r=e.target.value;"value"in l.props||l.setState({value:r});var t=l.props.onChange;t&&r!==a&&t(e)};var a=void 0;if("value"in e)a=e.value;else if("defaultValue"in e)a=e.defaultValue;else{var r=getCheckedValue(e.children);a=r&&r.value}return l.state={value:a},l}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"getChildContext",value:function(){return{radioGroup:{onChange:this.onRadioChange,value:this.state.value,disabled:this.props.disabled,name:this.props.name}}}},{key:"componentWillReceiveProps",value:function(e){if("value"in e)this.setState({value:e.value});else{var a=getCheckedValue(e.children);a&&this.setState({value:a.value})}}},{key:"shouldComponentUpdate",value:function(e,a){return!(0,_shallowequal2.default)(this.props,e)||!(0,_shallowequal2.default)(this.state,a)}},{key:"render",value:function(){var r=this,e=this.props,a=e.prefixCls,t=void 0===a?"dt-radio-group":a,l=e.className,s=void 0===l?"":l,i=e.options,u=(0,_classnames2.default)(t,(0,_defineProperty3.default)({},t+"-"+e.size,e.size),s),o=e.children;return i&&0<i.length&&(o=i.map(function(e,a){return"string"==typeof e?React.createElement(_radio2.default,{key:a,disabled:r.props.disabled,value:e,onChange:r.onRadioChange,checked:r.state.value===e},e):React.createElement(_radio2.default,{key:a,disabled:e.disabled||r.props.disabled,value:e.value,onChange:r.onRadioChange,checked:r.state.value===e.value},e.label)})),React.createElement("div",{className:u,style:e.style,onMouseEnter:e.onMouseEnter,onMouseLeave:e.onMouseLeave,id:e.id},o)}}]),t}(React.Component);(exports.default=RadioGroup).defaultProps={disabled:!1},RadioGroup.childContextTypes={radioGroup:PropTypes.any},module.exports=exports.default;