"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),React=_interopRequireWildcard(require("react")),_types=require("./types"),_propTypes=_interopRequireDefault(require("prop-types")),_classnames=_interopRequireDefault(require("classnames")),_withStyles=_interopRequireDefault(require("../../hoc/withStyles")),_ErrorBoundary=_interopRequireDefault(require("../../hoc/ErrorBoundary")),_helpers=require("../../helpers"),_styles=_interopRequireDefault(require("./styles")),CheckBox=/*#__PURE__*/function(_React$Component){function CheckBox(props){var _this;return(0,_classCallCheck2.default)(this,CheckBox),_this=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(CheckBox).call(this,props)),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"changeValue",function(value){_this.setState({value:value}),_this.props.onChange&&_this.props.onChange(value)}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"_toggleValue",function(){var newValue=!_this.state.value;_this.setState({value:newValue}),_this.props.onChange&&_this.props.onChange(newValue)}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"_renderCheckbox",function(){var _this$props=_this.props,classes=_this$props.classes,label=_this$props.label,disabled=_this$props.disabled,id=_this$props.id;return React.createElement("div",{id:id+"-checkbox",className:(0,_classnames.default)(classes.wrapper,{disabled:disabled}),onClick:_this._toggleValue},React.createElement("div",{className:(0,_classnames.default)(classes.checkbox,{checked:_this.state.value})},_this.state.value&&React.createElement("i",{className:(0,_classnames.default)("icon icon-tick",classes.tickIcon)})),!!label&&React.createElement("div",{className:(0,_classnames.default)(classes.label)},label))}),_this.state={value:props.value},_this}return(0,_inherits2.default)(CheckBox,_React$Component),(0,_createClass2.default)(CheckBox,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){this.props.value!==prevProps.value&&this.setState({value:this.props.value})}},{key:"render",value:function render(){var _this$props2=this.props,classes=_this$props2.classes,error=_this$props2.error,id=_this$props2.id;return React.createElement(_ErrorBoundary.default,null,React.createElement("div",{className:(0,_classnames.default)(classes.component),id:id},this._renderCheckbox(),!!error&&React.createElement("div",{id:id+"-error",className:(0,_classnames.default)(classes.error)},error)))}}]),CheckBox}(React.Component);(0,_defineProperty2.default)(CheckBox,"propTypes",{name:_propTypes.default.string,label:_propTypes.default.node,color:_propTypes.default.string,error:_propTypes.default.string,size:_propTypes.default.any,onChange:_propTypes.default.func,disabled:_propTypes.default.bool,value:_propTypes.default.bool,classes:_propTypes.default.object,theme:_propTypes.default.any,id:_propTypes.default.string}),(0,_defineProperty2.default)(CheckBox,"defaultProps",{label:"",onChange:function onChange(){},disabled:!1,value:!1,size:_types.CheckboxSize.large,id:"checkbox-".concat((0,_helpers.randomNumber)())});var _default=(0,_withStyles.default)(_styles.default)(CheckBox);exports.default=_default;