1+ import React from 'react' ;
2+
3+ type PricingTier = 'Free' | 'Base' | 'Ultimate' ;
4+
5+ interface PricingBadgeProps {
6+ tags : string [ ] ;
7+ }
8+
9+ const PricingBadge : React . FC < PricingBadgeProps > = ( { tags } ) => {
10+ // Find pricing tags from the tags array
11+ const pricingTags = tags . filter ( ( tag ) : tag is PricingTier =>
12+ [ 'Free' , 'Base' , 'Ultimate' ] . includes ( tag )
13+ ) ;
14+
15+ if ( pricingTags . length === 0 ) return null ;
16+
17+ // Sort by hierarchy and take the highest tier
18+ const sortedTags = pricingTags . sort ( ( a , b ) => {
19+ const order : Record < PricingTier , number > = { 'Free' : 0 , 'Base' : 1 , 'Ultimate' : 2 } ;
20+ return order [ a ] - order [ b ] ;
21+ } ) ;
22+
23+ const primaryPlan = sortedTags [ sortedTags . length - 1 ] ;
24+
25+ // Determine which plans have access based on inheritance
26+ const getAvailablePlans = ( plan : PricingTier ) : PricingTier [ ] => {
27+ switch ( plan ) {
28+ case 'Free' :
29+ return [ 'Free' , 'Base' , 'Ultimate' ] ;
30+ case 'Base' :
31+ return [ 'Base' , 'Ultimate' ] ;
32+ case 'Ultimate' :
33+ return [ 'Ultimate' ] ;
34+ }
35+ } ;
36+
37+ const availablePlans = getAvailablePlans ( primaryPlan ) ;
38+
39+ const getBadgeColor = ( plan : PricingTier ) => {
40+ switch ( plan ) {
41+ case 'Free' :
42+ return '#10b981' ; // green
43+ case 'Base' :
44+ return '#3b82f6' ; // blue
45+ case 'Ultimate' :
46+ return '#f59e0b' ; // amber
47+ }
48+ } ;
49+
50+ return (
51+ < div className = "pricing-badge-container" >
52+ < div className = "pricing-badge-header" >
53+ < span
54+ className = "pricing-badge-main"
55+ style = { {
56+ backgroundColor : getBadgeColor ( primaryPlan ) ,
57+ color : 'white' ,
58+ padding : '0.25rem 0.75rem' ,
59+ borderRadius : '0.375rem' ,
60+ fontSize : '0.875rem' ,
61+ fontWeight : 600
62+ } }
63+ >
64+ Available on { primaryPlan }
65+ </ span >
66+ </ div >
67+ < div className = "pricing-badge-details" >
68+ < span style = { { fontSize : '0.875rem' , color : '#6b7280' } } >
69+ This service is available on: { ' ' }
70+ </ span >
71+ { availablePlans . map ( ( plan , index ) => (
72+ < span key = { plan } >
73+ < span
74+ style = { {
75+ fontWeight : 600 ,
76+ color : getBadgeColor ( plan )
77+ } }
78+ >
79+ { plan }
80+ </ span >
81+ { index < availablePlans . length - 1 && (
82+ < span style = { { color : '#6b7280' } } > • </ span >
83+ ) }
84+ </ span >
85+ ) ) }
86+ </ div >
87+ </ div >
88+ ) ;
89+ } ;
90+
91+ export { PricingBadge } ;
92+ export default PricingBadge ;
0 commit comments