{"version":3,"file":"YJ4t3rmc.js","sources":["../../../../src/components/dialog/productSubscriptionActivate/useProductSubscriptionActivate.ts","../../../../src/components/dialog/productSubscriptionActivate/productSubscriptionActivate.vue"],"sourcesContent":["import { useSecureSessionPost } from '~/composables/dataFetching/genericFetchers';\nimport { DialogResponses, useDialogStore } from '@/stores/useDialogStore';\nimport { EDeliveryIntervalValues } from '@/@types/product-subscription';\nimport type { OrderAlarm } from '@/server/transformers/shop/orderAlarmTransformer';\nimport type { ProductSubscriptionCounter } from '@/server/gateway/connections/shopware/loaders/loadProductSubscriptionTotalCounter';\nimport type { NewDeliveryDate } from '@/server/gateway/connections/shopware/loaders/loadNewDeliveryDate';\nimport { useCartStore } from '~/stores/useCart';\nimport { handleLoadingError } from '~/utils/handleLoadingError';\n\nexport async function useProductSubscriptionActivate(orderAlarm: OrderAlarm) {\n const intervalMap = new Map([\n [2, EDeliveryIntervalValues.TWO_WEEKS],\n [3, EDeliveryIntervalValues.THREE_WEEKS],\n [4, EDeliveryIntervalValues.MONTHLY],\n [5, EDeliveryIntervalValues.FIVE_WEEKS],\n [6, EDeliveryIntervalValues.SIX_WEEKS],\n [8, EDeliveryIntervalValues.TWO_MONTHS],\n [12, EDeliveryIntervalValues.QUARTERLY],\n [24, EDeliveryIntervalValues.HALFYEARLY],\n [36, EDeliveryIntervalValues.NINE_MONTHS],\n ]);\n const site = useSiteIdent();\n const product = ref(orderAlarm.product);\n const quantity = ref(orderAlarm.packsPerWeek);\n const interval = ref(\n intervalMap.get(\n orderAlarm.selectedOrderInterval ?? orderAlarm.recommendedOrderInterval,\n ),\n );\n\n const productSubscriptionCounter = await (async () => {\n try {\n const result = await useSecureSessionPost(\n `/api/${site}/shop/product/productSubscription/counter`,\n );\n if (!result?.counter) {\n return {\n counter: 0,\n };\n }\n return result;\n } catch (e: any) {\n handleLoadingError(e);\n return {\n counter: 0,\n };\n }\n })();\n\n async function getNewDeliveryDate(\n interval: string,\n desiredDeliveryDay: string,\n ) {\n try {\n const deliveryDay: number = +desiredDeliveryDay;\n const response = await useSecureSessionPost(\n `/api/${site}/shop/product/productSubscription/deliveryDate/load`,\n {\n interval: interval,\n desiredDeliveryDay: deliveryDay,\n },\n );\n return response?.date;\n } catch (e: any) {\n handleLoadingError(e);\n return null;\n }\n }\n\n async function onSubmit(\n productId: string,\n quantity: number,\n interval: string,\n desiredDeliveryDay: string,\n ) {\n const { addProductSubscription } = useCartStore();\n const dialogStore = useDialogStore();\n const deliveryDay: number = +desiredDeliveryDay;\n addProductSubscription(productId, quantity, deliveryDay, interval);\n dialogStore.closeDialog(DialogResponses.SUCCESS);\n }\n\n return {\n product,\n quantity,\n interval,\n productSubscriptionCounter,\n getNewDeliveryDate,\n onSubmit,\n };\n}\n","\n\n\n"],"names":["useProductSubscriptionActivate","orderAlarm","intervalMap","EDeliveryIntervalValues","site","useSiteIdent","product","ref","quantity","interval","productSubscriptionCounter","result","useSecureSessionPost","handleLoadingError","getNewDeliveryDate","desiredDeliveryDay","deliveryDay","response","e","onSubmit","productId","addProductSubscription","useCartStore","dialogStore","useDialogStore","DialogResponses","t","tList","useTrans","userContext","useUserContext","session","useSessionStore","data","__temp","__restore","_withAsyncContext","deliveryIntervals","deliveryDays","useSubscriptionBox","selectedDeliveryDay","EDeliveryDaysValues","nextOrderDate","watch","newDate"],"mappings":"0gCASA,eAAsBA,GAA+BC,EAAwB,CACrE,MAAAC,MAAkB,IAAoB,CAC1C,CAAC,EAAGC,EAAwB,SAAS,EACrC,CAAC,EAAGA,EAAwB,WAAW,EACvC,CAAC,EAAGA,EAAwB,OAAO,EACnC,CAAC,EAAGA,EAAwB,UAAU,EACtC,CAAC,EAAGA,EAAwB,SAAS,EACrC,CAAC,EAAGA,EAAwB,UAAU,EACtC,CAAC,GAAIA,EAAwB,SAAS,EACtC,CAAC,GAAIA,EAAwB,UAAU,EACvC,CAAC,GAAIA,EAAwB,WAAW,CAAA,CACzC,EACKC,EAAOC,IACPC,EAAUC,EAAIN,EAAW,OAAO,E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