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BAA0B,CAAC;MACvDnC,IAAI,CAACuC,WAAW,CAACd,aAAa,CAAC;IACjC;IACA,OAAOA,aAAa;EACtB;AACF;;;;;;;;;;ACpGA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCtBA;WACA;WACA;WACA;WACA;WACA,iCAAiC,WAAW;WAC5C;WACA;;;;;WCPA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA;;;;;WCPA;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D;;;;;;;;;;;;ACN+B;AAE/B,IAAIlC,gDAAM,CAAC,CAAC,C","sources":["webpack://static-snap/./src/extensions/forms/wp-forms/app/src/wp-form.ts","webpack://static-snap/external var \"StaticSnapFrontendClasses\"","webpack://static-snap/external window [\"wp\",\"i18n\"]","webpack://static-snap/webpack/bootstrap","webpack://static-snap/webpack/runtime/compat get default export","webpack://static-snap/webpack/runtime/define property getters","webpack://static-snap/webpack/runtime/hasOwnProperty shorthand","webpack://static-snap/webpack/runtime/make namespace object","webpack://static-snap/./src/extensions/forms/wp-forms/app/src/init.ts"],"sourcesContent":["import {\n FormBase,\n FormBaseGetNoticeMessageType,\n FormSubmitResponseInterface,\n WebsiteFormSettings,\n} from '@staticsnap/frontend';\nimport ApiResponseInterface from '@staticsnap/frontend/src/interfaces/api-response.interface';\nimport { __, sprintf } from '@wordpress/i18n';\n\nexport default class WpForm extends FormBase {\n private extensionMessagesClasses: Record = {\n error: 'wpforms-error-alert',\n field_error: 'wpforms-error-alert',\n invalid_error: 'wpforms-error-alert',\n success: 'wpforms-confirmation-container-full',\n };\n\n constructor() {\n super('[data-static-snap-type=\"form\"][data-static-snap-form-type=\"wp-forms\"]');\n }\n\n protected onSubmit(\n _e: Event,\n form: HTMLFormElement,\n _submitData: unknown,\n responseData: ApiResponseInterface\n ): void {\n const settings = this.getFormSettings(responseData);\n this.setMessage(\n form,\n responseData.type === 'item' && responseData?.data?.saved ? 'success' : 'error',\n settings\n );\n\n // TODO: add webhook support\n const knowSubmitActions = ['redirect'];\n\n settings?.submit_actions?.some((action) => {\n if (knowSubmitActions.includes(action)) {\n if (action === 'redirect') {\n this.onRedirect(settings);\n }\n }\n });\n }\n\n protected onRedirect(settings: WebsiteFormSettings): void {\n if (settings.redirect_to) {\n window.location.href = settings.redirect_to;\n }\n }\n\n protected onError(_e: Event, form: HTMLFormElement, _error: unknown): void {\n //console.log('ElementorForms onError', e, form, error);\n this.setMessage(form, 'error', {\n messages: {\n error: __('An error occurred, please try again later.', 'static-snap'),\n invalid: '',\n required: '',\n success: '',\n },\n });\n }\n\n private setMessage(\n form: HTMLFormElement,\n type: FormBaseGetNoticeMessageType,\n settings: WebsiteFormSettings\n ): void {\n const matchTypeToMessage = {\n error: settings?.messages?.error,\n field_error: settings?.messages?.required,\n invalid_error: settings?.messages?.invalid,\n success: settings?.messages?.success,\n };\n const noticeElement = this.getNoticeElement(form);\n const message =\n matchTypeToMessage[type] ||\n sprintf('

%s

', __('An error occurred, please try again later.', 'static-snap'));\n\n noticeElement.innerHTML = message;\n const messageClass = this.extensionMessagesClasses[type];\n // remove other form classes\n Object.values(this.extensionMessagesClasses).forEach((messageClass) => {\n form.classList.remove(messageClass);\n });\n\n noticeElement.classList.add(messageClass);\n }\n\n private getNoticeElement(form: HTMLFormElement): Element {\n let noticeElement = form.querySelector(' .wpforms-notice-container');\n\n if (!noticeElement) {\n noticeElement = document.createElement('div');\n noticeElement.classList.add('wpforms-notice-container');\n form.appendChild(noticeElement);\n }\n return noticeElement;\n }\n}\n","module.exports = StaticSnapFrontendClasses;","module.exports = window[\"wp\"][\"i18n\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import WpForm from './wp-form';\n\nnew WpForm();\n"],"names":["FormBase","__","sprintf","WpForm","extensionMessagesClasses","error","field_error","invalid_error","success","constructor","onSubmit","_e","form","_submitData","responseData","settings","getFormSettings","setMessage","type","data","saved","knowSubmitActions","submit_actions","some","action","includes","onRedirect","redirect_to","window","location","href","onError","_error","messages","invalid","required","matchTypeToMessage","noticeElement","getNoticeElement","message","innerHTML","messageClass","Object","values","forEach","classList","remove","add","querySelector","document","createElement","appendChild"],"sourceRoot":""}