{"version":3,"file":"link-with-icon.js","sources":["../../../../src/assets/scripts/link-with-icon.entry.ts"],"sourcesContent":["import { addFavoriteAsync, removeFavoriteAsync } from '@_api/favorite';\nimport { AddRemoveFavoriteResponseModel } from '@_types/types';\n\n(() => {\n const favorite = {\n favoriteElems: document.querySelectorAll('.arjo-a-link-with-icon--with-favorite'),\n init: function () {\n if (!this.favoriteElems.length) {\n return;\n }\n\n this.addEvent();\n },\n addEvent: function () {\n for (const favoriteElem of this.favoriteElems) {\n favoriteElem.addEventListener('click', (event) => {\n this.handleClick(event, favoriteElem);\n });\n }\n },\n handleClick: function (event: Event, element: Element) {\n event.preventDefault();\n\n const target = event.currentTarget as HTMLElement;\n const textEl = element.querySelector('.arjo-a-link-with-icon__content');\n const textAddFavorite = element.getAttribute('data-add-to-favorite');\n const textRemoveFavorite = element.getAttribute('data-remove-from-favorite');\n\n if (!target) {\n return;\n }\n\n const productID = target.dataset.productId;\n const markedAsFavorite = target.dataset.markedAsFavorite;\n\n if (!productID) {\n return;\n }\n\n if (markedAsFavorite === 'true') {\n removeFavoriteAsync(productID)\n .then((data: AddRemoveFavoriteResponseModel) => {\n let total = data.favoriteTotal ?? '0';\n\n window.setFavoriteCount(total);\n target.removeAttribute('data-marked-as-favorite');\n\n if (textAddFavorite && textEl) {\n textEl.innerHTML = textAddFavorite;\n }\n })\n .catch(console.error);\n\n return;\n }\n\n addFavoriteAsync(productID)\n .then((data: AddRemoveFavoriteResponseModel) => {\n let total = data.favoriteTotal ?? '0';\n\n window.setFavoriteCount(total);\n target.setAttribute('data-marked-as-favorite', 'true');\n\n if (textRemoveFavorite && textEl) {\n textEl.innerHTML = textRemoveFavorite;\n }\n })\n .catch(console.error);\n },\n };\n\n favorite.init();\n})();\n\nexport {};\n"],"names":["favoriteElem","event","element","target","textEl","textAddFavorite","textRemoveFavorite","productID","markedAsFavorite","removeFavoriteAsync","data","total","addFavoriteAsync"],"mappings":"2LAImB,CACf,cAAe,SAAS,iBAAiB,uCAAuC,EAChF,KAAM,UAAY,CACX,KAAK,cAAc,QAIxB,KAAK,SAAS,CAChB,EACA,SAAU,UAAY,CACT,UAAAA,KAAgB,KAAK,cACjBA,EAAA,iBAAiB,QAAUC,GAAU,CAC3C,KAAA,YAAYA,EAAOD,CAAY,CAAA,CACrC,CAEL,EACA,YAAa,SAAUC,EAAcC,EAAkB,CACrDD,EAAM,eAAe,EAErB,MAAME,EAASF,EAAM,cACfG,EAASF,EAAQ,cAAc,iCAAiC,EAChEG,EAAkBH,EAAQ,aAAa,sBAAsB,EAC7DI,EAAqBJ,EAAQ,aAAa,2BAA2B,EAE3E,GAAI,CAACC,EACH,OAGI,MAAAI,EAAYJ,EAAO,QAAQ,UAC3BK,EAAmBL,EAAO,QAAQ,iBAExC,GAAKI,EAIL,IAAIC,IAAqB,OAAQ,CAC/BC,EAAoBF,CAAS,EAC1B,KAAMG,GAAyC,CAC1C,IAAAC,EAAQD,EAAK,eAAiB,IAElC,OAAO,iBAAiBC,CAAK,EAC7BR,EAAO,gBAAgB,yBAAyB,EAE5CE,GAAmBD,IACrBA,EAAO,UAAYC,EAEtB,CAAA,EACA,MAAM,QAAQ,KAAK,EAEtB,MACF,CAEAO,EAAiBL,CAAS,EACvB,KAAMG,GAAyC,CAC1C,IAAAC,EAAQD,EAAK,eAAiB,IAElC,OAAO,iBAAiBC,CAAK,EACtBR,EAAA,aAAa,0BAA2B,MAAM,EAEjDG,GAAsBF,IACxBA,EAAO,UAAYE,EAEtB,CAAA,EACA,MAAM,QAAQ,KAAK,EACxB,CAAA,GAGO,KAAK"}