"use client";
import React from "react";
import {
PhotoIcon,
VideoCameraIcon,
DocumentIcon,
TrashIcon,
EyeIcon,
ArrowDownTrayIcon,
} from "@heroicons/react/24/outline";
interface MediaFile {
id: string;
fileName: string;
originalName: string;
mimeType: string;
size: number;
url: string;
thumbnailUrl?: string;
createdAt: string;
downloadCount?: number;
viewCount?: number;
}
interface MediaGridProps {
files: MediaFile[];
onFileSelect?: (file: MediaFile) => void;
onFileDelete?: (fileId: string) => void;
onFileDownload?: (file: MediaFile) => void;
selectedFiles?: string[];
className?: string;
}
export function MediaGrid({
files,
onFileSelect,
onFileDelete,
onFileDownload,
selectedFiles = [],
className = "",
}: MediaGridProps) {
const getFileIcon = (mimeType: string) => {
if (mimeType.startsWith("image/")) {
return ;
}
if (mimeType.startsWith("video/")) {
return ;
}
return ;
};
const formatFileSize = (bytes: number): string => {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const sizes = ["Bytes", "KB", "MB", "GB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + " " + sizes[i];
};
const formatDate = (dateString: string): string => {
return new Date(dateString).toLocaleDateString("ko-KR", {
year: "numeric",
month: "short",
day: "numeric",
});
};
if (files.length === 0) {
return (
업로드된 파일이 없습니다
파일을 업로드하여 미디어 라이브러리를 시작하세요.
);
}
return (
{files.map((file) => {
const isSelected = selectedFiles.includes(file.id);
const isImage = file.mimeType.startsWith("image/");
return (
onFileSelect?.(file)}
>
{/* 파일 미리보기 */}
{isImage ? (

{
const target = e.target as HTMLImageElement;
target.style.display = "none";
target.nextElementSibling?.classList.remove("hidden");
}}
/>
) : null}
{getFileIcon(file.mimeType)}
{/* 파일 정보 */}
{file.originalName}
{formatFileSize(file.size)}
{formatDate(file.createdAt)}
{(file.downloadCount || file.viewCount) && (
{file.viewCount && (
{file.viewCount}
)}
{file.downloadCount && (
{file.downloadCount}
)}
)}
{/* 호버 오버레이 */}
{onFileDownload && (
)}
{onFileDelete && (
)}
{/* 선택 표시 */}
{isSelected && (
)}
);
})}
);
}