/*! Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one or more contributor license agreements. * Licensed under the Elastic License 2.0; you may not use this file except in compliance with the Elastic License 2.0. */ (window.stackConnectors_bundle_jsonpfunction=window.stackConnectors_bundle_jsonpfunction||[]).push([[16,34],{30:function(e,t,n){"use strict";n.r(t),n.d(t,"USERNAME_LABEL",(function(){return s})),n.d(t,"PASSWORD_LABEL",(function(){return r})),n.d(t,"FROM_LABEL",(function(){return o})),n.d(t,"SERVICE_LABEL",(function(){return i})),n.d(t,"TENANT_ID_LABEL",(function(){return l})),n.d(t,"CLIENT_ID_LABEL",(function(){return c})),n.d(t,"CLIENT_SECRET_LABEL",(function(){return u})),n.d(t,"HOST_LABEL",(function(){return d})),n.d(t,"PORT_LABEL",(function(){return p})),n.d(t,"SECURE_LABEL",(function(){return E})),n.d(t,"HAS_AUTH_LABEL",(function(){return m})),n.d(t,"SENDER_REQUIRED",(function(){return f})),n.d(t,"CLIENT_ID_REQUIRED",(function(){return x})),n.d(t,"TENANT_ID_REQUIRED",(function(){return b})),n.d(t,"PORT_REQUIRED",(function(){return j})),n.d(t,"PORT_INVALID",(function(){return g})),n.d(t,"SERVICE_REQUIRED",(function(){return O})),n.d(t,"HOST_REQUIRED",(function(){return C})),n.d(t,"USERNAME_REQUIRED",(function(){return R})),n.d(t,"TO_CC_REQUIRED",(function(){return k})),n.d(t,"MESSAGE_REQUIRED",(function(){return L})),n.d(t,"SUBJECT_REQUIRED",(function(){return A})),n.d(t,"PASSWORD_REQUIRED",(function(){return F})),n.d(t,"CLIENT_SECRET_REQUIRED",(function(){return I})),n.d(t,"getInvalidEmailAddress",(function(){return S})),n.d(t,"getNotAllowedEmailAddress",(function(){return T}));var a=n(0);const s=a.i18n.translate("xpack.stackConnectors.components.email.userTextFieldLabel",{defaultMessage:"Username"}),r=a.i18n.translate("xpack.stackConnectors.components.email.passwordFieldLabel",{defaultMessage:"Password"}),o=a.i18n.translate("xpack.stackConnectors.components.email.fromTextFieldLabel",{defaultMessage:"Sender"}),i=a.i18n.translate("xpack.stackConnectors.components.email.serviceTextFieldLabel",{defaultMessage:"Service"}),l=a.i18n.translate("xpack.stackConnectors.components.email.tenantIdFieldLabel",{defaultMessage:"Tenant ID"}),c=a.i18n.translate("xpack.stackConnectors.components.email.clientIdFieldLabel",{defaultMessage:"Client ID"}),u=a.i18n.translate("xpack.stackConnectors.components.email.clientSecretTextFieldLabel",{defaultMessage:"Client Secret"}),d=a.i18n.translate("xpack.stackConnectors.components.email.hostTextFieldLabel",{defaultMessage:"Host"}),p=a.i18n.translate("xpack.stackConnectors.components.email.portTextFieldLabel",{defaultMessage:"Port"}),E=a.i18n.translate("xpack.stackConnectors.components.email.secureSwitchLabel",{defaultMessage:"Secure"}),m=a.i18n.translate("xpack.stackConnectors.components.email.hasAuthSwitchLabel",{defaultMessage:"Require authentication for this server"}),f=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredFromText",{defaultMessage:"Sender is required."}),x=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredClientIdText",{defaultMessage:"Client ID is required."}),b=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredTenantIdText",{defaultMessage:"Tenant ID is required."}),j=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredPortText",{defaultMessage:"Port is required."}),g=a.i18n.translate("xpack.stackConnectors.components.email.error.invalidPortText",{defaultMessage:"Port is invalid."}),O=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredServiceText",{defaultMessage:"Service is required."}),C=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredHostText",{defaultMessage:"Host is required."}),R=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredAuthUserNameText",{defaultMessage:"Username is required."}),k=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredEntryText",{defaultMessage:"No To, Cc, or Bcc entry. At least one entry is required."}),L=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredMessageText",{defaultMessage:"Message is required."}),A=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredSubjectText",{defaultMessage:"Subject is required."}),F=a.i18n.translate("xpack.stackConnectors.components.email.error.requiredPasswordText",{defaultMessage:"Password is required."}),I=a.i18n.translate("xpack.stackConnectors.components.email.requiredClientSecretText",{defaultMessage:"Client Secret is required."});function S(e){return a.i18n.translate("xpack.stackConnectors.components.email.error.invalidEmail",{defaultMessage:"Email address {email} is not valid.",values:{email:e}})}function T(e){return a.i18n.translate("xpack.stackConnectors.components.email.error.notAllowed",{defaultMessage:"Email address {email} is not allowed.",values:{email:e}})}},38:function(e,t,n){"use strict";n.r(t),n.d(t,"EmailActionConnectorFields",(function(){return R})),n.d(t,"nullableString",(function(){return k})),n.d(t,"default",(function(){return R}));var a=n(1),s=n.n(a),r=n(10),o=n(25),i=n(29),l=n(16),c=n(28),u=n(26),d=n(27),p=n(2),E=n(6),m=n(17),f=n(0);const x=(e,t)=>{if(e){if(e===E.a.EXCHANGE)return;return{host:null!=t&&t.host?t.host:"",port:null!=t&&t.port?t.port:0,secure:null!=(null==t?void 0:t.secure)&&t.secure}}};var b=n(30),j=n(9);const{emptyField:g}=c.fieldValidators,O=Object(a.lazy)((()=>n.e(33).then(n.bind(null,117)))),C={label:b.PORT_LABEL,validations:[{validator:g(b.PORT_REQUIRED)},{validator:({value:e})=>{const t=Number.parseFloat(e);if(!Number.isInteger(t))return{message:b.PORT_INVALID}}}]},R=({readOnly:e})=>{const{docLinks:t,http:n,isCloud:c,notifications:{toasts:R}}=Object(p.useKibana)().services,{services:{validateEmailAddresses:k}}=Object(p.useConnectorContext)(),L=Object(u.useFormContext)(),{updateFieldValues:A}=L,[{config:F}]=Object(u.useFormData)({watch:["config.service","config.hasAuth"]}),I=Object(a.useMemo)((()=>{return e=t.links.alerting.emailActionConfig,n=k,{label:b.FROM_LABEL,helpText:Object(j.jsx)(o.EuiLink,{href:e,target:"_blank"},Object(j.jsx)(i.FormattedMessage,{id:"xpack.stackConnectors.components.email.configureAccountsHelpLabel",defaultMessage:"Configure email accounts"})),validations:[{validator:g(b.SENDER_REQUIRED)},{validator:({value:e})=>{const t=n([e])[0];if(!t.valid)return{message:t.reason===l.InvalidEmailReason.notAllowed?b.getNotAllowedEmailAddress(e):b.getInvalidEmailAddress(e)}}}]};var e,n}),[t.links.alerting.emailActionConfig,k]),{service:S=null,hasAuth:T=!1}=null!=F?F:{},v=(e=>Object(r.isEmpty)(e)||e!==E.a.EXCHANGE&&e!==E.a.OTHER)(S),{isLoading:_,getEmailServiceConfig:h}=function({http:e,toasts:t}){const[n,s]=Object(a.useState)(!1),o=Object(a.useRef)(new AbortController),i=Object(a.useRef)(!1),l=Object(a.useCallback)((async n=>{if(null!=n&&!Object(r.isEmpty)(n)){s(!0),i.current=!0,o.current.abort(),o.current=new AbortController;try{const t=await async function({http:e,service:t}){return await e.get(`${E.b}/_email_config/${t}`)}({http:e,service:n});return i.current&&s(!1),x(n,t)}catch(e){var a,l;i.current&&(s(!1),"AbortError"!==e.name&&t.addDanger(null!==(a=null===(l=e.body)||void 0===l?void 0:l.message)&&void 0!==a?a:f.i18n.translate("xpack.stackConnectors.components.email.updateErrorNotificationText",{defaultMessage:"Cannot get service configuration"})))}}}),[e,t]);return Object(a.useEffect)((()=>(i.current=!0,()=>{i.current=!1,o.current.abort()})),[]),{isLoading:n,getEmailServiceConfig:l}}({http:n,toasts:R});return Object(a.useEffect)((()=>{!async function(){if(null===S||S===E.a.OTHER||S===E.a.EXCHANGE)return;const e=await h(S);A({config:{host:null==e?void 0:e.host,port:null==e?void 0:e.port,secure:null==e?void 0:e.secure}})}()}),[A,h,S]),Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(o.EuiFlexGroup,null,Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"config.from",component:d.TextField,config:I,componentProps:{euiFieldProps:{"data-test-subj":"emailFromInput",readOnly:e}}}))),Object(j.jsx)(o.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"config.service",component:d.SelectField,config:{label:b.SERVICE_LABEL,validations:[{validator:g(b.SERVICE_REQUIRED)}]},componentProps:{euiFieldProps:{"data-test-subj":"emailServiceSelectInput",options:Object(m.b)(c),fullWidth:!0,hasNoInitialSelection:!0,disabled:e||_,isLoading:_,readOnly:e}}}))),S===E.a.EXCHANGE?Object(j.jsx)(O,{readOnly:e}):Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(o.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"config.host",component:d.TextField,config:{label:b.HOST_LABEL,validations:[{validator:g(b.HOST_REQUIRED)}]},componentProps:{euiFieldProps:{"data-test-subj":"emailHostInput",readOnly:e,isLoading:_,disabled:v}}})),Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(o.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"config.port",component:d.NumericField,config:C,componentProps:{euiFieldProps:{"data-test-subj":"emailPortInput",readOnly:e,isLoading:_,disabled:v}}})),Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"config.secure",component:d.ToggleField,config:{defaultValue:!1},componentProps:{hasEmptyLabelSpace:!0,euiFieldProps:{label:b.SECURE_LABEL,disabled:e||v,"data-test-subj":"emailSecureSwitch",readOnly:e}}}))))),Object(j.jsx)(o.EuiFlexGroup,null,Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(o.EuiSpacer,{size:"m"}),Object(j.jsx)(o.EuiTitle,{size:"xxs"},Object(j.jsx)("h4",null,Object(j.jsx)(i.FormattedMessage,{id:"xpack.stackConnectors.components.email.authenticationLabel",defaultMessage:"Authentication"}))),Object(j.jsx)(o.EuiSpacer,{size:"s"}),Object(j.jsx)(u.UseField,{path:"config.hasAuth",component:d.ToggleField,config:{defaultValue:!0},componentProps:{euiFieldProps:{label:b.HAS_AUTH_LABEL,disabled:e,readOnly:e}}}))),T?Object(j.jsx)(s.a.Fragment,null,Object(j.jsx)(o.EuiFlexGroup,{justifyContent:"spaceBetween"},Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"secrets.user",component:d.TextField,config:{label:b.USERNAME_LABEL,validations:[{validator:g(b.USERNAME_REQUIRED)}]},componentProps:{euiFieldProps:{"data-test-subj":"emailUserInput",readOnly:e}}})),Object(j.jsx)(o.EuiFlexItem,null,Object(j.jsx)(u.UseField,{path:"secrets.password",config:{label:b.PASSWORD_LABEL,validations:[{validator:g(b.PASSWORD_REQUIRED)}]},component:d.PasswordField,componentProps:{euiFieldProps:{readOnly:e,"data-test-subj":"emailPasswordInput"}}})))):null))};function k(e){return null==e||""===e.trim()?null:e}}}]);