import { ResourceNotFoundError } from "@formbricks/types/errors";
import { TProject } from "@formbricks/types/project";
import { getProjectByEnvironmentId } from "@/lib/project/service";
import { getTranslate } from "@/lingodotdev/server";
import { SecondaryNavigation } from "@/modules/ui/components/secondary-navigation";

interface PersonSecondaryNavigationProps {
  activeId: string;
  environmentId?: string;
  loading?: boolean;
}

export const ContactsSecondaryNavigation = async ({
  activeId,
  environmentId,
  loading,
}: PersonSecondaryNavigationProps) => {
  let project: TProject | null = null;
  const t = await getTranslate();
  if (!loading && environmentId) {
    project = await getProjectByEnvironmentId(environmentId);

    if (!project) {
      throw new ResourceNotFoundError(t("common.workspace"), null);
    }
  }

  const navigation = [
    {
      id: "contacts",
      label: t("common.contacts"),
      href: `/environments/${environmentId}/contacts`,
    },
    {
      id: "attributes",
      label: t("common.attributes"),
      href: `/environments/${environmentId}/attributes`,
    },
    {
      id: "segments",
      label: t("common.segments"),
      href: `/environments/${environmentId}/segments`,
    },
  ];

  return <SecondaryNavigation navigation={navigation} activeId={activeId} loading={loading} />;
};
