{"version":3,"file":"useBookmarks-CsoSbCUv.js","sources":["../../../packs/frontend/composables/collections/useBookmarks.ts"],"sourcesContent":["import { useApiClient } from \"@/composables/useApiClient\";\nimport { AppBookmarkableEnum } from \"@/services/fobizzToolsApi\";\nimport { useUserStore } from \"@/stores/user\";\nimport { ref, watch } from \"vue\";\n\nexport function useBookmark(\n objType: AppBookmarkableEnum,\n objId: string,\n isAuthor: ComputedRef\n) {\n const { bookmarks: bookmarksService } = useApiClient();\n const queryClient = useQueryClient();\n const userStore = useUserStore();\n const { t } = useI18n();\n\n const bookmarked = ref(false);\n\n const checkBookmark = async () => {\n if (isAuthor.value || userStore.isVisitor || !userStore.isAuthenticated)\n return;\n\n try {\n const response = await bookmarksService.checkBookmark({\n objType,\n objId,\n });\n bookmarked.value = response.bookmarked;\n } catch (error) {\n console.error(\"Error checking bookmark:\", error);\n }\n };\n\n const toggleBookmark = async () => {\n if (isAuthor.value || userStore.isVisitor) return;\n\n try {\n const response = await bookmarksService.toggleBookmark({\n objType,\n objId,\n });\n\n bookmarked.value = response.bookmarked;\n\n queryClient.invalidateQueries({ queryKey: [\"materials\"] });\n\n if (bookmarked.value) {\n flash(FlashKindEnum.INFO, t(\"flash.bookmarkSuccess\"));\n } else {\n flash(FlashKindEnum.INFO, t(\"flash.unbookmarkSuccess\"));\n }\n } catch (error) {\n console.error(\"Error toggling bookmark:\", error);\n }\n };\n\n watch(\n () => userStore.user?.id,\n async () => {\n await checkBookmark();\n },\n { immediate: true }\n );\n\n return {\n bookmarked,\n toggleBookmark,\n };\n}\n"],"names":["useBookmark","objType","objId","isAuthor","bookmarksService","useApiClient","queryClient","useQueryClient","userStore","useUserStore","t","useI18n","bookmarked","ref","checkBookmark","response","error","toggleBookmark","flash","FlashKindEnum","watch"],"mappings":"8HAKgB,SAAAA,EACdC,EACAC,EACAC,EACA,CACA,KAAM,CAAE,UAAWC,CAAiB,EAAIC,EAAa,EAC/CC,EAAcC,EAAe,EAC7BC,EAAYC,EAAa,EACzB,CAAE,EAAAC,CAAE,EAAIC,EAAQ,EAEhBC,EAAaC,EAAa,EAAK,EAE/BC,EAAgB,SAAY,CAChC,GAAI,EAAAX,EAAS,OAASK,EAAU,WAAa,CAACA,EAAU,iBAGpD,GAAA,CACI,MAAAO,EAAW,MAAMX,EAAiB,cAAc,CACpD,QAAAH,EACA,MAAAC,CAAA,CACD,EACDU,EAAW,MAAQG,EAAS,iBACrBC,EAAO,CACN,QAAA,MAAM,2BAA4BA,CAAK,CAAA,CAEnD,EAEMC,EAAiB,SAAY,CAC7B,GAAA,EAAAd,EAAS,OAASK,EAAU,WAE5B,GAAA,CACI,MAAAO,EAAW,MAAMX,EAAiB,eAAe,CACrD,QAAAH,EACA,MAAAC,CAAA,CACD,EAEDU,EAAW,MAAQG,EAAS,WAE5BT,EAAY,kBAAkB,CAAE,SAAU,CAAC,WAAW,EAAG,EAErDM,EAAW,MACbM,EAAMC,EAAc,KAAMT,EAAE,uBAAuB,CAAC,EAEpDQ,EAAMC,EAAc,KAAMT,EAAE,yBAAyB,CAAC,QAEjDM,EAAO,CACN,QAAA,MAAM,2BAA4BA,CAAK,CAAA,CAEnD,EAEA,OAAAI,EACE,IAAMZ,EAAU,MAAM,GACtB,SAAY,CACV,MAAMM,EAAc,CACtB,EACA,CAAE,UAAW,EAAK,CACpB,EAEO,CACL,WAAAF,EACA,eAAAK,CACF,CACF"}