import { redirect } from 'next/navigation';
import { Suspense } from 'react';
import { getMe } from '@/features/auth/api.server';
import { CreateGoalWizard } from '@/features/goals/ui/CreateGoalWizard';

export const metadata = { title: 'Create a goal' };

/**
 * Create a goal (QA #345, 13 Nov design create-goal.php): a full-window wizard without the side
 * menu and top bar, like the design's separate page.
 */
export default async function CreateGoalPage() {
  // Creating goals needs "Manage targets" (QA #583); the API refuses it otherwise.
  const me = await getMe();
  if (!me.permissionSet.rules.app.manage_targets) redirect('/goals');
  return (
    <Suspense>
      <CreateGoalWizard />
    </Suspense>
  );
}
