UNPKG

@xo-union/tk-component-header-nav

Version:
46 lines (45 loc) 1.96 kB
"use strict"; var _Object$defineProperty = require("@babel/runtime-corejs3/core-js/object/define-property"); var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault"); _Object$defineProperty(exports, "__esModule", { value: true }); exports.getDefaultFavoritesConfig = void 0; var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js/set")); const AUTO_FILLED_IN_PAGES = new _set.default(['your-favorites', 'wedding-vendor-manager', 'paper']); const NO_HREF_IN_PAGES = AUTO_FILLED_IN_PAGES; const NO_RENDER_IN_PAGES_UNLESS_OPTED_IN = new _set.default(['marketplace', 'review-wedding-vendors', 'inbox']); const PAPER_SLUG = 'paper'; const DEFAULT_LINK_KEY = 'YOUR_FAVORITES_INSPIRATION'; const targetLinkForProduct = { vendors: 'VENDOR_MANAGER', paper: 'PAPER_FAVORITES' }; const getHref = (isPaperPage, _ref, links, linkKey) => { let [currentPageSlug, lastCurrentPageSlug] = _ref; if (isPaperPage && !AUTO_FILLED_IN_PAGES.has(lastCurrentPageSlug)) { return links[linkKey]; } return NO_HREF_IN_PAGES.has(currentPageSlug) ? null : links[linkKey]; }; const getDefaultFavoritesConfig = _ref2 => { let { activeProduct, links, explicitlyOptedIn, location } = _ref2; const pathname = (location === null || location === void 0 ? void 0 : location.pathname) ?? ''; const [, currentPageSlug, lastCurrentPageSlug] = pathname.split('/', 3); const isPaperPage = currentPageSlug === PAPER_SLUG; if (NO_RENDER_IN_PAGES_UNLESS_OPTED_IN.has(currentPageSlug) && !explicitlyOptedIn) { return false; } const linkKey = targetLinkForProduct[activeProduct] ?? DEFAULT_LINK_KEY; const href = getHref(isPaperPage, [currentPageSlug, lastCurrentPageSlug], links, linkKey); return { isFilled: isPaperPage ? AUTO_FILLED_IN_PAGES.has(lastCurrentPageSlug) : AUTO_FILLED_IN_PAGES.has(currentPageSlug), href }; }; exports.getDefaultFavoritesConfig = getDefaultFavoritesConfig;