| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  | 'use client' | 
					
						
							|  |  |  | import type { FC } from 'react' | 
					
						
							|  |  |  | import React from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import ProgressBar from '../progress-bar' | 
					
						
							|  |  |  | import { NUM_INFINITE } from '../config' | 
					
						
							|  |  |  | import Tooltip from '@/app/components/base/tooltip' | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | type Props = { | 
					
						
							|  |  |  |   className?: string | 
					
						
							|  |  |  |   Icon: any | 
					
						
							|  |  |  |   name: string | 
					
						
							|  |  |  |   tooltip?: string | 
					
						
							|  |  |  |   usage: number | 
					
						
							|  |  |  |   total: number | 
					
						
							|  |  |  |   unit?: string | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const LOW = 50 | 
					
						
							|  |  |  | const MIDDLE = 80 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const UsageInfo: FC<Props> = ({ | 
					
						
							|  |  |  |   className, | 
					
						
							|  |  |  |   Icon, | 
					
						
							|  |  |  |   name, | 
					
						
							|  |  |  |   tooltip, | 
					
						
							|  |  |  |   usage, | 
					
						
							|  |  |  |   total, | 
					
						
							|  |  |  |   unit = '', | 
					
						
							|  |  |  | }) => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const percent = usage / total * 100 | 
					
						
							|  |  |  |   const color = (() => { | 
					
						
							|  |  |  |     if (percent < LOW) | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |       return 'bg-components-progress-bar-progress-solid' | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (percent < MIDDLE) | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |       return 'bg-components-progress-warning-progress' | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |     return 'bg-components-progress-error-progress' | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  |   })() | 
					
						
							|  |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |     <div className={cn('flex flex-col gap-2 rounded-xl bg-components-panel-bg p-4', className)}> | 
					
						
							|  |  |  |       <Icon className='h-4 w-4 text-text-tertiary' /> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |       <div className='flex items-center gap-1'> | 
					
						
							|  |  |  |         <div className='system-xs-medium text-text-tertiary'>{name}</div> | 
					
						
							|  |  |  |         {tooltip && ( | 
					
						
							|  |  |  |           <Tooltip | 
					
						
							|  |  |  |             popupContent={ | 
					
						
							|  |  |  |               <div className='w-[180px]'> | 
					
						
							|  |  |  |                 {tooltip} | 
					
						
							|  |  |  |               </div> | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         )} | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <div className='system-md-semibold flex items-center gap-1  text-text-primary'> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |         {usage} | 
					
						
							|  |  |  |         <div className='system-md-regular text-text-quaternary'>/</div> | 
					
						
							|  |  |  |         <div>{total === NUM_INFINITE ? t('billing.plansCommon.unlimited') : `${total}${unit}`}</div> | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2025-03-07 11:56:20 +08:00
										 |  |  |       <ProgressBar | 
					
						
							|  |  |  |         percent={percent} | 
					
						
							|  |  |  |         color={color} | 
					
						
							|  |  |  |       /> | 
					
						
							| 
									
										
										
										
											2023-12-03 22:10:16 +08:00
										 |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | export default React.memo(UsageInfo) |