11import type { FECollection } from '../frontend/feFront' ;
22import {
33 decideCollectionBranding ,
4- isPaidContentSameBranding ,
4+ shouldStripBrandingFromCards ,
5+ brandingEqual ,
56} from '../lib/branding' ;
67import type { EditionId } from '../lib/edition' ;
78import type { Branding } from '../types/branding' ;
@@ -77,11 +78,19 @@ export const enhanceCollections = ({
7778 const indexToShowFrontBranding =
7879 findCollectionSuitableForFrontBranding ( collections ) ;
7980
81+ // Track the branding from the first primary container to detect duplicates in subsequent primary containers
82+ let firstPrimaryBranding : Branding | undefined ;
83+
8084 return collections . filter ( isSupported ) . map ( ( collection , index ) => {
8185 const { id, displayName, collectionType, hasMore, href, description } =
8286 collection ;
8387 const allCards = [ ...collection . curated , ...collection . backfill ] ;
84- const collectionBranding = decideCollectionBranding ( {
88+
89+ const isPrimaryContainer =
90+ collection . config . collectionLevel === 'Primary' ;
91+
92+ // First, get the raw collection branding without considering previous containers
93+ const rawCollectionBranding = decideCollectionBranding ( {
8594 frontBranding,
8695 couldDisplayFrontBranding : index === indexToShowFrontBranding ,
8796 cards : allCards ,
@@ -91,8 +100,35 @@ export const enhanceCollections = ({
91100 ( { type } ) => type === 'Branded' ,
92101 ) ?? false ,
93102 } ) ;
94- const stripBrandingFromCards =
95- isPaidContentSameBranding ( collectionBranding ) ;
103+
104+ // Determine if we should hide collection branding due to a previous primary container
105+ const shouldHideCollectionBranding =
106+ isPrimaryContainer &&
107+ ! ! firstPrimaryBranding &&
108+ ! ! rawCollectionBranding ?. branding &&
109+ brandingEqual ( firstPrimaryBranding , rawCollectionBranding . branding ) ;
110+
111+ // The actual collection branding to display (hide if duplicate branding of previous primary)
112+ const collectionBranding = shouldHideCollectionBranding
113+ ? undefined
114+ : rawCollectionBranding ;
115+
116+ // Store the branding from the first primary container
117+ if (
118+ isPrimaryContainer &&
119+ ! firstPrimaryBranding &&
120+ rawCollectionBranding
121+ ) {
122+ firstPrimaryBranding = rawCollectionBranding . branding ;
123+ }
124+
125+ /** Determine if we should strip branding from cards
126+ * We need to check this directly in here because decideCollectionBranding might return undefined
127+ * when cards have same branding as frontBranding, but we still need to strip in that case
128+ */
129+ const stripBrandingFromCards = rawCollectionBranding
130+ ? shouldStripBrandingFromCards ( rawCollectionBranding )
131+ : shouldStripBrandingFromCards ( allCards , editionId ) ;
96132
97133 const containerPalette = decideContainerPalette (
98134 collection . config . metadata ?. map ( ( meta ) => meta . type ) ,
0 commit comments