{"version":3,"file":"C8kKkyfY.js","sources":["../../../../src/components/dialog/deleteFavList/useDeleteFavList.ts"],"sourcesContent":["import type { ErrorIdent } from '~/@types/errorIdents';\nimport { useSecureSessionPost } from '~/composables/dataFetching/genericFetchers';\nimport { useDialogStore } from '~/stores/useDialogStore';\nimport { useFavLists } from '~/stores/useFavLists';\nimport type { Result } from '@/server/api/[site]/user/favList/createFavList.post';\nimport { handleLoadingError } from '~/utils/handleLoadingError';\n\nconst favListStore = useFavLists();\n\nexport function useDeleteFavList() {\n const site = useSiteIdent();\n const errors = ref([]);\n const dialogStore = useDialogStore();\n const isLoading = ref(false);\n const listId = useRoute().params.id;\n\n //prevent deletion of favList if it is the default favList\n if (favListStore.myFavoriteList?.id === listId || !listId) {\n dialogStore.closeDialog();\n return;\n }\n\n async function deleteFavList() {\n try {\n isLoading.value = true;\n const result = await useSecureSessionPost(\n `/api/${site}/user/favList/deleteFavList`,\n {\n listId: String(listId),\n },\n );\n\n if (result) {\n await favListStore.loadLists();\n dialogStore.closeDialog();\n navigateToListAfterDelete();\n }\n } catch (e: any) {\n errors.value = e.data.data.errors;\n isLoading.value = false;\n handleLoadingError(e);\n }\n }\n\n return {\n deleteFavList,\n errors,\n dialogStore,\n isLoading,\n };\n}\n\n/**\n * @INFO\n * after delete the user will be navigated to\n *\n * 1. case: the default favList\n * when the list still exists, or the user dosen't have any lists\n *\n * 2. case: the first individual list\n * when the default favList dosen't exist anymore and the user has at least one individual favList\n */\nfunction navigateToListAfterDelete() {\n if (favListStore.myFavoriteList || favListStore.favoriteLists.length == 0) {\n navigateTo('/productlists/favorites');\n } else if (\n !favListStore.myFavoriteList &&\n favListStore.favoriteLists.length > 0\n ) {\n navigateTo(`/productlists/favorites/${favListStore.favoriteLists[0].id}`);\n }\n}\n"],"names":["favListStore","useFavLists","useDeleteFavList","site","useSiteIdent","errors","ref","dialogStore","useDialogStore","isLoading","listId","useRoute","_a","deleteFavList","useSecureSessionPost","navigateToListAfterDelete","e","handleLoadingError","navigateTo"],"mappings":"qFAOA,MAAMA,EAAeC,EAAY,EAE1B,SAASC,GAAmB,OACjC,MAAMC,EAAOC,IACPC,EAASC,EAAkB,CAAA,CAAE,EAC7BC,EAAcC,IACdC,EAAYH,EAAI,EAAK,EACrBI,EAASC,IAAW,OAAO,GAGjC,KAAIC,EAAAZ,EAAa,iBAAb,YAAAY,EAA6B,MAAOF,GAAU,CAACA,EAAQ,CACzDH,EAAY,YAAY,EACxB,MACF,CAEA,eAAeM,GAAgB,CACzB,GAAA,CACFJ,EAAU,MAAQ,GACH,MAAMK,EACnB,QAAQX,CAAI,8BACZ,CACE,OAAQ,OAAOO,CAAM,CACvB,CAAA,IAIA,MAAMV,EAAa,YACnBO,EAAY,YAAY,EACEQ,WAErBC,EAAQ,CACRX,EAAA,MAAQW,EAAE,KAAK,KAAK,OAC3BP,EAAU,MAAQ,GAClBQ,EAAmBD,CAAC,CACtB,CACF,CAEO,MAAA,CACL,cAAAH,EACA,OAAAR,EACA,YAAAE,EACA,UAAAE,CAAA,CAEJ,CAYA,SAASM,GAA4B,CAC/Bf,EAAa,gBAAkBA,EAAa,cAAc,QAAU,EACtEkB,EAAW,yBAAyB,EAEpC,CAAClB,EAAa,gBACdA,EAAa,cAAc,OAAS,GAEpCkB,EAAW,2BAA2BlB,EAAa,cAAc,CAAC,EAAE,EAAE,EAAE,CAE5E"}