import { state } from '../../core/state';
import { openPcModal } from '../../components/Modal/PCModal';
import { formatInline } from '../../core/utils';
import { createIcons, Paperclip, RefreshCcw } from 'lucide';
export function renderPcList(container: HTMLElement) {
const fullList = state.masterData.hw.filter(a => a.type === '개인PC');
const filterBar = document.createElement('div');
filterBar.className = 'search-bar';
const corps = Array.from(new Set(fullList.map(a => a.법인))).filter(Boolean).sort();
filterBar.innerHTML = `
`;
container.appendChild(filterBar);
const tableWrapper = document.createElement('div');
tableWrapper.className = 'table-container';
const table = document.createElement('table');
table.innerHTML = `| No | 법인 | 자산코드 | 사용자 | 위치 | CPU | RAM | Storage | 구매일 | 금액 | 품의서 | 관리 |
`;
tableWrapper.appendChild(table);
container.appendChild(tableWrapper);
const tbody = table.querySelector('tbody')!;
const updateTable = () => {
const keywordInput = document.getElementById('filter-keyword') as HTMLInputElement;
const corpSelect = document.getElementById('filter-corp') as HTMLSelectElement;
const keyword = keywordInput ? keywordInput.value.toLowerCase().trim() : '';
const corp = corpSelect ? corpSelect.value : '';
const filtered = fullList.filter(asset => {
const matchKeyword = !keyword || String(asset.자산코드||'').toLowerCase().includes(keyword) || String(asset.사용자||'').toLowerCase().includes(keyword);
const matchCorp = !corp || asset.법인 === corp;
return matchKeyword && matchCorp;
});
tbody.innerHTML = '';
if (filtered.length === 0) {
tbody.innerHTML = `| 검색 결과가 없습니다. |
`;
return;
}
filtered.forEach((asset, idx) => {
const tr = document.createElement('tr');
tr.style.cursor = 'pointer';
const storage = [asset.SSD1, asset.SSD2, asset.HDD1].filter(v => v).join(' / ');
tr.innerHTML = `
${idx+1} |
${asset.법인} |
${asset.자산코드} |
${asset.사용자||''} |
${asset.위치||''} |
${asset.CPU||''} |
${asset.RAM||''} |
${formatInline(storage)} |
${asset.구매일||''} |
${asset.금액||''} |
${asset.품의서명 ? '' : '-'} |
|
`;
tr.addEventListener('click', (e) => { if (!(e.target as HTMLElement).closest('button')) openPcModal(asset); });
tbody.appendChild(tr);
});
createIcons({ icons: { Paperclip } });
};
document.getElementById('filter-keyword')?.addEventListener('input', updateTable);
document.getElementById('filter-corp')?.addEventListener('change', updateTable);
document.getElementById('btn-reset-filters')?.addEventListener('click', () => {
(document.getElementById('filter-keyword') as HTMLInputElement).value = '';
(document.getElementById('filter-corp') as HTMLSelectElement).value = '';
updateTable();
});
updateTable();
}