import { ArrowSquareOut } from "@phosphor-icons/react";
import type { CompetitorTextPayload, MarkedToken, PageWord, ResearchPayload, Resource, TextColumn, TextPart } from "./api";
import { amazonListingUrl, ResearchInfo, ResearchSection } from "./ResearchSummary";
import { searchValue } from "./WhoTargets";
function WordChip({ word, theirs }: { word: PageWord; theirs: boolean }) {
const money = searchValue(word.mkt, "money");
const tip = theirs ? `On ${word.n} of ${word.N} competitors' pages. ${money} spent on searches with it.${word.fits ? "" : " Nothing shows it fits this product."}`
: `${word.n ? `On ${word.n} of ${word.N} competitors' pages` : "On no competitor's page"}. ${word.mkt == null ? "Search money not reported." : word.mkt ? `${money} spent on searches with it, ${searchValue(word.our, "money")} with you.` : "No search in the report uses it."}`;
return {word.word}
{theirs && {word.n} of {word.N}}{word.mkt === 0 ? "no searches" : money};
}
export function WordGap({ data }: { data: CompetitorTextPayload }) {
const theirs = data.theirs84, yours = data.yours84;
return
Gap
They have, you don't{theirs.length} words
{theirs.filter(word => word.fits).map(word => )}
{!theirs.some(word => word.fits) && None that fit this product}
{theirs.some(word => !word.fits) &&
Also on their pages, not fitting this product: {theirs.filter(word => !word.fits).map(word => word.word).join(", ")}
}
Only youYou have, they don't
{yours.length} words
{yours.filter(word => word.mkt !== 0).map(word => )}
{yours.some(word => word.mkt === 0) &&
No search uses: {yours.filter(word => word.mkt === 0).map(word => word.word).join(", ")}. Keep them only if they help the shopper decide.
}
;
}
export function markedWords(tokens: MarkedToken[]) {
return tokens.map((token, index) => typeof token === "string" ? token
: {token.mark});
}
function TextCard({ column, descriptionUnavailable }: { column: TextColumn; descriptionUnavailable: boolean }) {
return
{column.id === "you" ? "You, live" : column.name}
{column.m.group_rank != null && #{column.m.group_rank.toLocaleString("en-US")}}
{column.id !== "you" && }
{column.bullets ?
{column.bullets.map((bullet, index) =>
- {markedWords(column.marks[index] ?? [bullet])}
)}
:
{column.text ? markedWords(column.marks[0] ?? [column.text]) :
{descriptionUnavailable ? "Description not available from this source" : "Not on this listing"}}
}
;
}
export function CompetitorTextContent({ data, part }: { data?: CompetitorTextPayload; part: TextPart }) {
return
Competitors from Setup: {data?.picks.map(pick => pick.brand || pick.a).join(", ") || (data?.hasCompetitors ? "Not available" : "none")}
{data?.hasCompetitors ?
:
No competitors selected in Setup
}
{part !== "terms" &&
{data?.cols.map(column =>
)}
}
{[...new Set([data?.note, ...(data?.constraints ?? []),
part === "terms" ? "Backend search terms are hidden on every listing, so there is no text to compare. The keywords below still work."
: part === "highlights" ? "Competitors' item highlights are not in Amazon's API. Their titles are shown." : null])]
.filter((note): note is string => !!note).map(note =>
{note}
)}
;
}
export function CompetitorText({ resource, retry, part }: { resource: Resource; retry: () => void; part: TextPart }) {
return
{data => };
}