"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 _objectSpread3=_interopRequireDefault(require("@babel/runtime/helpers/objectSpread")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf3=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),React=_interopRequireWildcard(require("react")),_propTypes=_interopRequireDefault(require("prop-types")),_reactTippy=require("react-tippy"),_formik=require("formik"),_isEmpty=_interopRequireDefault(require("lodash/isEmpty")),Yup=_interopRequireWildcard(require("yup")),_ButtonBase=_interopRequireDefault(require("@material-ui/core/ButtonBase")),_withStyles=_interopRequireDefault(require("../../hoc/withStyles")),_ErrorBoundary=_interopRequireDefault(require("../../hoc/ErrorBoundary")),_TextField=_interopRequireDefault(require("../../bosons/TextField")),_Button=_interopRequireDefault(require("../../bosons/Button")),_FieldLabel=_interopRequireDefault(require("../../bosons/FieldLabel")),_styles=_interopRequireDefault(require("./styles")),EmailInputFields=/*#__PURE__*/function(_React$Component){function EmailInputFields(){return(0,_classCallCheck2.default)(this,EmailInputFields),(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf3.default)(EmailInputFields).apply(this,arguments))}return(0,_inherits2.default)(EmailInputFields,_React$Component),(0,_createClass2.default)(EmailInputFields,[{key:"_renderToField",value:function _renderToField(){var _this=this;return React.createElement(EmailInputField,{label:"To",onEmailChange:function onEmailChange(emails){_this.props.onEmailChange({to:emails})}})}},{key:"_renderCCField",value:function _renderCCField(){var _this2=this;return React.createElement(EmailInputField,{label:"CC",onEmailChange:function onEmailChange(emails){_this2.props.onEmailChange({cc:emails})}})}},{key:"_renderBCCField",value:function _renderBCCField(){var _this3=this;return React.createElement(EmailInputField,{label:"BCC",onEmailChange:function onEmailChange(emails){_this3.props.onEmailChange({bcc:emails})}})}},{key:"render",value:function render(){var _this$props=this.props,classes=_this$props.classes,showTo=_this$props.showTo,showCC=_this$props.showCC,showBCC=_this$props.showBCC;return React.createElement(_ErrorBoundary.default,null,React.createElement("div",{className:classes.component},showTo&&this._renderToField(),showCC&&this._renderCCField(),showBCC&&this._renderBCCField()))}}]),EmailInputFields}(React.Component);(0,_defineProperty2.default)(EmailInputFields,"propTypes",{classes:_propTypes.default.object,// will come from withStyles HOC
onEmailChange:_propTypes.default.func,showTo:_propTypes.default.bool,showBCC:_propTypes.default.bool,showCC:_propTypes.default.bool}),(0,_defineProperty2.default)(EmailInputFields,"defaultProps",{onEmailChange:function onEmailChange(){},showTo:!0,showCC:!0,showBCC:!0});var _default=(0,_withStyles.default)(_styles.default)(EmailInputFields);exports.default=_default;var BaseEmailInputField=/*#__PURE__*/function(_React$Component2){function BaseEmailInputField(){var _getPrototypeOf2,_this4;(0,_classCallCheck2.default)(this,BaseEmailInputField);for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return _this4=(0,_possibleConstructorReturn2.default)(this,(_getPrototypeOf2=(0,_getPrototypeOf3.default)(BaseEmailInputField)).call.apply(_getPrototypeOf2,[this].concat(args))),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this4)),"addEmailForm",void 0),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this4)),"state",{emails:{}}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this4)),"_onAddEmail",function(values){var emails=_this4.state.emails;_this4.setState({emails:(0,_objectSpread3.default)({},emails,(0,_defineProperty2.default)({},values.email,{name:values.name,email:values.email}))},function(){_this4.addEmailForm.resetForm({name:"",email:""}),_this4.props.onEmailChange(Object.values(_this4.state.emails))})}),(0,_defineProperty2.default)((0,_assertThisInitialized2.default)((0,_assertThisInitialized2.default)(_this4)),"_onRemoveEmail",function(_ref){var name=_ref.name,email=_ref.email,emails=_this4.state.emails,newEmails=emails;delete newEmails[email],_this4.setState({emails:newEmails},function(){_this4.props.onEmailChange(Object.values(_this4.state.emails))})}),_this4}return(0,_inherits2.default)(BaseEmailInputField,_React$Component2),(0,_createClass2.default)(BaseEmailInputField,[{key:"render",value:function render(){var _this5=this,_this$props2=this.props,classes=_this$props2.classes,label=_this$props2.label,emails=this.state.emails;return React.createElement("div",{className:classes.emailInputField},React.createElement(_FieldLabel.default,{label:label}),!(0,_isEmpty.default)(emails)&&React.createElement("div",{className:classes.listEmails},Object.values(emails).map(function(email,index){return React.createElement("div",{className:classes.addedEmailWrapper,key:index},React.createElement(_reactTippy.Tooltip,{title:email.email,interactive:!0,animation:"fade",position:"top",arrow:!0,arrowType:"round",trigger:"mouseenter focus"},React.createElement("div",{className:classes.addedEmail},email.name)),React.createElement(_ButtonBase.default,{classes:{root:classes.removeEmailIcon},onClick:function onClick(){_this5._onRemoveEmail(email)}},React.createElement("i",{className:"fa fa-times"})))})),React.createElement("div",{className:classes.emailInput},React.createElement(_formik.Formik,{ref:function ref(_ref2){return _this5.addEmailForm=_ref2},initialValues:{name:"",email:""},validationSchema:Yup.object({email:Yup.string().required("Email is required").email("Email is not valid"),name:Yup.string().required("Name is required")}),onSubmit:this._onAddEmail},function(formProps){return React.createElement("form",{className:classes.addEmailForm,onSubmit:formProps.handleSubmit},React.createElement(_TextField.default,{placeholder:"Name",classes:{component:classes.textInput},value:formProps.values.name,error:formProps.touched.name&&formProps.errors.name,onChange:formProps.handleChange,onBlur:formProps.handleBlur,name:"name"}),React.createElement(_TextField.default,{placeholder:"Email",classes:{component:classes.textInput},value:formProps.values.email,error:formProps.touched.email&&formProps.errors.email,onChange:formProps.handleChange,onBlur:formProps.handleBlur,name:"email"}),React.createElement(_Button.default,{title:"\u2713",type:"submit",isDisabled:!!(formProps.touched.name&&formProps.errors.name)||!!(formProps.touched.email&&formProps.errors.email),classes:{component:classes.addEmailButton}}))})))}}]),BaseEmailInputField}(React.Component);(0,_defineProperty2.default)(BaseEmailInputField,"propTypes",{classes:_propTypes.default.object,// will come from withStyles HOC
onEmailChange:_propTypes.default.func,label:_propTypes.default.string});var EmailInputField=(0,_withStyles.default)(_styles.default)(BaseEmailInputField);