/** 상품 그리드·페이지네이션 렌더링 */ import { state } from './state.js'; import { ITEMS_PER_PAGE, STATUS_META } from './config.js'; export function renderProducts(page = 1) { const grid = document.getElementById('product-grid'); const paginationContainer = document.getElementById('pagination'); if (!grid) return; // 1. 결과가 0개인 경우 (안내 텍스트만 출력) if (state.visibleProducts.length === 0) { grid.classList.remove('grid'); // 중앙 정렬을 위해 그리드 해제 grid.innerHTML = `
search_off

검색 결과가 없습니다

입력하신 검색어나 선택한 필터를 확인해 주세요.

`; if (paginationContainer) paginationContainer.innerHTML = ''; return; } // 2. 결과가 있을 경우 (그리드 복구 및 초기화) grid.classList.add('grid'); grid.innerHTML = ''; const startIndex = (page - 1) * ITEMS_PER_PAGE; const pagedProducts = state.visibleProducts.slice(startIndex, startIndex + ITEMS_PER_PAGE); // 상품 카드 생성 로직 pagedProducts.forEach((product) => { const isSold = STATUS_META[product.status]?.soldOut === true; const cardHtml = `

${product.title}

${product.description}

`; grid.insertAdjacentHTML('beforeend', cardHtml); }); renderPagination(); } export function renderPagination() { const container = document.getElementById('pagination'); if (!container) return; const totalPages = Math.ceil(state.visibleProducts.length / ITEMS_PER_PAGE); const { currentPage } = state; let html = ``; for (let i = 1; i <= totalPages; i++) { html += ``; } html += ``; container.innerHTML = html; } export function changePage(page) { state.currentPage = page; renderProducts(page); window.scrollTo({ top: 0, behavior: 'smooth' }); } /** 모든 필터를 초기 상태로 되돌리는 함수 */ function resetAllFilters() { state.searchKeyword = ''; const searchInput = document.getElementById('search-input'); if (searchInput) searchInput.value = ''; state.activeCategories.clear(); state.activeCategories.add('All'); // 상태 필터 초기화 (config에서 defaultActive인 것만) import('./config.js').then(({ STATUS_FILTERS }) => { state.activeStatuses.clear(); STATUS_FILTERS.filter(f => f.defaultActive).forEach(f => state.activeStatuses.add(f.key)); // UI 전체 갱신 applyFilters(); renderStatusChips(); renderCategoryChips(productsData); }); }