import { redirect } from 'next/navigation';

/**
 * Google sends the browser back here after connecting Google Calendar
 * (`?connected=1` or `?error=<code>`, see the API's /calendars/google/callback).
 * The setting lives on the General page, Calendar tab.
 */
export default async function CalendarConnectReturn({
  searchParams,
}: {
  searchParams: Promise<{ connected?: string; error?: string }>;
}) {
  const { connected, error } = await searchParams;
  const result = error ? `error-${encodeURIComponent(error)}` : connected ? 'connected' : '';
  redirect(`/settings/profile${result ? `?calendar=${result}` : ''}#tab-calendar`);
}
