{"version":3,"file":"assets/js/chunks/833.5eef6a2008a93f75410e.js","mappings":"07BASA,MAAMA,EAAwB,wCACxBC,EAAc,uCA2EpB,QAAc,wBAzEiB,IAAgB,IAAf,QAAEC,GAAa,EAC3C,MAAMC,GAAO,QAA2B,uCAClCC,GAAa,QAA6B,wCA0DhD,SAASC,uBACLH,EAAQI,UAAY,GACpBJ,EAAQK,QACJ,cAAKC,MAAM,kEACP,YAAGA,MAAM,yBAAuB,oDAChC,YAAGA,MAAM,kCAAgC,iFA7DrD,SAAU,MA2CV,SAASC,eACL,QAAS,QAAYR,IA3CjBQ,IACAJ,2BAIR,QAAUD,EAAY,SAAS,SAyB/B,SAASM,SAEDN,EAAWO,SAASC,OACwC,KAA5D,QAAcR,EAAWO,QAAQC,MAAO,SAASC,OAGjDX,EAAQY,UAAUC,IAAIf,GAEtBE,EAAQY,UAAUE,OAAOhB,KAjCe,OAChD,QAAUG,EAAM,kBAAkBc,UAC9B,MAAM,MAAEC,EAAF,WAASC,EAAT,UAAqBC,EAArB,SAAgCC,GAAaC,EAAEC,QAC/C,WAACC,EAAD,OAAaC,EAAb,gBAAqBC,GAAmBC,OAAOC,wBAE/CC,EAAmC,CACrCC,SAAU,cAAF,CACJC,cAAeN,EACfC,gBAAiBA,GACbF,GAAc,CAACA,eAEvBQ,SAAU,CACNd,QACAe,UAAWb,EACXc,SAAUb,EACVc,OAAQhB,UAIV,QAAuBU,GAsBjC,SAASO,wBACL,MAAMC,EAAe,IAAIC,KACzBD,EAAaE,YAAYF,EAAaG,cAAgB,GAEtD,QAAYvC,EAAa,OAAQ,CAC7BwC,QAASJ,IA1BbD,GACA/B,wBACA,QAAU","sources":["webpack://frontend-setup/./src/components/molecules/area-subscription-de/utilities/area-subscription-de.tsx"],"sourcesContent":["import { defineElement, FC, onDidLoad, useElement, useListen } from '@atomify/hooks';\nimport { h } from '@atomify/jsx';\nimport { debounce } from '@bpd-library/utilities';\nimport { BPDFormElement, validateField } from '@source/components/atoms';\nimport { openModal } from '@source/store/modals';\nimport { AreaProjectNewsletterProps } from '@store/subscription/services/api-calls';\nimport { subscribeToAreaProject } from '@store/subscription/store';\nimport Cookies from 'js-cookie';\n\nconst CLASS_EXPANDED_SIGNUP = 'area-subscription-de--expanded-signup';\nconst COOKIE_NAME = 'BPD::SubscribedToAreaProjectGermany';\n\nconst AreaSubscriptionDe: FC = ({ element }) => {\n const form = useElement('[js-hook-area-subscription-de-form]');\n const emailInput = useElement('[js-hook-area-subscription-de-email]');\n\n onDidLoad(() => {\n if (isSubscribed()) {\n setSubscribedMessage();\n }\n });\n\n useListen(emailInput, 'keyup', debounce(expand, 300));\n useListen(form, 'serializedForm', async (e: any) => {\n const { email, salutation, firstname, lastname } = e.detail;\n const {districtId, areaId, areaProjectName} = window.__ENVIRONMENT_DETAILS__;\n\n const data: AreaProjectNewsletterProps = {\n areaInfo: {\n areaProjectId: areaId,\n areaProjectName: areaProjectName,\n ...(districtId && {districtId})\n },\n userInfo: {\n email,\n firstName: firstname,\n lastName: lastname,\n gender: salutation,\n },\n };\n\n await subscribeToAreaProject(data);\n setIsSubscribedCookie();\n setSubscribedMessage();\n openModal('area-subscription-de');\n });\n\n function expand() {\n const emailIsValid =\n emailInput.current?.value &&\n validateField(emailInput.current.value, 'email').length === 0;\n\n if (emailIsValid) {\n element.classList.add(CLASS_EXPANDED_SIGNUP);\n } else {\n element.classList.remove(CLASS_EXPANDED_SIGNUP);\n }\n }\n\n function isSubscribed() {\n return !!Cookies.get(COOKIE_NAME);\n }\n\n function setIsSubscribedCookie() {\n const aYearFromNow = new Date();\n aYearFromNow.setFullYear(aYearFromNow.getFullYear() + 1);\n\n Cookies.set(COOKIE_NAME, 'true', {\n expires: aYearFromNow,\n });\n }\n\n function setSubscribedMessage() {\n element.innerHTML = '';\n element.append(\n
\n

Sie sind bereits für den Newsletter registriert

\n

\n Wir informieren Sie regelmäßig per E-Mail über die wichtigsten Neuigkeiten\n

\n
,\n );\n }\n};\n\ndefineElement('area-subscription-de', AreaSubscriptionDe);\n"],"names":["CLASS_EXPANDED_SIGNUP","COOKIE_NAME","element","form","emailInput","setSubscribedMessage","innerHTML","append","class","isSubscribed","expand","current","value","length","classList","add","remove","async","email","salutation","firstname","lastname","e","detail","districtId","areaId","areaProjectName","window","__ENVIRONMENT_DETAILS__","data","areaInfo","areaProjectId","userInfo","firstName","lastName","gender","setIsSubscribedCookie","aYearFromNow","Date","setFullYear","getFullYear","expires"],"sourceRoot":""}