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ALAxC,SAAAA,EAAWyC,aACP,kBACApB,EAAwB,OAAS,SAGjCA,EAAuB,CACvB,IAgBiCqB,EAhB3BC,EACFpC,EAAIL,cAAc,qCAChB0C,EACFrC,EAAIL,cAAc,qCAChB2C,EACFtC,EAAIL,cAAc,iCAEtB4C,EAIqCzB,EAHjC0B,EAAID,EAAJC,KACAC,EAAIF,EAAJE,KAC0BC,EAAeH,EAAzCI,yBAKJ,GAAIH,GAAQC,EACJL,IACAA,EAAwBQ,UAAYJ,EACpCJ,EAAwBS,KAAOJ,EAEM,QAArCN,EAAAC,EAAwBU,qBAAa,IAAAX,GAArCA,EAAuCzB,UAAUqC,OAAO,GAADC,OAChDf,EAAmB,YACtBrC,OAAOqD,SAASJ,KAAKK,SAAST,KAGlCJ,IACAA,EAAwBO,UAAYJ,EACpCH,EAAwBQ,KAAOJ,GAGnCH,GAEII,IACAJ,EAAwBM,UAAYF,EACpCJ,EAAwB5B,UAAUyC,OAAO,GAADH,OACjCf,EAAmB,mBAE1BK,EAAwBc,gBAAgB,YAGpD,CAG0D,QAAtDxC,EAAAZ,EAAIL,cAAc,4CAAoC,IAAAiB,GAAtDA,EAAwDF,UAAUyC,OAAO,GAADH,OACjEf,EAAmB,0BAKsB,QAAhDpB,EAAAb,EAAIL,cAAc,sCAA8B,IAAAkB,GAAhDA,EAAkDH,UAAUyC,OACxD,4CAGZ,CACJ,GACJ,C","sources":["webpack:///./html/wp-content/themes/ls/src/js/main/components/navigation/btf/navigationSecondary.ts"],"sourcesContent":["import { CookieMonster } from 'root/utils/cookies/cookieMonster';\n/*eslint no-unused-labels: \"off\"*/ //this rule is not working from .eslintrc\n\ntype CookieMonsterObject = {\n setCookie: (a: string, b: string) => void;\n getCookie: (a: string) => string;\n};\n\ntype BusinessTypeLexicData = {\n name: string;\n link: string;\n clear_business_type_text: string;\n slug: string;\n};\n\ntype BusinessTypeObject = {\n [key: number]: BusinessTypeLexicData;\n};\ntype GlobalLexic =\n | [\n {\n business_types: BusinessTypeObject;\n link: string;\n name: string;\n product: string;\n }\n ]\n | undefined;\n\ndeclare global {\n interface Window {\n btfNavSecondaryLexic: GlobalLexic;\n }\n}\n/*\nThe script sets a cookie based on the slug that's inserted dynamically on the body tag.\nIt retrieves the cookie, and dynamically changes the links in the nav in order to reflect the cookie value.\n*/\nfunction getCurrentCookieValue(\n cm: CookieMonsterObject,\n cookieName: string,\n cookieValue: string\n) {\n const consentCallback = () => {\n const body = document.body;\n const verticalSlug = body.dataset.verticalSlug;\n if (verticalSlug) {\n const isCookieDifferentThanSlug = cookieValue && verticalSlug !== cookieValue;\n // Set business type cookie if the ls_vertical_bt cookie is undefined/null OR\n // the vertical slug is different from the ls_vertical_bt value.\n if (!cookieValue || isCookieDifferentThanSlug) {\n /* Set the cookie - make sure that the path is always \"/\" or\n else a secondary cookie will be set and the functionality will break */\n {\n cm.setCookie(cookieName, verticalSlug);\n }\n }\n }\n };\n (window).registerCookieComplianceCallback({ callback: consentCallback });\n\n const body = document.body;\n const verticalSlug = body.dataset.verticalSlug;\n if (verticalSlug) {\n const isCookieDifferentThanSlug = cookieValue && verticalSlug !== cookieValue;\n // Set business type cookie if the ls_vertical_bt cookie is undefined/null OR\n // the vertical slug is different from the ls_vertical_bt value.\n if (!cookieValue || isCookieDifferentThanSlug) {\n /* Set the cookie - make sure that the path is always \"/\" or\n else a secondary cookie will be set and the functionality will break */\n {\n cm.setCookie(cookieName, verticalSlug);\n }\n }\n }\n return cm.getCookie(cookieName);\n}\nfunction getVerticalBusinessTypeSpecificLexic(\n businessTypeValue: string,\n globalLexicVar: GlobalLexic\n) {\n if (globalLexicVar && globalLexicVar.length > 0 && globalLexicVar[0].business_types) {\n if (typeof Object.values === 'function') {\n /* this is a fix for \"TypeError: Object.values is not a function\" recurrent error in DD */\n\n const btArray = Object.values(globalLexicVar[0].business_types);\n\n return (\n btArray &&\n btArray.find(function ({ slug }) {\n return slug === businessTypeValue;\n })\n );\n }\n }\n}\n\nexport default function navigationSecondary(navs: NodeList) {\n const cm = new CookieMonster();\n const btCookieName = 'ls_vertical_bt';\n const btCookieValue = cm.getCookie(btCookieName);\n const navHeader = document.querySelector('header.main-site-header-btf');\n\n setPreviousCookieValueInLocalStorage: {\n btCookieValue && window.localStorage.setItem('btf.businessType', btCookieValue);\n }\n navs.forEach((nav: HTMLElement) => {\n const isCurrentSecondaryNav =\n window.getComputedStyle(nav).getPropertyValue('display') !== 'none';\n\n const globalLexicVar = window.btfNavSecondaryLexic;\n const isGlobalLexicVar =\n globalLexicVar && globalLexicVar.length > 0 && globalLexicVar[0] !== null;\n const secondaryMobileNav: HTMLElement | null = nav.querySelector(\n '.navigation-btf-mobile__secondary'\n );\n checkForSecondaryMobileNav: {\n nav = secondaryMobileNav ? secondaryMobileNav : nav;\n }\n const isSecondary =\n nav.classList.contains('navigation-btf-desktop--secondary') ||\n secondaryMobileNav;\n\n /* make sure that the nav is not hidden and it is a secondary nav.\n The loop goes through the main desktop nav, the secondary desktop nav and the main mobile nav,\n which has the mobile secondary nav as a child */\n if (isCurrentSecondaryNav && isSecondary && isGlobalLexicVar) {\n const businessTypeLexicData = getVerticalBusinessTypeSpecificLexic(\n getCurrentCookieValue(cm, btCookieName, btCookieValue),\n globalLexicVar\n );\n const desktopItemSelector = 'navigation-btf-desktop__item';\n /* Based on that the cookie will be set/unset */\n navHeader?.setAttribute(\n 'data-slug-match',\n businessTypeLexicData ? 'true' : 'false'\n );\n\n if (businessTypeLexicData) {\n const secondaryNavIndexButton: HTMLAnchorElement | null =\n nav.querySelector('[data-secondary-nav-index-button]');\n const secondaryNavHeaderIndex: HTMLAnchorElement | null =\n nav.querySelector('[data-secondary-nav-header-index]');\n const secondaryNavClearButton: HTMLAnchorElement | null =\n nav.querySelector('[data-secondary-nav-clear-bt]');\n\n const {\n name,\n link,\n clear_business_type_text: clearButtonText,\n } = (businessTypeLexicData);\n /* Change the name and the link of the business type menu item in the secondary nav\n * for instance: Apparel, or Bike..\n * */\n if (name && link) {\n if (secondaryNavIndexButton) {\n secondaryNavIndexButton.innerText = name;\n secondaryNavIndexButton.href = link;\n /* Set the index link to active if on vertical page, but remove if not */\n secondaryNavIndexButton.parentElement?.classList.toggle(\n `${desktopItemSelector}--active`,\n window.location.href.includes(link)\n );\n }\n if (secondaryNavHeaderIndex) {\n secondaryNavHeaderIndex.innerText = name;\n secondaryNavHeaderIndex.href = link;\n }\n }\n if (secondaryNavClearButton) {\n /* insert the \"Not a yours?\" text into the element */\n if (clearButtonText) {\n secondaryNavClearButton.innerText = clearButtonText;\n secondaryNavClearButton.classList.remove(\n `${desktopItemSelector}__link--hidden`\n );\n secondaryNavClearButton.removeAttribute('tabindex');\n }\n }\n }\n\n showSecondaryNavItemsOnDesktop: {\n nav.querySelector('[data-secondary-nav-middle-group]')?.classList.remove(\n `${desktopItemSelector}-group-middle--hidden`\n );\n }\n\n showSecondaryNavItemsOnMobile: {\n nav.querySelector('[data-secondary-nav-header]')?.classList.remove(\n 'navigation-btf-mobile__menu__list--hidden'\n );\n }\n }\n });\n}\n"],"names":["navigationSecondary","navs","cm","CookieMonster","btCookieName","btCookieValue","getCookie","navHeader","document","querySelector","window","localStorage","setItem","forEach","nav","isCurrentSecondaryNav","getComputedStyle","getPropertyValue","globalLexicVar","btfNavSecondaryLexic","isGlobalLexicVar","length","secondaryMobileNav","isSecondary","classList","contains","_nav$querySelector","_nav$querySelector2","businessTypeLexicData","businessTypeValue","business_types","Object","values","btArray","find","_ref","slug","getVerticalBusinessTypeSpecificLexic","cookieName","cookieValue","registerCookieComplianceCallback","callback","verticalSlug","body","dataset","setCookie","getCurrentCookieValue","desktopItemSelector","setAttribute","_secondaryNavIndexBut","secondaryNavIndexButton","secondaryNavHeaderIndex","secondaryNavClearButton","_ref2","name","link","clearButtonText","clear_business_type_text","innerText","href","parentElement","toggle","concat","location","includes","remove","removeAttribute"],"sourceRoot":""}