{"version":3,"file":"navigation-BLogtgvh.js","sources":["../../../../scripts/services/layout/navigation.ts"],"sourcesContent":["import { DotCMSDestinationsLandingPageResponse } from \"interfaces/responses/dotcms-responses\";\r\nimport { FeatureCard } from \"interfaces/card\";\r\nimport { ProductType } from \"interfaces/enums\";\r\nimport { getCmsContent } from \"services/api/cms\";\r\nimport { isAdvisor } from \"services/auth/user-info\";\r\nimport { buildDestinationPageURL } from \"services/helpers/destinations\";\r\nimport { generateCmsImageUrl } from \"services/helpers/images\";\r\nimport { initDestinationAutoComplete } from \"services/search/destination-search\";\r\nimport { initProductSearchOmnibox } from \"services/search/product-search\";\r\nimport { cobrandLink } from \"virtuoso-shared-web-ui\";\r\nimport { mountMenuFeaturedDestinations } from \"vue-app\";\r\n\r\n\r\n/**\r\n * Initializes the destination autocomplete search, and moves the controls inside the hover menu\r\n * to preserve the hover state when mousing over the autoselect results\r\n * */\r\nexport function enableDestinationNavSearch(): void {\r\n    initDestinationAutoComplete(document.getElementById(\"destination-search-nav\") as HTMLInputElement);\r\n}\r\n\r\n/**\r\n * Initializes the hotel autocomplete search, and moves the controls inside the hover menu\r\n * to preserve the hover state when mousing over the autoselect results\r\n * */\r\nexport function enableHotelsNavSearch(): void {\r\n    const hotelAutocompleteInput = document.getElementById(\"hotels-search-nav\") as HTMLInputElement;\r\n\r\n    if (!hotelAutocompleteInput) {\r\n        return;\r\n    }\r\n\r\n    function selectCategory(acCategory: string, acValue: string): void {\r\n        let queryHash = \"#\";\r\n        let omniboxCategorySearch = \"\";\r\n        switch (acCategory) {\r\n            case \"city\":\r\n                omniboxCategorySearch = \"citySearch\";\r\n                break;\r\n            case \"country\":\r\n                omniboxCategorySearch = \"countrySearch\";\r\n                break;\r\n            case \"hotel name\":\r\n                omniboxCategorySearch = \"companySearch\";\r\n                break;\r\n            case \"all fields\":\r\n                omniboxCategorySearch = \"\";\r\n                break;\r\n        }\r\n\r\n        // Omnibox Search\r\n        if (omniboxCategorySearch !== \"\") {\r\n            queryHash += `${encodeURIComponent(omniboxCategorySearch.trim())}=${encodeURIComponent(acValue.trim())}&`;\r\n        }\r\n        // Text query\r\n        if (acValue.trim() !== \"\" && omniboxCategorySearch === \"\") {\r\n            queryHash += `query=${encodeURIComponent(acValue.trim())}&sort=SearchRelevance&`;\r\n        }\r\n\r\n        window.location.href = cobrandLink(`/travel/luxury-hotels/search${queryHash}`);\r\n        // Because this will only make a hashchange when on the hotel search page, we need to force a reload to get that page to see the change.\r\n        if (window.location.pathname.includes(\"luxury-hotels/search\")) {\r\n            window.location.reload();\r\n        }\r\n    }\r\n\r\n    initProductSearchOmnibox(hotelAutocompleteInput, ProductType.HOTELS, (category, searchTerm) => selectCategory(category, searchTerm));\r\n}\r\n\r\nexport function loadPopularDestinations(): void {\r\n\r\n    // ################## Grab the destination landing page... ##################\r\n\r\n    getCmsContent<DotCMSDestinationsLandingPageResponse[]>({\r\n        contentTypes: [\"DestinationsLandingPage\"],\r\n        depth: 1,\r\n        limit: 1\r\n    }).then((destinationJSON) => {\r\n\r\n        if (destinationJSON[0]) {\r\n\r\n            const dest = destinationJSON[0];\r\n            let featuredDestinations: FeatureCard[] = [];\r\n\r\n            // We only want the featured destinations from all the returned content\r\n            (dest.featuredDestinations).forEach(featuredDest => {\r\n                featuredDestinations.push({\r\n                    imageUrl: generateCmsImageUrl(featuredDest.gridImage),\r\n                    url: buildDestinationPageURL(featuredDest.destinationTag, featuredDest.isArbitraryDestination),\r\n                    name: featuredDest.title\r\n                });\r\n            });\r\n\r\n            // Let's randomize them and just take 5\r\n            if (featuredDestinations.length > 5) {\r\n                featuredDestinations = featuredDestinations\r\n                    .map((a) => ({ sort: Math.random(), value: a }))\r\n                    .sort((a, b) => a.sort - b.sort)\r\n                    .map((a) => a.value)\r\n                    .slice(0, 5);\r\n            }\r\n\r\n            mountMenuFeaturedDestinations(\"nav-popular-destinations\", featuredDestinations);\r\n\r\n        }\r\n    }).catch(() => {\r\n        console.error(\"Error retrieving popular destinations\");\r\n    });\r\n\r\n}\r\n\r\n\r\n/**\r\n * Jumps to the named link (id or name attribute) on the page, supplied in the URL; call this after the content is rendered\r\n * Includes header offset automatically.\r\n */\r\nexport function goToURLHash(): void {\r\n    const hashValue = window.location.hash.substring(1);\r\n    if (!hashValue) {\r\n        return;\r\n    }\r\n\r\n    const targetElement = document.getElementById(hashValue);\r\n    if (!targetElement) {\r\n        return;\r\n    }\r\n\r\n    targetElement.scrollIntoView();\r\n}\r\n\r\n\r\n/**\r\n * Applies classes to the body if necessary for cobranding or other things\r\n  */\r\nexport function setBodyClasses(): void {\r\n    if (isAdvisor()) {\r\n        document.body.classList.add(\"is-advisor\");\r\n    }\r\n}\r\n"],"names":["enableDestinationNavSearch","initDestinationAutoComplete","enableHotelsNavSearch","hotelAutocompleteInput","selectCategory","acCategory","acValue","queryHash","omniboxCategorySearch","cobrandLink","initProductSearchOmnibox","ProductType","category","searchTerm","loadPopularDestinations","getCmsContent","destinationJSON","dest","featuredDestinations","featuredDest","generateCmsImageUrl","buildDestinationPageURL","a","b","mountMenuFeaturedDestinations","goToURLHash","hashValue","targetElement","setBodyClasses","isAdvisor"],"mappings":"2NAiBO,SAASA,GAAmC,CACnBC,EAAA,SAAS,eAAe,wBAAwB,CAAqB,CACrG,CAMO,SAASC,GAA8B,CACpC,MAAAC,EAAyB,SAAS,eAAe,mBAAmB,EAE1E,GAAI,CAACA,EACD,OAGK,SAAAC,EAAeC,EAAoBC,EAAuB,CAC/D,IAAIC,EAAY,IACZC,EAAwB,GAC5B,OAAQH,EAAY,CAChB,IAAK,OACuBG,EAAA,aACxB,MACJ,IAAK,UACuBA,EAAA,gBACxB,MACJ,IAAK,aACuBA,EAAA,gBACxB,MACJ,IAAK,aACuBA,EAAA,GACxB,KACR,CAGIA,IAA0B,KACbD,GAAA,GAAG,mBAAmBC,EAAsB,KAAK,CAAC,CAAC,IAAI,mBAAmBF,EAAQ,MAAM,CAAC,KAGtGA,EAAQ,KAAA,IAAW,IAAME,IAA0B,KACnDD,GAAa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