{"version":3,"file":"Notification.hooks.TciSW003.mjs","names":["useEffect","__esmMin","init_npm_react_18_3_1","init_ssg_sandbox_shims","window","ce","init_framer_ChujFWHC","useRequestUserAgreementBottomSheet","init_location","useNotificationRequirements","init_useWithLogin","isContentOrigin","init_useRequestUserAgreementBottomSheet","isClient","useWithApp","init_source","init_useNotificationRequirements","init_useDialog","useWithLogin","init_context","useDialog","init_dist","init_content_store","useAnalytics","useSWR","init_useAnalytics","useContentStore","init_useWithApp","useIsNotificationRegistered","isNotificationAlreadyRegistered","init_useIsNotificationRegistered","key","isRegistered","mutate","NOTIFICATION_AGREEMENTS_API_END_POINT","ACCESS_FROM_APP_MESSAGE","useNotification","useTrackClickNotificationEvent","getCurrentScreen","init_Notification_hooks","options","requestRequirements","isTargetAppVersion","requestUserAgreementBottomSheet","trackClickNotificationEvent","markAsRegistered","dialog","withLogin","withApp","onNotificationEnabled","_a","trackFirebase","trackAmplitude","contentId","properties"],"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(1);\nexport {\n  useNotification,\n  useTrackClickNotificationEvent\n};\n"],"mappings":"A,yaAMM4B,EAA+BG,GAAQ,CAC3C,GAAM,CACJ,KAAMC,EACNC,UACET,EAAOO,MACFlB,EAAS,EAAIgB,EAAgCE,CAAG,EAAI,EAC5D,EAcD,OANA/B,MAAgB,CACT+B,GAGLE,EAAO,CACT,EAAG,CAACF,EAAKE,CAAM,CAAC,EACT,CACLD,eACA,qBAf6B,CACxBD,IAGL3B,EAAO,aAAa,QAAQ2B,EAAK,MAAM,EACvCE,EAAO,EACT,CAUA,CACF,EACMJ,EAAmCE,GAAQ,CAC/C,GAAI,CAEF,OADc,KAAK,MAAM3B,EAAO,aAAa,QAAQ2B,CAAG,GAAK,OAClD,IAAM,EACnB,MAAgB,CACd,MAAO,EACT,CACF,C,uFC7BMG,EAAwC,sBACxCC,EAA0B;mBAC1BC,GAAmBL,EAAKS,IAAY,CACxC,IAAMC,EAAsBhC,EAA4B,EAClD,CACJiC,qBACAC,mCACEpC,EAAmC,EACjCqC,EAA8BP,EAA+BN,CAAG,EAChE,CACJC,eACAa,oBACEjB,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