@@ -10,10 +10,49 @@ interface BrandTabContentProps {
1010 calculateBrandStats : BrandStats | null ;
1111}
1212
13+ // Helper function to get color based on score
14+ const getScoreColor = ( score : number ) : string => {
15+ if ( score <= 2 ) return colours . score . low ;
16+ if ( score <= 3 ) return colours . score . medium ;
17+ return colours . score . high ;
18+ } ;
19+
20+ // Helper function to get background color with opacity
21+ const getScoreBackgroundColor = ( score : number ) : string => {
22+ return getScoreColor ( score ) + '20' ; // 20% opacity
23+ } ;
24+
25+ // Performance metrics configuration
26+ const PERFORMANCE_METRICS = [
27+ {
28+ label : 'Price' ,
29+ color : '#fef3c7' , /* yellow-100 */
30+ svg : '/pound-svgrepo-com.svg'
31+ } ,
32+ {
33+ label : 'Quality' ,
34+ color : '#fee2e2' , /* red-100 */
35+ svg : '/quality-supervision-svgrepo-com.svg'
36+ } ,
37+ {
38+ label : 'Nutrition' ,
39+ color : '#dbeafe' , /* blue-100 */
40+ svg : '/meal-svgrepo-com.svg'
41+ } ,
42+ {
43+ label : 'Sustainability' ,
44+ color : '#ecfccb' , /* lime-100 */
45+ svg : '/leaf-svgrepo-com.svg'
46+ }
47+ ] ;
48+
1349const BrandTabContent : React . FC < BrandTabContentProps > = ( {
1450 animatedBrand,
1551 calculateBrandStats,
1652} ) => {
53+ const strokeColor = getScoreColor ( animatedBrand ) ;
54+ const backgroundColor = getScoreBackgroundColor ( animatedBrand ) ;
55+
1756 return (
1857 < div className = "w-full flex flex-col items-center opacity-0 animate-fade-in px-1" style = { { animationDelay : '0.05s' } } >
1958 < h2
@@ -49,31 +88,16 @@ const BrandTabContent: React.FC<BrandTabContentProps> = ({
4988 < div
5089 className = "relative w-16 h-16 rounded-full border-2 border-dashed flex items-center justify-center"
5190 style = { {
52- borderColor : ( ( ) => {
53- const score = animatedBrand ;
54- if ( score <= 2 ) return colours . score . low ;
55- if ( score <= 3 ) return colours . score . medium ;
56- return colours . score . high ;
57- } ) ( ) ,
58- backgroundColor : ( ( ) => {
59- const score = animatedBrand ;
60- if ( score <= 2 ) return colours . score . low + '20' ;
61- if ( score <= 3 ) return colours . score . medium + '20' ;
62- return colours . score . high + '20' ;
63- } ) ( ) ,
91+ borderColor : strokeColor ,
92+ backgroundColor : backgroundColor ,
6493 } }
6594 >
6695 < span className = "relative inline-block w-12 h-12 align-middle" >
6796 < svg width = "48" height = "48" viewBox = "0 0 48 48" className = "absolute top-0 left-0" style = { { zIndex : 1 } } >
6897 < circle
6998 cx = "24" cy = "24" r = "18"
7099 fill = "none"
71- stroke = { ( ( ) => {
72- const score = animatedBrand ;
73- if ( score <= 2 ) return colours . score . low ;
74- if ( score <= 3 ) return colours . score . medium ;
75- return colours . score . high ;
76- } ) ( ) }
100+ stroke = { strokeColor }
77101 strokeWidth = "3"
78102 strokeDasharray = { Math . PI * 2 * 18 }
79103 strokeDashoffset = { Math . PI * 2 * 18 * ( 1 - ( animatedBrand / 5 ) ) }
@@ -88,14 +112,7 @@ const BrandTabContent: React.FC<BrandTabContentProps> = ({
88112 < div className = "absolute inset-0 flex flex-col items-center justify-center" >
89113 < span
90114 className = "text-xl font-bold"
91- style = { {
92- color : ( ( ) => {
93- const score = animatedBrand ;
94- if ( score <= 2 ) return colours . score . low ;
95- if ( score <= 3 ) return colours . score . medium ;
96- return colours . score . high ;
97- } ) ( )
98- } }
115+ style = { { color : strokeColor } }
99116 >
100117 { animatedBrand }
101118 </ span >
@@ -126,38 +143,15 @@ const BrandTabContent: React.FC<BrandTabContentProps> = ({
126143 { calculateBrandStats ? (
127144 < div className = "w-full" >
128145 < div className = "space-y-3" >
129- { [
130- {
131- label : 'Price' ,
132- value : calculateBrandStats . price ,
133- color : '#fef3c7' , /* yellow-100 */
134- svg : '/pound-svgrepo-com.svg'
135- } ,
136- {
137- label : 'Quality' ,
138- value : calculateBrandStats . quality ,
139- color : '#fee2e2' , /* red-100 */
140- svg : '/quality-supervision-svgrepo-com.svg'
141- } ,
142- {
143- label : 'Nutrition' ,
144- value : calculateBrandStats . nutrition ,
145- color : '#dbeafe' , /* blue-100 */
146- svg : '/meal-svgrepo-com.svg'
147- } ,
148- {
149- label : 'Sustainability' ,
150- value : calculateBrandStats . sustainability ,
151- color : '#ecfccb' , /* lime-100 */
152- svg : '/leaf-svgrepo-com.svg'
153- }
154- ] . map ( ( stat , index ) => {
155- const percentage = ( ( stat . value - 1 ) / 4 ) * 100 ;
146+ { PERFORMANCE_METRICS . map ( ( metric , index ) => {
147+ const value = calculateBrandStats [ metric . label . toLowerCase ( ) as keyof BrandStats ] as number ;
148+ const percentage = ( ( value - 1 ) / 4 ) * 100 ;
149+
156150 return (
157- < div key = { stat . label } className = "flex items-center gap-3" >
151+ < div key = { metric . label } className = "flex items-center gap-3" >
158152 < Image
159- src = { stat . svg }
160- alt = { stat . label }
153+ src = { metric . svg }
154+ alt = { metric . label }
161155 width = { 16 }
162156 height = { 16 }
163157 className = "flex-shrink-0"
@@ -176,7 +170,7 @@ const BrandTabContent: React.FC<BrandTabContentProps> = ({
176170 className = "transition-all duration-1000 ease-out absolute inset-0 rounded-lg opacity-0 animate-fade-in"
177171 style = { {
178172 width : `${ percentage } %` ,
179- backgroundColor : stat . color ,
173+ backgroundColor : metric . color ,
180174 border : `2px solid ${ colours . card . border } ` ,
181175 animationDelay : `${ 0.3 + index * 0.1 } s`
182176 } }
@@ -187,7 +181,7 @@ const BrandTabContent: React.FC<BrandTabContentProps> = ({
187181 className = "text-xs font-medium w-8 text-right flex-shrink-0"
188182 style = { { color : colours . text . primary } }
189183 >
190- { stat . value . toFixed ( 1 ) }
184+ { value . toFixed ( 1 ) }
191185 </ span >
192186 </ div >
193187 ) ;
0 commit comments