{"version":3,"file":"Notification.hooks.BPJsIDUP.mjs","names":[],"sources":["https:/asset.29cm.co.kr/contents/framer/hooks/useIsNotificationRegistered.js","https:/asset.29cm.co.kr/contents/framer/components/primitives/Notification/Notification.hooks.js"],"sourcesContent":["import useSWR from \"../node_modules/swr/core/dist/index.js\";\nimport { useEffect } from \"react\";\nimport \"./stores/content/content.store.js\";\nimport { isClient } from \"../utils/context.js\";\nimport \"../utils/event-properties/source.js\";\nimport \"framer\";\nconst useIsNotificationRegistered = (key) => {\n  const {\n    data: isRegistered,\n    mutate\n  } = useSWR(key, () => {\n    return isClient() ? isNotificationAlreadyRegistered(key) : false;\n  });\n  const markAsRegistered = () => {\n    if (!key) {\n      return;\n    }\n    window.localStorage.setItem(key, \"true\");\n    mutate();\n  };\n  useEffect(() => {\n    if (!key) {\n      return;\n    }\n    mutate();\n  }, [key, mutate]);\n  return {\n    isRegistered,\n    markAsRegistered\n  };\n};\nconst isNotificationAlreadyRegistered = (key) => {\n  try {\n    const value = JSON.parse(window.localStorage.getItem(key) ?? \"false\");\n    return value === true;\n  } catch (error) {\n    return false;\n  }\n};\nexport {\n  useIsNotificationRegistered\n};\n","import { useAnalytics } from \"../../../hooks/analytics/useAnalytics.js\";\nimport { useContentStore } from \"../../../hooks/stores/content/content.store.js\";\nimport { useDialog } from \"../../../hooks/useDialog.js\";\nimport { useIsNotificationRegistered } from \"../../../hooks/useIsNotificationRegistered.js\";\nimport { useNotificationRequirements } from \"../../../hooks/useNotificationRequirements.js\";\nimport { useRequestUserAgreementBottomSheet } from \"../../../hooks/useRequestUserAgreementBottomSheet.js\";\nimport { useWithApp } from \"../../../hooks/useWithApp.js\";\nimport { useWithLogin } from \"../../../hooks/useWithLogin.js\";\nimport { isContentOrigin } from \"../../../utils/location.js\";\nconst NOTIFICATION_AGREEMENTS_API_END_POINT = \"content-detail-page\";\nconst ACCESS_FROM_APP_MESSAGE = \"알림 신청 기능은 APP에서만 사용할 수 있어요\\nAPP에서 다시 시도해 주세요.\";\nconst useNotification = (key, options) => {\n  const requestRequirements = useNotificationRequirements();\n  const {\n    isTargetAppVersion,\n    requestUserAgreementBottomSheet\n  } = useRequestUserAgreementBottomSheet();\n  const trackClickNotificationEvent = useTrackClickNotificationEvent(key);\n  const {\n    isRegistered,\n    markAsRegistered\n  } = useIsNotificationRegistered(key);\n  const dialog = useDialog();\n  const withLogin = useWithLogin();\n  const withApp = useWithApp({\n    content: ACCESS_FROM_APP_MESSAGE\n  });\n  const onNotificationEnabled = () => {\n    var _a;\n    markAsRegistered();\n    if (!(options == null ? void 0 : options.bypassNotificationEventTracking)) {\n      trackClickNotificationEvent();\n    }\n    (_a = options == null ? void 0 : options.onNotificationEnabled) == null ? void 0 : _a.call(options);\n  };\n  const registerNotification = withApp(withLogin(() => {\n    if (isTargetAppVersion) {\n      requestUserAgreementBottomSheet({\n        type: \"CONTENT_DETAIL_PAGE\",\n        onConfirm: onNotificationEnabled\n      });\n    } else {\n      requestRequirements({\n        apiEndpoint: NOTIFICATION_AGREEMENTS_API_END_POINT,\n        onNotificationEnabled\n      });\n    }\n  }));\n  const notifyAlreadyRegistered = () => {\n    dialog.show({\n      title: \"알림 신청이 이미 되어 있어요.\",\n      content: \"잊지 않도록 알림을 보내드릴게요.\",\n      primaryButtonText: \"확인\"\n    });\n  };\n  return {\n    isRegistered,\n    registerNotification,\n    notifyAlreadyRegistered\n  };\n};\nconst useTrackClickNotificationEvent = (key) => {\n  const {\n    trackFirebase,\n    trackAmplitude\n  } = useAnalytics();\n  const trackClickNotificationEvent = () => {\n    if (!isContentOrigin()) {\n      return;\n    }\n    const {\n      contentId\n    } = useContentStore.getState().summary;\n    const properties = {\n      notification_key: key,\n      curr_screen: getCurrentScreen(),\n      content_no: contentId,\n      format_type: \"FRAMER\",\n      target_status: \"on\"\n    };\n    trackFirebase(\"click_notification\", properties);\n    trackAmplitude(\"click_notification\", properties);\n  };\n  return trackClickNotificationEvent;\n};\nconst getCurrentScreen = () => new URL(document.location.href).pathname.substring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