| 1 | "use client"; |
| 2 | |
| 3 | import { Button } from "@/components/ui/button"; |
| 4 | import { Input } from "@/components/ui/input"; |
| 5 | import { Label } from "@/components/ui/label"; |
| 6 | import { ImageIcon, Trash2, Upload } from "lucide-react"; |
| 7 | import Image from "next/image"; |
| 8 | |
| 9 | interface LogoUploaderProps { |
| 10 | logoPreview: string | null; |
| 11 | onFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void; |
| 12 | onRemove: () => void; |
| 13 | } |
| 14 | |
| 15 | export function LogoUploader({ |
| 16 | logoPreview, |
| 17 | onFileChange, |
| 18 | onRemove, |
| 19 | }: LogoUploaderProps) { |
| 20 | return ( |
| 21 | <div className="space-y-4"> |
| 22 | <Label>Theme Logo</Label> |
| 23 | <div className="flex items-center gap-4"> |
| 24 | <div className="relative"> |
| 25 | <Input |
| 26 | type="file" |
| 27 | accept="image/*" |
| 28 | onChange={onFileChange} |
| 29 | className="hidden" |
| 30 | id="logo-upload" |
| 31 | /> |
| 32 | <Label |
| 33 | htmlFor="logo-upload" |
| 34 | className="flex cursor-pointer items-center gap-2 rounded-md border border-input bg-background px-4 py-2 hover:bg-accent" |
| 35 | > |
| 36 | <Upload className="h-4 w-4" /> |
| 37 | Upload Logo |
| 38 | </Label> |
| 39 | </div> |
| 40 | {logoPreview && ( |
| 41 | <Button |
| 42 | variant="destructive" |
| 43 | size="sm" |
| 44 | onClick={onRemove} |
| 45 | className="flex items-center gap-2" |
| 46 | > |
| 47 | <Trash2 className="h-4 w-4" /> |
| 48 | Remove |
| 49 | </Button> |
| 50 | )} |
| 51 | </div> |
| 52 | {logoPreview ? ( |
| 53 | <div className="relative h-32 w-full overflow-hidden rounded-md border"> |
| 54 | <Image |
| 55 | src={logoPreview} |
| 56 | alt="Logo Preview" |
| 57 | fill |
| 58 | className="object-contain" |
| 59 | /> |
| 60 | </div> |
| 61 | ) : ( |
| 62 | <div className="flex h-32 items-center justify-center rounded-md border border-dashed"> |
| 63 | <div className="flex flex-col items-center"> |
| 64 | <div className="mb-2 rounded-full bg-muted p-2"> |
| 65 | <ImageIcon className="h-4 w-4 text-muted-foreground" /> |
| 66 | </div> |
| 67 | <span className="text-sm text-muted-foreground">Upload Logo</span> |
| 68 | </div> |
| 69 | </div> |
| 70 | )} |
| 71 | </div> |
| 72 | ); |
| 73 | } |
| 74 |