import React, { useEffect, useState } from "react"; import { Tag } from "primereact/tag"; import Image from "next/image"; import { useImageProxy } from "@/hooks/useImageProxy"; import { getTotalFromZaps } from "@/utils/lightning"; import ZapDisplay from "@/components/zaps/ZapDisplay"; import dynamic from "next/dynamic"; import { useZapsQuery } from "@/hooks/nostrQueries/zaps/useZapsQuery"; const MDDisplay = dynamic( () => import("@uiw/react-markdown-preview"), { ssr: false, } ); const CourseLesson = ({ lesson, course, decryptionPerformed, isPaid }) => { const [zapAmount, setZapAmount] = useState(0); const { zaps, zapsLoading, zapsError } = useZapsQuery({ event: lesson, type: "lesson" }); const { returnImageProxy } = useImageProxy(); useEffect(() => { if (!zaps || zapsLoading || zapsError) return; const total = getTotalFromZaps(zaps, lesson); setZapAmount(total); }, [zaps, zapsLoading, zapsError, lesson]); const renderContent = () => { if (isPaid && decryptionPerformed) { return ; } if (isPaid && !decryptionPerformed) { return

This content is paid and needs to be purchased before viewing.

; } if (lesson?.content) { return ; } return null; } return (
{lesson && lesson.topics && lesson.topics.length > 0 && ( lesson.topics.map((topic, index) => ( )) )}

{lesson?.title}

{lesson?.summary && (

{lesson.summary.split('\n').map((line, index) => (

{line}

))}
)}

{lesson?.additionalLinks && lesson.additionalLinks.length > 0 && (

External links:

)}
{lesson && (
course thumbnail
)}
{renderContent()}
) } export default CourseLesson;