"use client"; import React, { useState } from "react"; import { FunnelIcon, XMarkIcon, CalendarIcon, TagIcon, DocumentIcon, PhotoIcon, VideoCameraIcon, MusicalNoteIcon, } from "@heroicons/react/24/outline"; export interface MediaFilterOptions { fileTypes: string[]; dateRange: { start?: string; end?: string; }; sizeRange: { min?: number; max?: number; }; tags: string[]; searchTerm: string; } export interface MediaFilterProps { filters: MediaFilterOptions; onFilterChange: (filters: MediaFilterOptions) => void; availableTags: string[]; className?: string; } const FILE_TYPE_OPTIONS = [ { value: "image", label: "이미지", icon: PhotoIcon, types: ["image/jpeg", "image/png", "image/gif", "image/webp"], }, { value: "video", label: "동영상", icon: VideoCameraIcon, types: ["video/mp4", "video/webm", "video/avi"], }, { value: "audio", label: "오디오", icon: MusicalNoteIcon, types: ["audio/mp3", "audio/wav", "audio/ogg"], }, { value: "document", label: "문서", icon: DocumentIcon, types: ["application/pdf", "application/msword", "text/plain"], }, ]; const SIZE_OPTIONS = [ { label: "모든 크기", min: 0, max: Infinity }, { label: "1MB 미만", min: 0, max: 1024 * 1024 }, { label: "1MB - 10MB", min: 1024 * 1024, max: 10 * 1024 * 1024 }, { label: "10MB - 100MB", min: 10 * 1024 * 1024, max: 100 * 1024 * 1024 }, { label: "100MB 이상", min: 100 * 1024 * 1024, max: Infinity }, ]; export function MediaFilter({ filters, onFilterChange, availableTags, className = "", }: MediaFilterProps) { const [isOpen, setIsOpen] = useState(false); const updateFilter = ( key: K, value: MediaFilterOptions[K] ) => { onFilterChange({ ...filters, [key]: value, }); }; const toggleFileType = (typeOption: (typeof FILE_TYPE_OPTIONS)[0]) => { const newTypes = filters.fileTypes.includes(typeOption.value) ? filters.fileTypes.filter((t) => t !== typeOption.value) : [...filters.fileTypes, typeOption.value]; updateFilter("fileTypes", newTypes); }; const toggleTag = (tag: string) => { const newTags = filters.tags.includes(tag) ? filters.tags.filter((t) => t !== tag) : [...filters.tags, tag]; updateFilter("tags", newTags); }; const clearFilters = () => { onFilterChange({ fileTypes: [], dateRange: {}, sizeRange: {}, tags: [], searchTerm: "", }); }; const activeFiltersCount = filters.fileTypes.length + filters.tags.length + (filters.dateRange.start || filters.dateRange.end ? 1 : 0) + (filters.sizeRange.min !== undefined || filters.sizeRange.max !== undefined ? 1 : 0); return (
{/* 필터 버튼 */} {/* 필터 패널 */} {isOpen && (

필터

{/* 파일 형식 필터 */}
{FILE_TYPE_OPTIONS.map((option) => { const IconComponent = option.icon; return ( ); })}
{/* 날짜 범위 필터 */}
updateFilter("dateRange", { ...filters.dateRange, start: e.target.value, }) } className="text-sm border border-gray-300 rounded px-2 py-1 focus:ring-2 focus:ring-blue-500" placeholder="시작일" /> updateFilter("dateRange", { ...filters.dateRange, end: e.target.value, }) } className="text-sm border border-gray-300 rounded px-2 py-1 focus:ring-2 focus:ring-blue-500" placeholder="종료일" />
{/* 파일 크기 필터 */}
{SIZE_OPTIONS.map((option, index) => ( ))}
{/* 태그 필터 */} {availableTags.length > 0 && (
{availableTags.map((tag) => ( ))}
)}
)}
); }