import { state } from '../../core/state'; import { openSwModal } from '../../components/Modal/SWModal'; import { formatPrice } from '../../core/utils'; import { createIcons, Cloud, CreditCard, DollarSign } from 'lucide'; export function renderCloudList(container: HTMLElement) { // DB에서 직접 로드된 전용 배열을 사용하여 데이터 소스를 일원화함 const getFullList = () => state.masterData.cloud || []; const filterBar = document.createElement('div'); filterBar.className = 'search-bar'; filterBar.innerHTML = `
`; container.appendChild(filterBar); const tableWrapper = document.createElement('div'); tableWrapper.className = 'table-container'; const table = document.createElement('table'); table.innerHTML = ` No. 플랫폼명 법인 담당부서 진행 프로젝트(사용용도) 계정명(관리자) 결제수단 결제일 당월 청구액 비고 `; tableWrapper.appendChild(table); container.appendChild(tableWrapper); const tbody = table.querySelector('tbody')!; const updateTable = () => { const keywordInput = document.getElementById('filter-keyword') as HTMLInputElement; const paymentSelect = document.getElementById('filter-payment') as HTMLSelectElement; const keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : ''; const payment = paymentSelect ? paymentSelect.value : ''; const filtered = getFullList().filter(asset => { const kwMatch = !keyword || (asset.제품명 || '').toLowerCase().includes(keyword) || (asset.부서 || '').toLowerCase().includes(keyword) || (asset.계정명 || '').toLowerCase().includes(keyword); const payMatch = !payment || asset.결제수단 === payment; return kwMatch && payMatch; }); tbody.innerHTML = ''; if (filtered.length === 0) { tbody.innerHTML = '등록된 클라우드 서비스가 없습니다.'; return; } filtered.forEach((asset, idx) => { const tr = document.createElement('tr'); tr.style.cursor = 'pointer'; const paymentBadge = asset.결제수단 === '법인카드' ? '법인카드 (' + (asset.연결카드번호||'미상') + ')' : (asset.결제수단 === '인보이스' ? '인보이스' : '미설정'); tr.innerHTML = ` ${idx+1} ${asset.플랫폼명||'미지정'} ${asset.법인||''} ${asset.부서||''} ${asset.제품명||''} ${asset.계정명||''} ${paymentBadge} ${asset.결제일 ? asset.결제일 + '일' : ''} ${asset.당월청구액 ? '₩ ' + formatPrice(asset.당월청구액) : '₩ 0'} ${asset.비고||''} `; tr.addEventListener('click', () => openSwModal(asset, 'view')); tbody.appendChild(tr); }); createIcons({ icons: { Cloud, CreditCard, DollarSign } }); }; document.getElementById('filter-keyword')?.addEventListener('input', updateTable); document.getElementById('filter-payment')?.addEventListener('change', updateTable); document.getElementById('btn-reset-filters')?.addEventListener('click', () => { if (document.getElementById('filter-keyword')) (document.getElementById('filter-keyword') as HTMLInputElement).value = ''; if (document.getElementById('filter-payment')) (document.getElementById('filter-payment') as HTMLSelectElement).value = ''; updateTable(); }); updateTable(); }