import type {FunctionComponent} from 'react'
import PageTitle from '@/components/custom/pageTitle'
import MeetingForm from '@/app/(authenticated)/meetings/meetingForm'
import {getMeeting} from '@/dal/meetings'
import {getContacts} from '@/dal/contacts'
import {getSessionProfileFromCookieOrThrow} from '@/lib/sessionUtils'

interface MeetingDetailPageParams {
  params: Promise<{
    meetingId: string
  }>
}

const MeetingDetailPage: FunctionComponent<MeetingDetailPageParams> = async ({params}) => {
  const {meetingId} = await params
  const profile = await getSessionProfileFromCookieOrThrow()
  const [meeting, contacts] = await Promise.all([getMeeting(meetingId, profile.id), getContacts(profile.id)])

  return (
    <>
      <div className="flex justify-between items-center mb-6">
        <PageTitle>My meetings</PageTitle>
      </div>

      <MeetingForm contacts={contacts} meeting={meeting} />
    </>
  )
}

export default MeetingDetailPage
