"use client"; import React, { useState } from 'react'; import { Mail, Edit2, Trash2, Power, PowerOff, Search, Calendar, Zap, CheckCircle, XCircle, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { MailAccount } from '@/lib/api/mail'; interface MailAccountTableProps { accounts: MailAccount[]; onEdit: (account: MailAccount) => void; onDelete: (account: MailAccount) => void; onToggleStatus: (account: MailAccount) => void; } export default function MailAccountTable({ accounts, onEdit, onDelete, onToggleStatus, }: MailAccountTableProps) { const [searchTerm, setSearchTerm] = useState(''); const [sortField, setSortField] = useState('createdAt'); const [sortOrder, setSortOrder] = useState<'asc' | 'desc'>('desc'); // 검색 필터링 const filteredAccounts = accounts.filter( (account) => account.name.toLowerCase().includes(searchTerm.toLowerCase()) || account.email.toLowerCase().includes(searchTerm.toLowerCase()) || account.smtpHost.toLowerCase().includes(searchTerm.toLowerCase()) ); // 정렬 const sortedAccounts = [...filteredAccounts].sort((a, b) => { const aValue = a[sortField]; const bValue = b[sortField]; if (typeof aValue === 'string' && typeof bValue === 'string') { return sortOrder === 'asc' ? aValue.localeCompare(bValue) : bValue.localeCompare(aValue); } if (typeof aValue === 'number' && typeof bValue === 'number') { return sortOrder === 'asc' ? aValue - bValue : bValue - aValue; } return 0; }); const handleSort = (field: keyof MailAccount) => { if (sortField === field) { setSortOrder(sortOrder === 'asc' ? 'desc' : 'asc'); } else { setSortField(field); setSortOrder('asc'); } }; const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString('ko-KR', { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', }); }; if (accounts.length === 0) { return (

등록된 메일 계정이 없습니다

"새 계정 추가" 버튼을 클릭하여 첫 번째 메일 계정을 등록하세요.

); } return (
{/* 검색 */}
setSearchTerm(e.target.value)} placeholder="계정명, 이메일, 서버로 검색..." className="w-full pl-10 pr-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-orange-500 focus:border-orange-500 transition-all" />
{/* 테이블 */}
{sortedAccounts.map((account) => ( ))}
handleSort('name')} >
계정명 {sortField === 'name' && ( {sortOrder === 'asc' ? '↑' : '↓'} )}
handleSort('email')} > 이메일 주소 SMTP 서버 handleSort('status')} > 상태 handleSort('dailyLimit')} >
일일 제한
handleSort('createdAt')} >
생성일
액션
{account.name}
{account.email}
{account.smtpHost}:{account.smtpPort}
{account.smtpSecure ? 'SSL' : 'TLS'}
{account.dailyLimit > 0 ? account.dailyLimit.toLocaleString() : '무제한'}
{formatDate(account.createdAt)}
{/* 결과 요약 */}
전체 {accounts.length}개 중 {sortedAccounts.length}개 표시 {searchTerm && ` (검색: "${searchTerm}")`}
); }