"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")),_classnames=_interopRequireDefault(require("classnames")),_propTypes=_interopRequireDefault(require("prop-types")),_Switch=_interopRequireDefault(require("@material-ui/core/Switch")),_withStyles=_interopRequireDefault(require("../../hoc/withStyles")),_ErrorBoundary=_interopRequireDefault(require("../../hoc/ErrorBoundary")),_styles=_interopRequireDefault(require("./styles")),ToggleSwitch=/*#__PURE__*/function(_React$Component){function ToggleSwitch(props){var _this;return(0,_classCallCheck2.default)(this,ToggleSwitch),_this=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(ToggleSwitch).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)),"_handleChange",function(event,checked){_this.setState({value:checked}),_this.props.onChange&&_this.props.onChange(checked)}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this)),"_renderSwitch",function(){var _this$props=_this.props,classes=_this$props.classes,offLabel=_this$props.offLabel,onLabel=_this$props.onLabel;return React.createElement("div",{className:classes.toggleSwitchWrapper,"data-test":"toggle-switch".concat(_this.state.value?"-checked":"")},React.createElement(_Switch.default,{checked:_this.state.value,classes:{root:classes.root,icon:classes.icon,bar:classes.bar,checked:classes.checked},disabled:_this.props.disabled,onChange:_this._handleChange}),!_this.state.value&&React.createElement("div",{className:classes.offLabel},offLabel),_this.state.value&&React.createElement("div",{className:classes.onLabel},onLabel))}),_this.state={value:props.value},_this}return(0,_inherits2.default)(ToggleSwitch,_React$Component),(0,_createClass2.default)(ToggleSwitch,[{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){var props=this.props;props.value!==prevProps.value&&this.setState({value:props.value})}},{key:"_renderLabel",value:function _renderLabel(){var _this$props2=this.props,classes=_this$props2.classes,label=_this$props2.label;return React.createElement("div",{className:classes.label},label)}},{key:"render",value:function render(){var _this$props3=this.props,classes=_this$props3.classes,label=_this$props3.label,componentClass=(0,_classnames.default)(classes.switchComponent);return React.createElement(_ErrorBoundary.default,null,React.createElement("div",{className:componentClass},!!label&&this._renderLabel(),this._renderSwitch()))}}]),ToggleSwitch}(React.Component);(0,_defineProperty2.default)(ToggleSwitch,"propTypes",{offLabel:_propTypes.default.string,offColor:_propTypes.default.string,onLabel:_propTypes.default.string,onColor:_propTypes.default.string,onChange:_propTypes.default.func,disabled:_propTypes.default.bool,value:_propTypes.default.bool,label:_propTypes.default.string,compact:_propTypes.default.bool,classes:_propTypes.default.object,theme:_propTypes.default.any,name:_propTypes.default.string}),(0,_defineProperty2.default)(ToggleSwitch,"defaultProps",{offLabel:"OFF",onLabel:"ON",onChange:function onChange(){},value:!1});var _default=(0,_withStyles.default)(_styles.default)(ToggleSwitch);exports.default=_default;