"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _toConsumableArray2=require("babel-runtime/helpers/toConsumableArray"),_toConsumableArray3=_interopRequireDefault(_toConsumableArray2),_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),_Checkbox=require("./Checkbox"),_Checkbox2=_interopRequireDefault(_Checkbox);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var CheckboxGroup=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var l=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return l.toggleOption=function(e){var t=l.state.value.indexOf(e.value),r=[].concat((0,_toConsumableArray3.default)(l.state.value));-1===t?r.push(e.value):r.splice(t,1),"value"in l.props||l.setState({value:r});var a=l.props.onChange;a&&a(r)},l.state={value:e.value||e.defaultValue||[]},l}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"getChildContext",value:function(){return{checkboxGroup:{toggleOption:this.toggleOption,value:this.state.value,disabled:this.props.disabled}}}},{key:"componentWillReceiveProps",value:function(e){"value"in e&&this.setState({value:e.value||[]})}},{key:"shouldComponentUpdate",value:function(e,t){return!(0,_shallowequal2.default)(this.props,e)||!(0,_shallowequal2.default)(this.state,t)}},{key:"getOptions",value:function(){return this.props.options.map(function(e){return"string"==typeof e?{label:e,value:e}:e})}},{key:"render",value:function(){var t=this,r=this.props,a=this.state,l=r.prefixCls,e=r.className,s=r.style,u=r.options,o=r.children;u&&0<u.length&&(o=this.getOptions().map(function(e){return React.createElement(_Checkbox2.default,{key:e.value,disabled:"disabled"in e?e.disabled:r.disabled,value:e.value,checked:-1!==a.value.indexOf(e.value),onChange:function(){return t.toggleOption(e)},className:l+"-item"},e.label)}));var i=(0,_classnames2.default)(l,e);return React.createElement("div",{className:i,style:s},o)}}]),t}(React.Component);(exports.default=CheckboxGroup).defaultProps={options:[],prefixCls:"dt-checkbox-group"},CheckboxGroup.propTypes={defaultValue:PropTypes.array,value:PropTypes.array,options:PropTypes.array.isRequired,onChange:PropTypes.func},CheckboxGroup.childContextTypes={checkboxGroup:PropTypes.any},module.exports=exports.default;