diff --git a/lib/ebay-parts-visibility.ts b/lib/ebay-parts-visibility.ts new file mode 100644 index 00000000..551e05c1 --- /dev/null +++ b/lib/ebay-parts-visibility.ts @@ -0,0 +1,43 @@ +import type { EbayCacheState } from "@/lib/ebay-parts-match" + +type PartLike = { + ebayListings?: Array +} + +const HIDDEN_CACHE_STATUSES = new Set([ + "rate_limited", + "missing_config", + "disabled", + "error", +]) + +export function hasTrustedPartsListings(parts: PartLike[]) { + return parts.some((part) => (part.ebayListings || []).length > 0) +} + +export function shouldShowEbayPartsPanel(args: { + isLoading: boolean + parts: PartLike[] + cache: EbayCacheState | null + error: string | null +}) { + if (args.isLoading) { + return true + } + + const hasListings = hasTrustedPartsListings(args.parts) + if (hasListings) { + return true + } + + const status = args.cache?.status || "idle" + if (HIDDEN_CACHE_STATUSES.has(status)) { + return false + } + + if (args.error) { + return false + } + + return false +}