/**
 * Copyright (c) 2023-present Plane Software, Inc. and contributors
 * SPDX-License-Identifier: AGPL-3.0-only
 * See the LICENSE file for details.
 */

import { observer } from "mobx-react";
import { useSearchParams } from "next/navigation";
import { EInboxIssueCurrentTab } from "@plane/types";
import { useTranslation } from "@plane/i18n";
import { PageHead } from "@/components/core/page-title";
import { useProject } from "@/hooks/store/use-project";
import { ExternalContoursRoot } from "@/plane-web/components/projects/external-contours/root";
import type { Route } from "./+types/page";

function ProjectExternalContoursPage({ params }: Route.ComponentProps) {
  const { workspaceSlug, projectId } = params;
  const searchParams = useSearchParams();
  const navigationTab = searchParams.get("currentTab");
  const inboxIssueId = searchParams.get("inboxIssueId");
  const { t } = useTranslation();
  const { currentProjectDetails } = useProject();

  const pageTitle = currentProjectDetails?.name
    ? t("external_contours_page.page_label", { workspace: currentProjectDetails.name })
    : t("external_contours_page.page_label", { workspace: "NODE.DC" });

  const currentNavigationTab = navigationTab
    ? navigationTab === "open"
      ? EInboxIssueCurrentTab.OPEN
      : EInboxIssueCurrentTab.CLOSED
    : undefined;

  return (
    <div className="flex h-full flex-col">
      <PageHead title={pageTitle} />
      <div className="h-full w-full overflow-hidden">
        <ExternalContoursRoot
          workspaceSlug={workspaceSlug}
          projectId={projectId}
          inboxIssueId={inboxIssueId || undefined}
          navigationTab={currentNavigationTab}
        />
      </div>
    </div>
  );
}

export default observer(ProjectExternalContoursPage);
