| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | import { useState } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   RiCloseLine, | 
					
						
							|  |  |  |   RiDownloadLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							|  |  |  | import FileImageRender from '../file-image-render' | 
					
						
							|  |  |  | import type { FileEntity } from '../types' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   downloadFile, | 
					
						
							|  |  |  |   fileIsUploaded, | 
					
						
							|  |  |  | } from '../utils' | 
					
						
							|  |  |  | import Button from '@/app/components/base/button' | 
					
						
							|  |  |  | import ProgressCircle from '@/app/components/base/progress-bar/progress-circle' | 
					
						
							|  |  |  | import { ReplayLine } from '@/app/components/base/icons/src/vender/other' | 
					
						
							|  |  |  | import ImagePreview from '@/app/components/base/image-uploader/image-preview' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | type FileImageItemProps = { | 
					
						
							|  |  |  |   file: FileEntity | 
					
						
							|  |  |  |   showDeleteAction?: boolean | 
					
						
							|  |  |  |   showDownloadAction?: boolean | 
					
						
							|  |  |  |   canPreview?: boolean | 
					
						
							|  |  |  |   onRemove?: (fileId: string) => void | 
					
						
							|  |  |  |   onReUpload?: (fileId: string) => void | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | const FileImageItem = ({ | 
					
						
							|  |  |  |   file, | 
					
						
							|  |  |  |   showDeleteAction, | 
					
						
							|  |  |  |   showDownloadAction, | 
					
						
							|  |  |  |   canPreview, | 
					
						
							|  |  |  |   onRemove, | 
					
						
							|  |  |  |   onReUpload, | 
					
						
							|  |  |  | }: FileImageItemProps) => { | 
					
						
							|  |  |  |   const { id, progress, base64Url, url, name } = file | 
					
						
							|  |  |  |   const [imagePreviewUrl, setImagePreviewUrl] = useState('') | 
					
						
							| 
									
										
										
										
											2025-04-30 22:47:59 +08:00
										 |  |  |   const download_url = url ? `${url}&as_attachment=true` : base64Url | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <> | 
					
						
							|  |  |  |       <div | 
					
						
							|  |  |  |         className='group/file-image relative cursor-pointer' | 
					
						
							| 
									
										
										
										
											2024-12-10 10:53:37 +08:00
										 |  |  |         onClick={() => canPreview && setImagePreviewUrl(base64Url || url || '')} | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           showDeleteAction && ( | 
					
						
							|  |  |  |             <Button | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               className='absolute -right-1.5 -top-1.5 z-[11] hidden h-5 w-5 rounded-full p-0 group-hover/file-image:flex' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               onClick={() => onRemove?.(id)} | 
					
						
							|  |  |  |             > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |               <RiCloseLine className='h-4 w-4 text-components-button-secondary-text' /> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |             </Button> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         <FileImageRender | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='h-[68px] w-[68px] shadow-md' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |           imageUrl={base64Url || url || ''} | 
					
						
							|  |  |  |           showDownloadAction={showDownloadAction} | 
					
						
							|  |  |  |         /> | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           progress >= 0 && !fileIsUploaded(file) && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             <div className='absolute inset-0 z-10 flex items-center justify-center border-[2px] border-effects-image-frame bg-background-overlay-alt'> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               <ProgressCircle | 
					
						
							|  |  |  |                 percentage={progress} | 
					
						
							|  |  |  |                 size={12} | 
					
						
							|  |  |  |                 circleStrokeColor='stroke-components-progress-white-border' | 
					
						
							|  |  |  |                 circleFillColor='fill-transparent' | 
					
						
							|  |  |  |                 sectorFillColor='fill-components-progress-white-progress' | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           progress === -1 && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             <div className='absolute inset-0 z-10 flex items-center justify-center border-[2px] border-state-destructive-border bg-background-overlay-destructive'> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               <ReplayLine | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 className='h-5 w-5' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 onClick={() => onReUpload?.(id)} | 
					
						
							|  |  |  |               /> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |           showDownloadAction && ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             <div className='absolute inset-0.5 z-10 hidden bg-background-overlay-alt bg-opacity-[0.3] group-hover/file-image:block'> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 className='absolute bottom-0.5 right-0.5  flex h-6 w-6 items-center justify-center rounded-lg bg-components-actionbar-bg shadow-md' | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 onClick={(e) => { | 
					
						
							|  |  |  |                   e.stopPropagation() | 
					
						
							| 
									
										
										
										
											2025-04-30 22:47:59 +08:00
										 |  |  |                   downloadFile(download_url || '', name) | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |                 }} | 
					
						
							|  |  |  |               > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |                 <RiDownloadLine className='h-4 w-4 text-text-tertiary' /> | 
					
						
							| 
									
										
										
										
											2024-10-21 10:32:37 +08:00
										 |  |  |               </div> | 
					
						
							|  |  |  |             </div> | 
					
						
							|  |  |  |           ) | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |       { | 
					
						
							|  |  |  |         imagePreviewUrl && canPreview && ( | 
					
						
							|  |  |  |           <ImagePreview | 
					
						
							|  |  |  |             title={name} | 
					
						
							|  |  |  |             url={imagePreviewUrl} | 
					
						
							|  |  |  |             onCancel={() => setImagePreviewUrl('')} | 
					
						
							|  |  |  |           /> | 
					
						
							|  |  |  |         ) | 
					
						
							|  |  |  |       } | 
					
						
							|  |  |  |     </> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default FileImageItem |