// 库存管理页面的JavaScript功能
document.addEventListener('DOMContentLoaded', function() {
    // 库存显示颜色标记
    const stockElements = document.querySelectorAll('.book-stock');
    stockElements.forEach(element => {
        const stockValue = parseInt(element.textContent.trim());
        if (stockValue <= 0) {
            element.classList.add('book-stock-critical');
        } else if (stockValue <= 5) {
            element.classList.add('book-stock-warning');
        } else {
            element.classList.add('book-stock-normal');
        }
    });

    // 表格排序功能
    const tableHeaders = document.querySelectorAll('th[data-sort]');
    tableHeaders.forEach(header => {
        header.addEventListener('click', function() {
            const sort = this.dataset.sort;
            const currentOrder = new URLSearchParams(window.location.search).get('order') || 'asc';
            const newOrder = currentOrder === 'asc' ? 'desc' : 'asc';

            const url = new URL(window.location);
            url.searchParams.set('sort', sort);
            url.searchParams.set('order', newOrder);
            window.location.href = url.toString();
        });
    });
});
