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AQ,mBACtDC,EAAU,WAAHrD,OAAcmD,EAAc,qCAAAnD,OAAoCkD,EAAY,6BAAAlD,OAA4BnB,KAAKF,OAAO2E,eACjIxE,EAAAA,KAAO,CACLyE,IAAKF,EACLG,OAAQ,OACRC,SAAU,OACVC,SAAQ,SAACC,EAAOC,GACK,YAAfA,GACFX,EAAKjB,gBACLiB,EAAKtE,OAAO6D,YAAcS,EAAKR,WAAaQ,EAAKP,eAGA,IAA7C5D,EAAE,iBAAkBmE,EAAKvE,SAASiE,QACpCM,EAAKjE,KAAK6E,OAAO,oCAAsCZ,EAAKtE,OAAOiD,YAAc,SAGvF,GAEJ,GAAC,CAAAxB,IAAA,WAAAC,MAED,WACEyD,OAAOC,SAASC,KAAOnF,KAAKF,OAAO6D,WACrC,GAAC,CAAApC,IAAA,cAAAC,MAED,WACExB,KAAKG,KAAKiF,OACVpF,KAAKK,QAAQgF,YAAY,YAKA,oBAAdC,WAGTA,UAAUC,KAAK,CAAE,MAAS,0BAE9B,M,oEAAC3F,CAAA,CAhKmC,E","sources":["webpack:///./resources/js/components/generic/exact-target-formV2.ts"],"sourcesContent":["import * as $ from \"jquery\";\nimport { ConsentHelper } from '../../common/ConsentHubV2';\nimport Environment from \"../../common/environment\";\nimport imkt from '../../imkt';\nimport 'jquery-validation';\nimport '@types/jquery.validation';\n\ntype RulesType = {\n  [key: string]: {\n    required: boolean;\n    email: boolean;\n  }\n};\n\ntype MessagesType = {\n  [key: string]: {\n    required: string;\n    email: string;\n  }\n};\n\nexport default class ExactTargetFormV2 {\n  domRoot: JQuery<HTMLElement>;\n  params: {\n    consentYes: any;\n    isEAP: any;\n    useGdpr: boolean;\n    subscriptionKey: any;\n    useSubmissionBlock: string;\n    postSubmissionBlockId: any;\n    requiredError: string;\n    invalidEmailError: string;\n    redirectUrl: any;\n    submitError: string;\n    exactTargetId: any;\n    name: string;\n    useSocs: boolean;\n  };\n  form: JQuery<HTMLElement>;\n  emailInput: JQuery<HTMLElement>;\n  message: JQuery<HTMLElement>;\n  honeypot: JQuery<HTMLElement>;\n  useSocs: boolean;\n  consentHubPromise?: Promise<any>;\n  consentYes: any;\n  useConsentHub: any;\n  useSubmissionBlock: boolean;\n  postSubmissionBlock: any;\n\n  constructor(domRoot: HTMLElement, params: any) {\n    this.domRoot = $(domRoot);\n    this.params = { ...params };\n\n    //Component elements\n    this.form = $('.exact-target-form', this.domRoot);\n    this.emailInput = $('.exact-target-form__email-input input', this.domRoot);\n    this.message = $('.exact-target-form__message', this.domRoot);\n    this.honeypot = $('.exact-target-form__hp-field input', this.domRoot);\n    this.useSocs = params.useSocs;\n    this.consentYes = this.params.consentYes;\n    this.useConsentHub = this.consentYes.match('generalMarketingOptIn|allowPartnerShare') || this.params.isEAP || (this.params.useGdpr && this.params.subscriptionKey.trim() !== '');\n    this.useSubmissionBlock = this.params.useSubmissionBlock === 'true';\n    this.postSubmissionBlock = this.useSubmissionBlock && document.querySelectorAll(`#${this.params.postSubmissionBlockId}, .${this.params.postSubmissionBlockId}`);\n\n    if (this.useConsentHub) {\n      this.init();\n    } else {\n      this.bindFormValidation();\n    }\n  }\n\n  init() {\n    this.consentHubPromise = (new ConsentHelper(this.params, this.form)).configPromise;\n    this.bindFormValidation();\n  }\n\n  bindFormValidation() {\n\n    // Bind validation rules to our form using jQuery Validate functions\n    $.validator.methods.email = function( value, element ) {\n      return this.optional( element ) || /.+\\@.+\\..+/.test( value );\n    }\n\n    const rules: RulesType = {};\n    const messages: MessagesType = {};\n    rules[this.params.name] = {\n      required: true,\n      email: true\n    };\n    messages[this.params.name] = {\n      required: this.params.requiredError,\n      email: this.params.invalidEmailError\n    };\n    this.form.validate({\n      rules: rules,\n      messages: messages,\n      submitHandler: () => {\n        if (this.honeypot.val() === \"\") {\n          if (this.useConsentHub) {\n            this.consentHubPromise.then((consentHub: ConsentHelper) => {\n              consentHub.submitForm(this.submitSuccess.bind(this), this.submitError.bind(this));\n            }).catch((error: unknown) => {\n              console.error(error);\n              this.submitError();\n            });\n          } else {\n            this.submitDirectlyToExactTarget();\n          }\n        }\n      }\n    });\n  }\n\n  submitSuccess() {\n    this.setSocsCookie();\n    if (this.useSubmissionBlock) {\n      // hide Form\n      this.form.css('display', 'none');\n      // show post submission content block\n      if (this.postSubmissionBlock) {\n        const postSubmissionBlocks = Array.from(document.querySelectorAll(`#${this.params.postSubmissionBlockId}, .${this.params.postSubmissionBlockId}`));\n        postSubmissionBlocks.forEach(psb => {\n          (psb as HTMLElement).style.display = 'block';\n        })\n      }\n    } else {\n      this.params.redirectUrl ? this.redirect() : this.showMessage();\n    }\n  }\n\n  submitError() {\n    if ($('.error--server', this.domRoot).length === 0) {\n      this.form.after('<div class=\"error error--server\">' + this.params.submitError + '</div>');\n    }\n  }\n\n  setSocsCookie() {\n    if (this.useSocs) {\n      imkt.utils?.storage.setCookie(\"atl_soc2_nda_signed\", 1, false, \"Strict\", \"atlassian.com\");\n    }\n  }\n\n  submitDirectlyToExactTarget() {\n    const self = this;\n    const emailAddress = this.emailInput.val();\n    const endpointDomain = Environment.isProduction() ? 'www' : 'wac.stg.internal';\n    const postUrl = `https://${endpointDomain}.atlassian.com/apis/exact-target/${emailAddress}/subscribe?mailingListId=${this.params.exactTargetId}`;\n    $.ajax({\n      url: postUrl,\n      method: \"POST\",\n      dataType: \"text\",\n      complete(jqXHR, textStatus) {\n        if (textStatus === 'success') {\n          self.setSocsCookie();\n          self.params.redirectUrl ? self.redirect() : self.showMessage();\n        } else {\n          // did not submit successfully, if there is not an error then show one\n          if ($('.error--server', self.domRoot).length === 0) {\n            self.form.append('<div class=\"error error--server\">' + self.params.submitError + '</div>');\n          }\n        }\n      }\n    });\n  }\n\n  redirect() {\n    window.location.href = this.params.redirectUrl;\n  }\n\n  showMessage() {\n    this.form.hide();\n    this.message.removeClass('hide-all');\n\n    // TODO: Is this behavior in use, can this be removed or scoped to a type?\n    // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n    // @ts-ignore\n    if (typeof dataLayer !== \"undefined\") {\n      // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n      // @ts-ignore\n      dataLayer.push({ 'event': 'emailSubmissionSuccess' });\n    }\n  }\n}\n"],"names":["ExactTargetFormV2","domRoot","params","_classCallCheck","this","$","_objectSpread","form","emailInput","message","honeypot","useSocs","consentYes","useConsentHub","match","isEAP","useGdpr","subscriptionKey","trim","useSubmissionBlock","postSubmissionBlock","document","querySelectorAll","concat","postSubmissionBlockId","init","bindFormValidation","key","value","consentHubPromise","ConsentHelper","configPromise","_this","element","optional","test","rules","messages","name","required","email","requiredError","invalidEmailError","validate","submitHandler","val","then","consentHub","submitForm","submitSuccess","bind","submitError","error","console","submitDirectlyToExactTarget","setSocsCookie","css","Array","from","forEach","psb","style","display","redirectUrl","redirect","showMessage","length","after","_imkt$utils","imkt","storage","setCookie","self","emailAddress","endpointDomain","Environment","postUrl","exactTargetId","url","method","dataType","complete","jqXHR","textStatus","append","window","location","href","hide","removeClass","dataLayer","push"],"sourceRoot":""}