import { getCurrentUser } from '@/lib/auth';
import { getAdForEdit } from '@/lib/queries';
import { PostAdForm } from '@/components/PostAdForm';

export const dynamic = 'force-dynamic';

export default async function PublierPage({
  searchParams,
}: {
  searchParams: Promise<{ edit?: string }>;
}) {
  const { edit } = await searchParams;
  let initial = undefined;
  if (edit) {
    const user = await getCurrentUser();
    if (user) {
      const ad = getAdForEdit(Number(edit), user.id);
      if (ad) initial = ad;
    }
  }
  return <PostAdForm initial={initial} />;
}
