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J;IAEJ;AACF","sources":["src/ts/components/compareItems.ts","src/ts/util.ts"],"sourcesContent":["import { getItem, setItem } from 'ts/util';\n\ndocument.addEventListener('DOMContentLoaded', () => {\n const container = document.querySelector('.compare') as HTMLElement;\n\n // STARS\n const favourites = getItem('cbs:savings:favourites') || [];\n\n const stars = document.querySelectorAll('.compare__item__head__item__star');\n\n stars.forEach((el) => {\n const parent = el.parentElement as HTMLElement;\n const nextSiblingDiv = parent.nextElementSibling as HTMLElement;\n const h5 = nextSiblingDiv.querySelector('h5') as HTMLElement;\n\n el.dataset.name = h5.textContent as string;\n\n if (favourites.includes(h5.textContent as string)) {\n el.setAttribute('fill', '#632573');\n el.setAttribute('stroke', '#632573');\n }\n });\n\n stars.forEach((el) => {\n if (el) {\n el.addEventListener('click', () => {\n const name = el.dataset.name || '';\n const isFavourite = favourites.includes(name);\n\n if (isFavourite) {\n el.setAttribute('fill', '#f8f5f9');\n el.setAttribute('stroke', 'gray');\n name && favourites.splice(favourites.indexOf(name), 1);\n } else {\n el.setAttribute('fill', '#632573');\n el.setAttribute('stroke', '#632573');\n name && favourites.push(name);\n }\n\n // Reorder items based on favorites\n const items = document.querySelectorAll('.compare__item') as NodeListOf;\n\n items.forEach((item) => {\n if (favourites.includes(item.querySelector('.compare__item__head__item h5')?.textContent || '')) {\n container.insertBefore(item, container.firstChild);\n } else {\n container.appendChild(item);\n }\n });\n\n setItem('cbs:savings:favourites', favourites);\n });\n }\n });\n\n // Reorder items based on favorites on page load\n const items = document.querySelectorAll('.compare__item') as NodeListOf;\n\n items.forEach((item) => {\n if (favourites.includes(item.querySelector('.compare__item__head__item h5')?.textContent || '')) {\n container.insertBefore(item, container.firstChild);\n }\n });\n\n // ITEMS\n document.querySelectorAll('.compare__item').forEach((el) => {\n if (!el) return;\n const expandHandle = el.querySelector('.compare__item__head__item__btn-wrap') as HTMLElement;\n const btnParent = expandHandle.querySelector('.compare__item__head__item__btn-d') as HTMLElement;\n btnParent.setAttribute('aria-label', 'click to expand');\n if (expandHandle instanceof HTMLElement) {\n expandHandle.addEventListener('click', () => {\n const content = el.querySelector('.compare__item__content');\n const btnVer = expandHandle.querySelector('.compare__item__head__item__btn-d__ver') as HTMLElement;\n const label = expandHandle.querySelector('.compare__item__head__item__btn-label') as HTMLElement;\n\n if (content instanceof HTMLElement) {\n if (content.classList.contains('closed')) {\n el.style.outline = '1px solid #632573';\n content.classList.remove('closed');\n label.innerHTML = 'See Less';\n btnVer.style.display = 'none';\n btnParent.setAttribute('aria-label', 'Expanded , click to close');\n } else {\n el.style.outline = '';\n content.classList.add('closed');\n btnVer.style.display = '';\n btnParent.setAttribute('aria-label', 'click to expand');\n label.innerHTML = 'See More';\n }\n }\n });\n }\n });\n});\n","type Key = 'cbs:savings:favourites';\n\nexport const getItem = (key: Key): T | undefined => {\n const data = window.localStorage.getItem(key);\n if (!data) {\n return undefined;\n }\n\n try {\n return JSON.parse(data);\n } catch (error) {\n return undefined;\n }\n};\n\nexport const setItem = (key: Key, data: any) => {\n window.localStorage.setItem(key, JSON.stringify(data));\n};\n"],"names":[],"version":3,"file":"compare.33cd3ff1.js.map"}