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AAG,CAC7F,MAAE6E,KAAMC,EAAe,EACvB,CAACC,CAAa,EAAIC,EAAa,EAC/BE,EAAanB,EAAc,EAC3B,CAAEqB,oBAAqBC,EAAkB,EAEzCe,EAA0BC,cAAY,SAAY,CAChD,IACA,MAAMnB,EAAW,CAAEpC,SAAQ1E,eAAc,EAErC0E,EAAO8C,4BAA8BR,EACvBL,EAAA,CAACjC,EAAO+C,SAAS,CAAC,EAE1BjE,UAAgBiD,EAAEiB,CAAW,EAAG,CAClCH,SAAU,YACb,QAEAI,EAAG,CACFlE,cAAcgD,EAAEmB,CAAgB,EAAG,CACrCL,SAAU,YACb,EACK,IAAItC,MAAM0C,CAAW,EAC/B,EACD,CAAChB,EAAejC,EAAQ+B,EAAGzG,EAAcgH,CAAgB,CAAC,EAGzD,OAAA1D,EAAA,IAAChC,GACG,SAAS0G,EACT,KAAK,SACL,aAAYvB,EAAEqB,CAAM,EACpB,GAAIlG,CACN,EAEV,CAEA,MAAAsG,GAAeC,OAAOC,OAAO5B,GAAkB,CAC3C6B,QAASN,EACb,CAAC","names":["getBrandClubPowerstepParams","label","paramValues","split","levelAndPositionParamValues","param_name","param_value","getRecommendationParams","recommendationType","indexAndPositionParamValues","getParams","eventCategory","firstCharacterToLower","getProductListParams","undefined","addToCartTypeEventCategoryMapper","eventLabel","context","eventCategoryToContext","eventParams","trackingObj","eventName","category","createActionTracking","trackingInfo","defaultUAEvent","overrideCallback","overriddenUAEvent","eventAction","UAEventTracking","Container","styled","div","withConfig","displayName","componentId","AnimatedContainer","animated","StyledButtonWithAnimatedStatuses","Button","status","css","ColorSystemPositive1","ColorSystemNegative1","$disabled","theme","ButtonWithAnimatedStatuses","React","forwardRef","onClick","asyncFunction","children","restProps","ref","execute","reset","useAsync","delayedStatus","setDelayedStatus","useState","canChangeState","setCanChangeState","transition","useTransition","initial","scale","from","enter","leave","exitBeforeEnter","config","stiff","onStart","onRest","components","idle","Icon","pending","jsx","Spinner","success","error","useEffect","timer","setTimeout","style","item","SubscriptionContext","createContext","subscriptionActive","setSubscriptionActive","bool","SelectedFrequencyContext","selectedFrequency","setSelectedFrequency","obj","getEventLabelByContext","type","params","contextEventLabel","recommendationPlacement","loadAddToBasketFunc","addToBasket","__vitePreload","n","Error","addToBasketPos","subscriptionFrequencyId","subscriptionDiscountId","addProductAndSubscriptionToReceipt","externalProductId","toString","subscriptionMinimumSalesQuantity","addToReceipt","minimumSalesQuantity","useAddProduct","GA4Tracking","useGA4Tracking","isPosRequest","usePointOfSaleRequest","addProductTracking","additionalGA4Params","GA4TrackingObject","serverSideTrackingModel","serverSideTracking","data","eventType","response","AddProductButton","t","useTranslation","openPowerstep","usePowerstep","useContext","AddProduct","isSubscriptionSelected","powerstepEnabled","useFeatureToggles","buttonClick","addProductParams","id","quantityModified","ProductNotAddedToBasket","position","showPowerstepOnAddToBasket","productId","AddToBasket","e","ErrorAddToBasket","ButtonWithSpinner","BuyNow","AddProductButtonCompact","AddProductAndSpawnToast","useCallback","AddProductButton$1","Object","assign","Compact"],"ignoreList":[],"sources":["../../../wwwdev/scripts/modules/tracking/GA4/helpers/getBrandClubPowerstepParams.ts","../../../wwwdev/scripts/modules/tracking/GA4/helpers/getRecommendationParams.ts","../../../wwwdev/scripts/modules/tracking/GA4/helpers/addToCart.ts","../../../wwwdev/esm/components/generic/productCTA/shared/helpers.ts","../../../wwwdev/esm/components/Button/ButtonWithAnimatedStatuses.tsx","../../../wwwdev/esm/components/pages/PDP/components/MidSection/hooks/context.ts","../../../wwwdev/esm/components/generic/productCTA/components/AddProduct/action.ts","../../../wwwdev/esm/components/generic/productCTA/components/AddProduct/AddProductButton.tsx"],"sourcesContent":["import { RecommendationType } from '../types/RecommendationType';\r\nimport { FilterParams } from '../types/types';\r\n\r\ntype BrandClubPowerstepParam =\r\n | FilterParams<'recommendation_type', RecommendationType>\r\n | FilterParams<'product_type'>\r\n | FilterParams<'level'>\r\n | FilterParams<'position'>;\r\n\r\nexport default function getBrandClubPowerstepParams(label): BrandClubPowerstepParam[] {\r\n const paramValues = label.split('_');\r\n const levelAndPositionParamValues = paramValues[2].split(' - ');\r\n\r\n return [\r\n { param_name: 'recommendation_type', param_value: 'brand_club_powerstep' },\r\n { param_name: 'product_type', param_value: paramValues[1] },\r\n { param_name: 'level', param_value: levelAndPositionParamValues[0] },\r\n { param_name: 'position', param_value: levelAndPositionParamValues[1] }\r\n ];\r\n}\r\n","import type { RecommendationType } from '../types/RecommendationType';\r\nimport type { FilterParams } from '../types/types';\r\n\r\ntype BrandClubPowerstepParam =\r\n | FilterParams<'recommendation_type', RecommendationType>\r\n | FilterParams<'recommendation_name'>\r\n | FilterParams<'recommendation_index'>\r\n | FilterParams<'position'>;\r\n\r\nexport default function getRecommendationParams(label, recommendationType): BrandClubPowerstepParam[] {\r\n const paramValues = label.split('.');\r\n const indexAndPositionParamValues = paramValues[1].split(' - ');\r\n\r\n return [\r\n { param_name: 'recommendation_type', param_value: recommendationType },\r\n { param_name: 'recommendation_index', param_value: indexAndPositionParamValues[0] },\r\n { param_name: 'position', param_value: indexAndPositionParamValues[1] }\r\n ];\r\n}\r\n","import type { TrackingCategory } from 'modules/tracking/UAEventTracking';\r\nimport { firstCharacterToLower } from 'modules/helpers/strings';\r\nimport type { UATrackingProps, EventParamDecorated } from '../types';\r\nimport eventCategoryToContext from './eventCategoryToContext';\r\nimport getProductListParams from './getProductListParams';\r\nimport getBrandClubPowerstepParams from './getBrandClubPowerstepParams';\r\nimport getRecommendationParams from './getRecommendationParams';\r\n\r\nfunction getParams(eventCategory: TrackingCategory, label?: string): EventParamDecorated[] | undefined {\r\n const categoryType: Uncapitalize = firstCharacterToLower(eventCategory);\r\n\r\n switch (categoryType) {\r\n case 'productList':\r\n return [...getProductListParams()];\r\n case 'productPage':\r\n return [];\r\n case 'basketRecomendation':\r\n return getRecommendationParams(label, 'basket');\r\n case 'cmsPageRecomendation':\r\n return getRecommendationParams(label, 'cms_page');\r\n case 'powerstep':\r\n return getRecommendationParams(label, 'powerstep');\r\n case 'powerstepAfterBasket':\r\n return getRecommendationParams(label, 'powerstep_after_basket');\r\n case 'productGroupRecomendation':\r\n return getRecommendationParams(label, 'product_group');\r\n case 'productRecomendation':\r\n return getRecommendationParams(label, 'product_page');\r\n case 'receiptPageRecommendation':\r\n return getRecommendationParams(label, 'receipt_page');\r\n case 'searchResultPageRecomendation':\r\n case 'zeroResultPageRecomendation':\r\n return getRecommendationParams(label, 'search_result_page');\r\n case 'bestMatch':\r\n case 'visualSearchResults':\r\n return [{ param_name: 'search_type', param_value: 'visual_search' }];\r\n case 'crossSell':\r\n return [{ param_name: 'is_cross_sell', param_value: true }];\r\n case 'productSlider':\r\n return [];\r\n case 'productRegime':\r\n return [{ param_name: 'is_regime', param_value: true }];\r\n case 'replenish':\r\n return [{ param_name: 'is_replenish', param_value: true }];\r\n case 'samples':\r\n return [{ param_name: 'is_sample', param_value: true }];\r\n case 'brandClubPowerstep':\r\n return getBrandClubPowerstepParams(label);\r\n case 'none':\r\n default:\r\n return undefined;\r\n }\r\n}\r\n\r\nexport default function addToCartTypeEventCategoryMapper(\r\n eventCategory: TrackingCategory,\r\n eventLabel?: string\r\n): UATrackingProps {\r\n const context = eventCategoryToContext(eventCategory);\r\n const eventParams = getParams(eventCategory, eventLabel);\r\n\r\n const trackingObj: UATrackingProps = {\r\n eventName: 'add_to_cart',\r\n category: 'ecommerce'\r\n };\r\n\r\n if (context) {\r\n trackingObj.context = context;\r\n }\r\n\r\n if (eventParams) {\r\n trackingObj.eventParams = eventParams;\r\n }\r\n\r\n return trackingObj;\r\n}\r\n","import UAEventTracking, { ITrackUAEvent } from 'modules/tracking/UAEventTracking';\r\nimport { IProductActionTrackingContext } from './types';\r\n\r\nconst createActionTracking = (\r\n trackingInfo: IProductActionTrackingContext,\r\n defaultUAEvent: ITrackUAEvent,\r\n overrideCallback?: (trackingInfo: IProductActionTrackingContext) => Partial\r\n) => {\r\n let overriddenUAEvent: Partial = {\r\n eventAction: trackingInfo?.eventAction,\r\n eventCategory: trackingInfo?.eventCategory,\r\n eventLabel: trackingInfo?.eventLabel\r\n };\r\n\r\n if (overrideCallback) {\r\n overriddenUAEvent = overrideCallback(trackingInfo);\r\n }\r\n\r\n return UAEventTracking({\r\n eventAction: overriddenUAEvent.eventAction || defaultUAEvent.eventAction,\r\n eventCategory: overriddenUAEvent.eventCategory || defaultUAEvent.eventCategory,\r\n eventLabel: overriddenUAEvent.eventLabel || defaultUAEvent.eventLabel\r\n });\r\n};\r\n\r\nexport default createActionTracking;\r\n","/* eslint-disable consistent-return */\r\nimport { animated, config, useTransition } from '@react-spring/web';\r\nimport { ColorSystemNegative1, ColorSystemPositive1 } from 'autogen/design-tokens/tokens';\r\nimport Icon from 'components/Icon';\r\nimport useAsync, { type StatusStates } from 'hooks/globals/useAsync';\r\nimport Spinner from 'modules/shared/circleSpinner';\r\nimport React, { useEffect, useState } from 'react';\r\nimport styled, { css } from 'styled-components';\r\nimport Button from './Button';\r\nimport type IButton from './shared/types/button';\r\n\r\nconst Container = styled.div`\r\n width: 16px;\r\n height: 16px;\r\n max-width: 16px;\r\n max-height: 16px;\r\n`;\r\n\r\nconst AnimatedContainer = animated(Container);\r\n\r\nconst StyledButtonWithAnimatedStatuses = styled(Button)<{ status: StatusStates }>`\r\n ${({ status }) => {\r\n switch (status) {\r\n case 'success':\r\n return css`\r\n background-color: ${ColorSystemPositive1};\r\n &:focus,\r\n &:hover {\r\n background-color: ${ColorSystemPositive1};\r\n }\r\n `;\r\n case 'error':\r\n return css`\r\n background-color: ${ColorSystemNegative1};\r\n &:focus,\r\n &:hover {\r\n background-color: ${ColorSystemNegative1};\r\n }\r\n `;\r\n default:\r\n }\r\n }}\r\n\r\n cursor: ${($disabled) => ($disabled ? 'pointer' : 'pointer')};\r\n transition: background-color 500ms linear;\r\n ${({ theme }) => theme.ButtonWithAnimatedStatuses}\r\n`;\r\n\r\ninterface IButtonWithAnimatedStatuses extends IButton {\r\n onClick: () => Promise;\r\n}\r\n\r\nconst ButtonWithAnimatedStatuses = React.forwardRef(\r\n ({ onClick: asyncFunction, children, ...restProps }, ref) => {\r\n const { execute, status, reset } = useAsync(asyncFunction, false);\r\n const [delayedStatus, setDelayedStatus] = useState(status);\r\n const [canChangeState, setCanChangeState] = useState(true);\r\n const transition = useTransition(delayedStatus, {\r\n initial: { scale: 1 },\r\n from: { scale: 0 },\r\n enter: { scale: 1 },\r\n leave: { scale: 0 },\r\n exitBeforeEnter: true,\r\n config: config.stiff,\r\n onStart: () => setCanChangeState(false),\r\n onRest: () => {\r\n setCanChangeState(true);\r\n }\r\n });\r\n\r\n const components = {\r\n idle: ,\r\n pending: ,\r\n success: ,\r\n error: \r\n };\r\n\r\n // We need to do this stuff due to a bug with the exitBeforeEnter property in react spring. If the state changes before the spring animation have finished the animations bugs out completely.\r\n useEffect(() => {\r\n let timer;\r\n if (canChangeState) {\r\n setDelayedStatus(status);\r\n\r\n if (status === 'success' || status === 'error') {\r\n timer = setTimeout(() => {\r\n reset();\r\n }, 2000);\r\n }\r\n }\r\n\r\n return () => {\r\n if (timer) clearTimeout(timer);\r\n };\r\n }, [canChangeState, reset, status]);\r\n\r\n return transition((style, item) => (\r\n \r\n {components[item]}\r\n \r\n ));\r\n }\r\n);\r\n\r\nexport default ButtonWithAnimatedStatuses;\r\n","/* eslint-disable @typescript-eslint/no-empty-function */\r\nimport { ChoosableSubscriptionFrequency } from 'autogen/swagger/all';\r\nimport { createContext } from 'react';\r\n\r\nexport const SubscriptionContext = createContext({\r\n subscriptionActive: false,\r\n setSubscriptionActive: (bool: boolean) => {}\r\n});\r\n\r\nexport const SelectedFrequencyContext = createContext({\r\n selectedFrequency: {} as ChoosableSubscriptionFrequency | undefined,\r\n setSelectedFrequency: (obj: ChoosableSubscriptionFrequency) => {}\r\n});\r\n","import serverSideTracking from 'components/shared/productItem/shared/helpers';\r\nimport RequestContext from 'modules/requestContext';\r\nimport { addProductAndSubscriptionToReceipt, addToReceipt } from 'pos/shared/fiftytwo/fiftyTwoApi';\r\nimport { type EventParamDecorated, addToCartTypeEventCategoryMapper } from 'modules/tracking/GA4';\r\nimport useGA4Tracking from 'modules/tracking/GA4/GA4Tracking';\r\nimport createActionTracking from '../../shared/helpers';\r\nimport type { IProductActionTrackingContext, ProductActionProps } from '../../shared/types';\r\nimport usePointOfSaleRequest from 'hooks/user/usePointOfSaleRequest';\r\n\r\nfunction getEventLabelByContext({\r\n eventCategory,\r\n eventAction,\r\n eventLabel,\r\n type,\r\n params\r\n}: IProductActionTrackingContext<{ recommendationPlacement?: number | string }>) {\r\n let contextEventLabel;\r\n\r\n switch (type) {\r\n case 'Bundle':\r\n contextEventLabel = 'bundleButton';\r\n break;\r\n case 'Epaper':\r\n contextEventLabel = 'epaperButton';\r\n break;\r\n case 'ProductGroupRecomendation':\r\n contextEventLabel = params?.recommendationPlacement;\r\n break;\r\n default:\r\n contextEventLabel = eventLabel;\r\n }\r\n\r\n return { eventAction, eventCategory, eventLabel: contextEventLabel };\r\n}\r\n\r\nexport const loadAddToBasketFunc = async () => {\r\n try {\r\n const { addToBasket } = await import(\r\n /* webpackChunkName: \"addAndRemoveFromBasket\" */ 'modules/addAndRemoveFromBasket'\r\n );\r\n\r\n return addToBasket;\r\n } catch (error) {\r\n throw new Error('failed to load addToBasket');\r\n }\r\n};\r\n\r\nasync function addToBasketPos(params: ProductActionProps['BuyNow']['params']) {\r\n try {\r\n if (params.subscriptionFrequencyId && params.subscriptionDiscountId) {\r\n await addProductAndSubscriptionToReceipt(\r\n params.externalProductId.toString(),\r\n params.subscriptionMinimumSalesQuantity ?? 1,\r\n params.subscriptionDiscountId.toString(),\r\n params.subscriptionFrequencyId.toString()\r\n );\r\n } else {\r\n await addToReceipt(params.externalProductId.toString(), params.minimumSalesQuantity ?? 1);\r\n }\r\n } catch (error) {\r\n throw new Error('Could not add product');\r\n }\r\n}\r\n\r\nexport function useAddProduct() {\r\n const GA4Tracking = useGA4Tracking();\r\n const { isPosRequest } = usePointOfSaleRequest();\r\n\r\n function addProductTracking(\r\n trackingInfo: ProductActionProps['BuyNow']['trackingInfo'],\r\n additionalGA4Params?: EventParamDecorated[]\r\n ) {\r\n const GA4TrackingObject = addToCartTypeEventCategoryMapper(\r\n trackingInfo.eventCategory,\r\n trackingInfo.eventLabel?.toString()\r\n );\r\n const eventParams = additionalGA4Params\r\n ? [...additionalGA4Params, ...(GA4TrackingObject.eventParams || [])]\r\n : GA4TrackingObject.eventParams;\r\n\r\n GA4Tracking({ ...GA4TrackingObject, eventParams });\r\n\r\n createActionTracking(\r\n trackingInfo,\r\n { eventCategory: 'none', eventAction: 'addToBasket', eventLabel: 'normal' },\r\n getEventLabelByContext\r\n );\r\n\r\n if (trackingInfo?.serverSideTrackingModel) {\r\n serverSideTracking(\r\n trackingInfo.serverSideTrackingModel.data,\r\n trackingInfo.serverSideTrackingModel.eventType\r\n );\r\n }\r\n }\r\n\r\n return async function AddProduct(\r\n { params, trackingInfo }: ProductActionProps['BuyNow'],\r\n additionalGA4Params?: EventParamDecorated[]\r\n ) {\r\n let response;\r\n try {\r\n if (isPosRequest) {\r\n response = await addToBasketPos(params);\r\n } else {\r\n const addToBasket = await loadAddToBasketFunc();\r\n response = await addToBasket(params);\r\n }\r\n } catch (error) {\r\n throw new Error('Could not add product');\r\n }\r\n\r\n try {\r\n addProductTracking(trackingInfo, additionalGA4Params);\r\n } catch (err) {\r\n console.error(`Could not track AddProduct: ${err}`);\r\n }\r\n return response;\r\n };\r\n}\r\n","import { AddToBasket, ErrorAddToBasket, ProductNotAddedToBasket } from 'autogen/translation-keys/trans-website-basket';\r\nimport { BuyNow } from 'autogen/translation-keys/trans-website-shared-buttons';\r\nimport { ButtonWithSpinner } from 'components/Button';\r\nimport ButtonWithAnimatedStatuses from 'components/Button/ButtonWithAnimatedStatuses';\r\nimport React, { useCallback, useContext } from 'react';\r\nimport { useTranslation } from 'react-i18next';\r\nimport toast from 'components/Toast';\r\nimport usePowerstep from 'components/powerstep/shared/hooks/usePowerstep';\r\nimport {\r\n SelectedFrequencyContext,\r\n SubscriptionContext\r\n} from 'components/pages/PDP/components/MidSection/hooks/context';\r\nimport type { ProductActionProps } from '../../shared/types';\r\nimport { useAddProduct } from './action';\r\nimport useFeatureToggles from 'hooks/user/useFeatureToggles';\r\n\r\nexport function AddProductButton({ params, trackingInfo, children, ...restProps }: ProductActionProps['BuyNow']) {\r\n const { t } = useTranslation();\r\n const [openPowerstep] = usePowerstep();\r\n const { selectedFrequency } = useContext(SelectedFrequencyContext);\r\n const { subscriptionActive } = useContext(SubscriptionContext);\r\n const AddProduct = useAddProduct();\r\n const isSubscriptionSelected = subscriptionActive && selectedFrequency;\r\n const { powerstepEnabled } = useFeatureToggles();\r\n\r\n async function buttonClick() {\r\n try {\r\n const addProductParams = isSubscriptionSelected\r\n ? {\r\n ...params,\r\n ...{ subscriptionFrequencyId: selectedFrequency?.id }\r\n }\r\n : params;\r\n\r\n const { quantityModified } = await AddProduct({ params: addProductParams, trackingInfo });\r\n\r\n if (quantityModified === 0) {\r\n toast.error(t(ProductNotAddedToBasket), {\r\n position: 'top-right'\r\n });\r\n return;\r\n }\r\n\r\n if (params.showPowerstepOnAddToBasket && powerstepEnabled) {\r\n openPowerstep([params.productId]);\r\n } else {\r\n toast.success(t(AddToBasket), {\r\n position: 'top-right'\r\n });\r\n }\r\n } catch (e) {\r\n toast.error(t(ErrorAddToBasket), {\r\n position: 'top-right'\r\n });\r\n throw new Error(e as string);\r\n }\r\n }\r\n\r\n return (\r\n \r\n {children || t(BuyNow)}\r\n \r\n );\r\n}\r\n\r\nfunction AddProductButtonCompact({ params, trackingInfo, ...restProps }: ProductActionProps['BuyNow']) {\r\n const { t } = useTranslation();\r\n const [openPowerstep] = usePowerstep();\r\n const AddProduct = useAddProduct();\r\n const { powerstepEnabled } = useFeatureToggles();\r\n\r\n const AddProductAndSpawnToast = useCallback(async () => {\r\n try {\r\n await AddProduct({ params, trackingInfo });\r\n\r\n if (params.showPowerstepOnAddToBasket && powerstepEnabled) {\r\n openPowerstep([params.productId]);\r\n } else {\r\n toast.success(t(AddToBasket), {\r\n position: 'top-right'\r\n });\r\n }\r\n } catch (e) {\r\n toast.error(t(ErrorAddToBasket), {\r\n position: 'top-right'\r\n });\r\n throw new Error(e as string);\r\n }\r\n }, [openPowerstep, params, t, trackingInfo, powerstepEnabled]);\r\n\r\n return (\r\n \r\n );\r\n}\r\n//\r\nexport default Object.assign(AddProductButton, {\r\n Compact: AddProductButtonCompact\r\n});\r\n"],"file":"client/chunks/AddProductButton.mwxjz0po.js"}