"use client"
import { LABELS } from "@/app/labels"
import { AppLink } from "@/components/app-link"
import { Banner } from "@/components/banner"
import { Card } from "@/components/cards/card"
import { TableRowCard } from "@/components/cards/table-row-card"
import { Divider } from "@/components/divider"
import { Icons } from "@/components/icons"
import { PageHeader } from "@/components/page-header"
import { Accordion } from "@/components/ui/accordion"
import { Button } from "@/components/ui/button"
import { siteConfig } from "@/config/site"
import { cn, interpolate } from "@/lib/utils"
import Image from "next/image"
import { useCallback, useEffect, useRef, useState } from "react"
import { ReactNode } from "react-markdown/lib/ast-to-react"
import { twMerge } from "tailwind-merge"
type ProgramDetailProps = {
region?: string
title: ReactNode
deadline?: string
location?: string
date: string
}
const SectionTitle = ({ label }: { label: string }) => {
return (
{label}
)
}
const AccordionLabel = ({
label,
className,
}: {
label: string
className?: string
}) => {
return (
{label}
)
}
const ProgramDetail = ({
title,
location,
date,
region,
deadline,
}: ProgramDetailProps) => {
return (
{region}
{title}
{deadline && (
Application Deadline: {deadline}
)}
{location && (
{location}
)}
{date}
)
}
const ProgramSections = ["coreProgram", "accelerationProgram"] as const
export const ProgramPageContent = () => {
const [activeId, setActiveId] = useState("")
const [isManualScroll, setIsManualScroll] = useState(false)
const SCROLL_OFFSET = -900
const sectionsRef = useRef | null>(null)
const howToApply = LABELS.PROGRAMS_PAGE.HOW_TO_APPLY
const coreProgramDescription = LABELS.PROGRAMS_PAGE.CORE_PROGRAM.DESCRIPTION
const accelerationProgramDescription =
LABELS.PROGRAMS_PAGE.ACCELERATION_PROGRAM.DESCRIPTION
const curriculum = LABELS.PROGRAMS_PAGE.CURRICULUM
useEffect(() => {
if (sectionsRef.current === null)
sectionsRef.current = document.querySelectorAll("div[data-section]")
if (!activeId) setActiveId(ProgramSections?.[0] ?? "")
const handleScroll = () => {
if (isManualScroll) return
sectionsRef.current?.forEach((section: any) => {
const sectionTop = section.offsetTop - SCROLL_OFFSET
if (window.scrollY >= sectionTop && window.scrollY > 0) {
setActiveId(section.getAttribute("id"))
}
})
}
window.addEventListener("scroll", handleScroll)
return () => window.removeEventListener("scroll", handleScroll)
}, [SCROLL_OFFSET, activeId, isManualScroll])
const scrollToId = useCallback((id: string) => {
const element = document.getElementById(id)
const scrollTop = document.documentElement.scrollTop
const rectViewportTop = element?.getBoundingClientRect()?.top ?? 0
const top = rectViewportTop + scrollTop
if (element) {
setActiveId(id) // active clicked id
setIsManualScroll(true) // tell the window event listener to ignore this scrolling
window?.scrollTo({
behavior: "smooth",
top,
})
}
setTimeout(() => setIsManualScroll(false), 800)
}, [])
const getSectionTitle = (sectionId: string) => {
switch (sectionId) {
case "coreProgram":
return LABELS.PROGRAMS_PAGE.CORE_PROGRAM.TITLE
case "accelerationProgram":
return LABELS.PROGRAMS_PAGE.ACCELERATION_PROGRAM.TITLE
default:
return ""
}
}
return (
{LABELS.PROGRAMS_PAGE.COMMON.APPLY_NOW}
{LABELS.PROGRAMS_PAGE.COMMON.APPLY_NOW}
{coreProgramDescription?.map((description, index) => {
return (
{description}
)
})}
({
title: (
{interpolate(LABELS.PROGRAMS_PAGE.COMMON.WEEK, {
week: index,
})}
),
subtitle: TITLE,
items: ITEMS,
}))}
/>
{
return {
label,
value: index.toString(),
children: (
),
}
}
)}
/>
Acceleration Program
Round 2
>
}
deadline="May 31, 2024"
location="Remote Application"
date="June 1, 2024 - August 31, 2024"
/>
{LABELS.PROGRAMS_PAGE.COMMON.LEARN_MORE_ON_GITHUB}
{accelerationProgramDescription?.map((description, index) => {
return (
{description}
)
})}
{LABELS.PROGRAMS_PAGE.HOW_TO_APPLY.OPEN_TASKS.TITLE}
{howToApply.OPEN_TASKS.DESCRIPTION.map(
(task: string, index: number) => {
return (
)
}
)}
{
LABELS.PROGRAMS_PAGE.HOW_TO_APPLY.SUBMIT_IDEA
.TITLE
}
{howToApply.SUBMIT_IDEA.DESCRIPTION.map(
(task: string, index: number) => {
return (
)
}
)}
{LABELS.PROGRAMS_PAGE.HOW_TO_APPLY.DESCRIPTION}
{
return {
label,
value: index.toString(),
children: (
{typeof answer === "string"
? answer
: answer.map((item, index) => {
return {item}
})}
),
}
}
)}
/>
{LABELS.COMMON.JOIN_OUR_DISCORD}
)
}