import Link from "@/components/Link";
import { ExternalLink, Hourglass, KeyRound, Rocket, Wrench, X } from "lucide-react";
import type { ProductNeedView, ProductReview, ProjectProduct, PublishMode } from "@peppa/core";
import { Hidden } from "@/components/cards";
import { ago } from "@/components/common";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { getT } from "@/lib/i18n";
import { deployProdAction, removeNeedAction, saveProjectSecretAction, setNeedDoneAction } from "@/app/(app)/actions";
import { wording } from "@peppa/shared/wording";
const host = (url: string) => url.replace(/^https?:\/\//, "");
/**
* PEP-111: «Ваш продукт» on the project page — where the result is and what to do next, for a
* product manager who asks «где это работает?». PEP-145: one big «Открыть продукт»; without a
* link — the honest status («Готовим ссылку», the system story), never «попросите аналитика».
*/
export async function ProductCard({
product,
projectKey,
chat = true,
engineer = false,
projectId,
needs = [],
review = null,
back,
publish = "button",
}: {
product: ProjectProduct;
projectKey: string;
chat?: boolean;
/** PEP-119: «Инженер» gets the link to the releases tab, «Продакт» — the button right here. */
engineer?: boolean;
projectId?: number;
/** PEP-112: what the owner has to give before the product is real. */
needs?: ProductNeedView[];
/** PEP-112: the product agent's last acceptance. */
review?: ProductReview | null;
back?: string;
/** PEP-145: «Показывать всем: сам» — no button, Peppa shows the version to everyone itself. */
publish?: PublishMode;
}) {
const t = await getT();
// «Показать всем»: the same action as the button in «Релизы», without sending a product manager there.
const showAll = engineer ? (
<>
{t("показать её всем можно в")} {t("Релизах")}.
>
) : (
);
const { task } = wording(engineer ? "engineer" : "product", t.locale);
const { live, check, doneStories } = product;
const open = needs.filter((n) => n.open);
if (!live && !check && doneStories === 0 && !open.length && !product.preparing && !product.stalled) return null;
// PEP-145: one big button — the working product, else the version to check.
const link = live ?? check;
const deployed = !!(live || check);
const mayEdit = chat && projectId != null && !!back;
const next = chat && (
{live ? t("Ваш продукт работает") : t("Ваш продукт готов — пока его видите только вы")}
{product.versionDone && {t("Готово")}}
{live ? t("Открыт для всех по адресу") : t("Адрес:")} {host(link.url)} · {t("обновлён {when}", { when: ago(link.at, t) })}
{link.stories.length > 0 && <> · {t("вошли {tasks} {keys}", { tasks: task("pl"), keys: link.stories.slice(0, 6).join(", ") })}>}
{!live && (
{publish === "auto" ? t("Когда задачи этой версии будут приняты, FORGE сама покажет её всем.") : <>{t("Посмотрите — и, если всё хорошо,")} {showAll}>}
)}
) : product.stalled ? (
// PEP-274: the wait ran out — an error in two phrases (what happened, what to do), not an endless «готовим».
{t("Ссылка на продукт пока не открывается")}
{product.fix ? (
<>
{t("Агент уже чинит это:")} {product.fix.key}. {t("Ссылка появится здесь сама, делать ничего не нужно.")}
>
) : (
<>
{t("Запустить продукт пока не получилось. Если ссылка нужна срочно —")} {t("напишите аналитику в чате")}.
>
)}
) : product.preparing || doneStories > 0 ? (
{t("Готовим ссылку на продукт")}
{product.fix ? (
<>
{product.fix.working ? t("Агент уже этим занят:") : t("Агент возьмёт это первым:")} {product.fix.key}. {t("Ссылка появится здесь, делать ничего не нужно.")}
>
) : product.preparing ? (
t("Продукт запускается — ссылка появится здесь через несколько минут.")
) : (
t("Ссылка появится здесь сама — делать ничего не нужно. Что уже получилось — на странице каждой готовой {task}.", { task: task("gen") })
)}
) : null}
{link && product.broken && (
{t("Последнее обновление не запустилось — по ссылке открывается прежняя версия. Чиним.")}{" "}
{product.fix && {product.fix.key}}
)}
{live && check && (
{t("Есть новая версия для проверки:")}{" "}
{host(check.url)}
{check.stories.length > 0 && ({check.stories.slice(0, 6).join(", ")})} — {publish === "auto" ? t("FORGE покажет её всем сама, когда задачи будут приняты.") : showAll}
)}
{open.length > 0 && (
{deployed ? t("Работает в демо-режиме — чтобы заработало по-настоящему, нужно от вас:") : t("Продукт будет работать в демо-режиме — чтобы заработало по-настоящему, нужно от вас:")}
{t("Пока этого нет, продукт показывает примеры вместо настоящей работы. Ключи хранятся зашифрованными; FORGE сама передаст их продукту и перезапустит его — через пару минут после сохранения.")}