import React from "react"
import { Metadata } from "next"
import UpdateReminderContainer from "./section/UpdateReminderContainer"
import { appConfig } from "@/config/app"
import { notFound } from "next/navigation"

type Props = { params: { reminderid: string } }

const fetchReminderDetail: any = async (id: string) => {
  try {
    const res = await fetch(`${appConfig.apiUrl}/reminders/${id}`, {
      method: "GET",
      next: { revalidate: 0 },
    })
    if (!res.ok) throw new Error("Failed to fetch reminders data")
    return res.json()
  } catch (error) {
    console.error("Error fetching reminders data:", error)
    return null
  }
}

export const metadata: Metadata = {
  title: "Reminder",
}

export default async function UpdateReminderPage(props: Props) {
  const { reminderid } = props.params
  const reminder = await fetchReminderDetail(reminderid)

  if (!reminder) notFound()

  return <UpdateReminderContainer reminder={reminder?.data || null} />
}
 