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hC,IACf,IAAIF,EAAME,EAAK,GACjB,G,IC5Ic,M","sources":["webpack://modularity/./source/php/Module/Subscribe/assets/ungapd.ts","webpack://modularity/webpack/startup"],"sourcesContent":["\"use strict\";\nvar __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nclass Ungpd {\n constructor(form) {\n Object.defineProperty(this, \"form\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"id\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"notices\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: []\n });\n Object.defineProperty(this, \"successTemplate\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: null\n });\n Object.defineProperty(this, \"errorTemplate\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: null\n });\n Object.defineProperty(this, \"consent\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n Object.defineProperty(this, \"email\", {\n enumerable: true,\n configurable: true,\n writable: true,\n value: void 0\n });\n this.form = form;\n this.id = form.getAttribute('id') || '';\n this.email = this.form.querySelector('input[name=\"email\"]');\n this.consent = this.form.querySelector('input[name=\"user_consent\"]');\n this.successTemplate = document.querySelector(`template[id=\"${this.id}-success\"]`);\n this.errorTemplate = document.querySelector(`template[id=\"${this.id}-error\"]`);\n this.setupEventListener();\n }\n handleSuccess() {\n var _a, _b;\n const successElement = (_a = this.successTemplate) === null || _a === void 0 ? void 0 : _a.content.cloneNode(true);\n if ((_b = this.successTemplate) === null || _b === void 0 ? void 0 : _b.parentNode) {\n this.notices.push(this.successTemplate.parentNode.appendChild(successElement));\n }\n }\n handleError(message) {\n var _a, _b;\n const errorElement = (_a = this.errorTemplate) === null || _a === void 0 ? void 0 : _a.content.cloneNode(true);\n const messageElement = errorElement === null || errorElement === void 0 ? void 0 : errorElement.querySelector('.message');\n if (messageElement) {\n messageElement.innerHTML = message.toString();\n }\n if ((_b = this.errorTemplate) === null || _b === void 0 ? void 0 : _b.parentNode) {\n this.notices.push(this.errorTemplate.parentNode.appendChild(errorElement));\n }\n }\n clearNotices() {\n this.notices.forEach(notice => { var _a; return (_a = notice.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(notice); });\n }\n setupEventListener() {\n this.form.addEventListener(\"submit\", this.handleFormSubmit.bind(this));\n }\n handleFormSubmit(event) {\n return __awaiter(this, void 0, void 0, function* () {\n event.preventDefault();\n this.clearNotices();\n const subscription = this.subscriptionData();\n try {\n yield this.submitSubscription(subscription);\n this.handleSuccess();\n }\n catch (error) {\n this.handleError(error.message);\n }\n });\n }\n subscriptionData() {\n const listIds = this.form.getAttribute('data-js-ungpd-list-ids');\n const doubleOptInIssueId = this.form.getAttribute('data-js-ungpd-double-opt-in-issue-id');\n const confirmationIssueId = this.form.getAttribute('data-js-ungpd-confirmation-issue-id');\n const subscriptionConfirmedUrl = this.form.getAttribute('data-js-ungpd-subscription-confirmed-url');\n const subscriptionFailedUrl = this.form.getAttribute('data-js-ungpd-subscription-failed-url');\n const lists = listIds ? listIds.split(\",\").map((listId) => listId.trim()) : [];\n const subscription = {\n Contact: { Email: this.email.value },\n ConsentText: this.consent.value,\n ListIds: lists\n };\n if (doubleOptInIssueId)\n subscription.DoubleOptIn = { Issue: { IssueId: doubleOptInIssueId } };\n if (confirmationIssueId)\n subscription.ConfirmationIssue = { IssueId: confirmationIssueId };\n if (subscriptionConfirmedUrl)\n subscription.SubscriptionConfirmedUrl = subscriptionConfirmedUrl;\n if (subscriptionFailedUrl)\n subscription.SubscriptionFailedUrl = subscriptionFailedUrl;\n return subscription;\n }\n submitSubscription(subscription) {\n return __awaiter(this, void 0, void 0, function* () {\n const accountId = this.form.getAttribute('data-js-ungpd-id');\n const response = yield fetch(\"https://ui.ungpd.com/Api/Subscriptions/\" + accountId, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\"\n },\n body: JSON.stringify(subscription)\n });\n if (!response.ok) {\n throw new Error(`Failed to subscribe: ${response.status}`);\n }\n this.consent.checked = false;\n this.email.value = \"\";\n });\n }\n}\ndocument.addEventListener(\"DOMContentLoaded\", () => {\n const ungpdForms = [...document.querySelectorAll(\"[data-js-ungpd-id]\")];\n ungpdForms.forEach(form => {\n new Ungpd(form);\n });\n});\n","// startup\n// Load entry module and return exports\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = {};\n__webpack_modules__[460]();\n"],"names":["__awaiter","this","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","value","step","next","e","rejected","result","done","then","apply","Ungpd","constructor","form","Object","defineProperty","enumerable","configurable","writable","id","getAttribute","email","querySelector","consent","successTemplate","document","errorTemplate","setupEventListener","handleSuccess","_a","_b","successElement","content","cloneNode","parentNode","notices","push","appendChild","handleError","message","errorElement","messageElement","innerHTML","toString","clearNotices","forEach","notice","removeChild","addEventListener","handleFormSubmit","bind","event","preventDefault","subscription","subscriptionData","submitSubscription","error","listIds","doubleOptInIssueId","confirmationIssueId","subscriptionConfirmedUrl","subscriptionFailedUrl","lists","split","map","listId","trim","Contact","Email","ConsentText","ListIds","DoubleOptIn","Issue","IssueId","ConfirmationIssue","SubscriptionConfirmedUrl","SubscriptionFailedUrl","accountId","response","fetch","method","headers","body","JSON","stringify","ok","Error","status","checked","querySelectorAll"],"sourceRoot":""}