import { notFound } from "next/navigation";
import { getActivityLog, getUpcomingReminders, getTranscripts } from "@/lib/lead-service";
import {
  getLeadByIdWithTags,
  getLeadFieldOptions,
  getClientIdFromLead,
} from "@/lib/admin-queries";
import { LeadDetail } from "@/components/admin/leads/LeadDetail";

export default async function LeadDetailPage({ params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;

  const [lead, options, convertedClientId] = await Promise.all([
    getLeadByIdWithTags(id),
    getLeadFieldOptions(),
    getClientIdFromLead(id),
  ]);

  if (!lead) {
    notFound();
  }

  const [activities, reminders, transcripts] = await Promise.all([
    getActivityLog(id),
    getUpcomingReminders(id),
    getTranscripts(id),
  ]);

  return (
    <LeadDetail
      lead={lead}
      activities={activities}
      reminders={reminders}
      tags={lead.tags}
      tagOptions={options.tags}
      transcripts={transcripts}
      convertedClientId={convertedClientId}
    />
  );
}
