<?php
// ========================================
// مدیریت محصولات
// پروژه فروشگاه کیف‌لند
// ========================================
require_once '../config/database.php';
require_once '../config/settings.php';
require_once '../includes/auth.php';
require_once '../includes/functions.php';

Auth::requireAdmin();
$db = Database::getInstance()->getConnection();
$pageTitle = 'مدیریت محصولات | کیف‌لند';

$success = '';
$error = '';

// ========================================
// پردازش درخواست‌های POST
// ========================================
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_POST['delete_id'])) {
        $id = (int)($_POST['delete_id'] ?? 0);
        try {
            $stmt = $db->prepare("SELECT image FROM products WHERE id = ?");
            $stmt->execute([$id]);
            $product = $stmt->fetch();
            if ($product && $product['image'] && file_exists('../uploads/products/' . $product['image'])) {
                unlink('../uploads/products/' . $product['image']);
            }
            $db->prepare("DELETE FROM products WHERE id = ?")->execute([$id]);
            Auth::logActivity('product_delete', "حذف محصول #$id");
            $success = 'محصول با موفقیت حذف شد.';
        } catch (Exception $e) {
            $error = 'خطا در حذف محصول: ' . $e->getMessage();
        }
    }
}

// ========================================
// فیلتر، جستجو و صفحه‌بندی
// ========================================
$search = trim($_GET['search'] ?? '');
$category_filter = (int)($_GET['category'] ?? 0);
$status_filter = $_GET['status'] ?? '';
$page = max(1, (int)($_GET['page'] ?? 1));
$per_page = 12;
$offset = ($page - 1) * $per_page;

$categories_stmt = $db->query("SELECT id, name FROM categories ORDER BY name ASC");
$categories = $categories_stmt->fetchAll();

$sql = "SELECT p.*, c.name as category_name FROM products p LEFT JOIN categories c ON p.category_id = c.id WHERE 1=1";
$params = [];

if ($search !== '') {
    $sql .= " AND (p.name LIKE ? OR p.sku LIKE ? OR p.description LIKE ?)";
    $p = "%$search%";
    array_push($params, $p, $p, $p);
}
if ($category_filter > 0) {
    $sql .= " AND p.category_id = ?";
    $params[] = $category_filter;
}
if ($status_filter === 'active') {
    $sql .= " AND p.is_active = 1";
} elseif ($status_filter === 'inactive') {
    $sql .= " AND p.is_active = 0";
} elseif ($status_filter === 'out_of_stock') {
    $sql .= " AND p.stock = 0";
}

$count_sql = preg_replace('/SELECT p\.\*, c\.name as category_name/', 'SELECT COUNT(*)', $sql);
$stmt_count = $db->prepare($count_sql);
$stmt_count->execute($params);
$total_products = $stmt_count->fetchColumn();
$total_pages = ceil($total_products / $per_page);

$sql .= " ORDER BY p.created_at DESC LIMIT ? OFFSET ?";
array_push($params, (int)$per_page, (int)$offset);

$stmt = $db->prepare($sql);
$stmt->execute($params);
$products = $stmt->fetchAll();

$stats_stmt = $db->query("SELECT 
    COUNT(*) as total,
    SUM(CASE WHEN is_active = 1 THEN 1 ELSE 0 END) as active,
    SUM(CASE WHEN is_active = 0 THEN 1 ELSE 0 END) as inactive,
    SUM(CASE WHEN stock = 0 THEN 1 ELSE 0 END) as out_of_stock
    FROM products");
$stats = $stats_stmt->fetch();

include 'includes/admin-header.php';
?>

<style>
/* ========================================
   Products Page - Complete CSS
   ======================================== */

/* Page Header */
.products-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 16px;
}

/* Filters Bar */
.filters-bar {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    padding: 16px;
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    margin-bottom: 24px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
    flex: 1;
}

.filter-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-group label i {
    opacity: 0.7;
}

.filter-group select,
.filter-group input {
    padding: 10px 14px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    background: var(--glass-bg-light);
    font-family: 'Vazirmatn', sans-serif;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-height: 44px;
}

.filter-group select:hover,
.filter-group input:hover {
    background: var(--glass-hover);
    border-color: var(--primary);
}

.filter-group select:focus,
.filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
    background: #fff;
}

.filter-group select option {
    background: #fff;
    color: var(--text-primary);
    padding: 8px;
}

/* Stats Row */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-box {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: center;
    transition: all var(--transition-fast);
}

.stat-box:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-soft);
    background: var(--glass-bg-light);
}

.stat-box h4 {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 4px;
    line-height: 1;
}

.stat-box p {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 0;
}

/* Products Grid */
.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* Product Card */
.product-card {
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: all var(--transition-fast);
    position: relative;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-soft);
    background: var(--glass-bg-light);
    border-color: rgba(0, 122, 255, 0.3);
}

/* Product Image */
.product-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    transition: transform var(--transition-fast);
}

.product-card:hover .product-image {
    transform: scale(1.02);
}

.product-image-placeholder {
    width: 100%;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: var(--text-secondary);
    font-size: 48px;
    opacity: 0.5;
}

/* Badge Status */
.badge-status {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 10px;
    font-weight: 700;
    backdrop-filter: blur(10px);
    z-index: 1;
    transition: all var(--transition-fast);
}

.badge-status.active {
    background: rgba(52, 199, 89, 0.95);
    color: white;
}

.badge-status.inactive {
    background: rgba(108, 117, 125, 0.95);
    color: white;
}

/* Product Info */
.product-info {
    padding: 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.product-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}

.product-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
    font-size: 12px;
}

.product-meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.product-meta-item i {
    width: 16px;
    text-align: center;
    opacity: 0.7;
    font-size: 11px;
}

.product-price {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 12px;
    line-height: 1;
}

/* Stock Badge */
.product-stock {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    margin-bottom: 12px;
    width: fit-content;
    transition: all var(--transition-fast);
}

.product-stock.in-stock {
    background: rgba(52, 199, 89, 0.15);
    color: var(--success);
    border: 0.5px solid rgba(52, 199, 89, 0.3);
}

.product-stock.low-stock {
    background: rgba(255, 149, 0, 0.15);
    color: var(--warning);
    border: 0.5px solid rgba(255, 149, 0, 0.3);
}

.product-stock.out-of-stock {
    background: rgba(255, 59, 48, 0.15);
    color: var(--danger);
    border: 0.5px solid rgba(255, 59, 48, 0.3);
}

/* Product Actions - BUTTONS WITH HOVER */
.product-actions {
    display: flex;
    gap: 8px;
    padding-top: 12px;
    margin-top: auto;
    border-top: 1px solid var(--glass-border);
}

/* Base Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
    border: 1px solid transparent;
    text-decoration: none;
    min-height: 36px;
    font-family: 'Vazirmatn', sans-serif;
    flex: 1;
}

.btn i {
    font-size: 11px;
    opacity: 0.9;
}

/* Primary Button */
.btn-primary {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 122, 255, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-primary:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.3);
}

/* Danger Button */
.btn-danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-hover);
    border-color: var(--danger-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(255, 59, 48, 0.3);
}

.btn-danger:active {
    transform: translateY(0);
    box-shadow: none;
}

.btn-danger:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(255, 59, 48, 0.3);
}

/* Ghost Button */
.btn-ghost {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-ghost:hover {
    background: var(--glass-hover);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.btn-ghost:active {
    transform: translateY(0);
}

/* Secondary Button (for filters) */
.btn-secondary {
    background: rgba(0, 122, 255, 0.12);
    color: var(--primary);
    border: 1px solid rgba(0, 122, 255, 0.2);
}

.btn-secondary:hover {
    background: rgba(0, 122, 255, 0.2);
    border-color: var(--primary);
    transform: translateY(-1px);
}

.btn-secondary:active {
    transform: translateY(0);
}

/* Button Sizes */
.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
    min-height: 32px;
}

.btn-lg {
    padding: 12px 24px;
    font-size: 14px;
    min-height: 44px;
}

/* Button Block */
.btn-block {
    width: 100%;
}

/* Button Disabled */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
}

.empty-state i {
    font-size: 64px;
    color: var(--text-secondary);
    opacity: 0.3;
    margin-bottom: 16px;
}

.empty-state h3 {
    font-size: 18px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 20px;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 24px;
    flex-wrap: wrap;
}

.page-link {
    min-width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text-primary);
    transition: all var(--transition-fast);
    text-decoration: none;
}

.page-link:hover {
    background: var(--glass-hover);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

.page-link.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    font-weight: 600;
}

.page-link:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Alerts */
.alert {
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    border: 1px solid transparent;
}

.alert-success {
    background: rgba(52, 199, 89, 0.15);
    color: #0B5D0A;
    border-color: rgba(52, 199, 89, 0.3);
}

.alert-danger {
    background: rgba(255, 59, 48, 0.15);
    color: #7A1815;
    border-color: rgba(255, 59, 48, 0.3);
}

/* Responsive */
@media (max-width: 992px) {
    .products-grid {
        grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    }
}

@media (max-width: 768px) {
    .products-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filters-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        width: 100%;
        min-width: 100%;
    }
    
    .filter-group:last-child {
        flex-direction: row;
        gap: 8px;
    }
    
    .filter-group:last-child .btn {
        flex: 1;
    }
    
    .products-grid {
        grid-template-columns: 1fr;
    }
    
    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .product-actions {
        flex-direction: row;
    }
}

@media (max-width: 480px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
    
    .product-actions {
        flex-direction: column;
    }
    
    .product-actions .btn {
        width: 100%;
    }
    
    .filter-group:last-child {
        flex-direction: column;
    }
    
    .page-link {
        min-width: 36px;
        height: 36px;
        font-size: 12px;
    }
}

/* Animation for new items */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.product-card {
    animation: fadeInUp 0.3s ease forwards;
}

.product-card:nth-child(1) { animation-delay: 0.05s; }
.product-card:nth-child(2) { animation-delay: 0.1s; }
.product-card:nth-child(3) { animation-delay: 0.15s; }
.product-card:nth-child(4) { animation-delay: 0.2s; }
.product-card:nth-child(5) { animation-delay: 0.25s; }
.product-card:nth-child(6) { animation-delay: 0.3s; }
</style>

<main class="main-content">
    <header class="top-header">
        <button class="menu-toggle" id="menuToggle"><i class="fas fa-bars"></i></button>
        <div class="search-box">
            <i class="fas fa-search"></i>
            <input type="text" id="globalSearch" value="<?= htmlspecialchars($search) ?>" placeholder="جستجو در محصولات...">
        </div>
        <div class="header-actions">
            <a href="product-add.php" class="btn btn-primary btn-sm">
                <i class="fas fa-plus"></i>
                <span>محصول جدید</span>
            </a>
        </div>
    </header>

    <div class="dashboard-content">
        <div class="page-title">
            <h1>مدیریت محصولات</h1>
            <p>مشاهده، ویرایش و مدیریت محصولات فروشگاه</p>
        </div>

        <?php if ($error): ?>
        <div class="alert alert-danger">
            <i class="fas fa-exclamation-circle"></i>
            <?= htmlspecialchars($error) ?>
        </div>
        <?php endif; ?>
        
        <?php if ($success): ?>
        <div class="alert alert-success">
            <i class="fas fa-check-circle"></i>
            <?= htmlspecialchars($success) ?>
        </div>
        <?php endif; ?>

        <!-- آمار سریع -->
        <div class="stats-row">
            <div class="stat-box">
                <h4><?= number_format($stats['total']) ?></h4>
                <p>کل محصولات</p>
            </div>
            <div class="stat-box">
                <h4><?= number_format($stats['active']) ?></h4>
                <p>فعال</p>
            </div>
            <div class="stat-box">
                <h4><?= number_format($stats['inactive']) ?></h4>
                <p>غیرفعال</p>
            </div>
            <div class="stat-box">
                <h4><?= number_format($stats['out_of_stock']) ?></h4>
                <p>ناموجود</p>
            </div>
        </div>

        <!-- فیلترها -->
        <form method="GET" class="filters-bar">
            <div class="filter-group">
                <label><i class="fas fa-search"></i> جستجو</label>
                <input type="text" name="search" value="<?= htmlspecialchars($search) ?>" placeholder="نام، کد یا توضیحات...">
            </div>
            
            <div class="filter-group">
                <label><i class="fas fa-folder"></i> دسته‌بندی</label>
                <select name="category">
                    <option value="0">همه دسته‌ها</option>
                    <?php foreach ($categories as $cat): ?>
                    <option value="<?= $cat['id'] ?>" <?= $category_filter == $cat['id'] ? 'selected' : '' ?>>
                        <?= htmlspecialchars($cat['name']) ?>
                    </option>
                    <?php endforeach; ?>
                </select>
            </div>
            
            <div class="filter-group">
                <label><i class="fas fa-toggle-on"></i> وضعیت</label>
                <select name="status">
                    <option value="">همه وضعیت‌ها</option>
                    <option value="active" <?= $status_filter == 'active' ? 'selected' : '' ?>>فعال</option>
                    <option value="inactive" <?= $status_filter == 'inactive' ? 'selected' : '' ?>>غیرفعال</option>
                    <option value="out_of_stock" <?= $status_filter == 'out_of_stock' ? 'selected' : '' ?>>ناموجود</option>
                </select>
            </div>
            
            <div class="filter-group" style="flex: none; display: flex; gap: 8px;">
                <button type="submit" class="btn btn-primary">
                    <i class="fas fa-filter"></i>
                    اعمال
                </button>
                <a href="products.php" class="btn btn-ghost">
                    <i class="fas fa-undo"></i>
                    ریست
                </a>
            </div>
        </form>

        <!-- گرید محصولات -->
        <?php if (!empty($products)): ?>
        <div class="products-grid">
            <?php foreach ($products as $product): ?>
            <div class="product-card">
                <!-- نشانگر وضعیت -->
                <span class="badge-status <?= $product['is_active'] ? 'active' : 'inactive' ?>">
                    <?= $product['is_active'] ? 'فعال' : 'غیرفعال' ?>
                </span>
                
                <!-- تصویر محصول -->
                <?php if ($product['image'] && file_exists('../uploads/products/' . $product['image'])): ?>
                    <img src="../uploads/products/<?= htmlspecialchars($product['image']) ?>" 
                         alt="<?= htmlspecialchars($product['name']) ?>" 
                         class="product-image">
                <?php else: ?>
                    <div class="product-image-placeholder">
                        <i class="fas fa-image"></i>
                    </div>
                <?php endif; ?>
                
                <!-- اطلاعات محصول -->
                <div class="product-info">
                    <h3 class="product-title"><?= htmlspecialchars($product['name']) ?></h3>
                    
                    <div class="product-meta">
                        <div class="product-meta-item">
                            <i class="fas fa-barcode"></i>
                            <span><?= htmlspecialchars($product['sku'] ?: 'بدون کد') ?></span>
                        </div>
                        <div class="product-meta-item">
                            <i class="fas fa-folder"></i>
                            <span><?= htmlspecialchars($product['category_name'] ?: 'بدون دسته') ?></span>
                        </div>
                    </div>
                    
                    <div class="product-price">
                        <?= number_format($product['price']) ?> تومان
                    </div>
                    
                    <!-- وضعیت موجودی -->
                    <?php
                    $stock_class = 'out-of-stock';
                    $stock_text = 'ناموجود';
                    if ($product['stock'] > 10) {
                        $stock_class = 'in-stock';
                        $stock_text = 'موجود: ' . number_format($product['stock']);
                    } elseif ($product['stock'] > 0) {
                        $stock_class = 'low-stock';
                        $stock_text = 'موجودی کم: ' . number_format($product['stock']);
                    }
                    ?>
                    <div class="product-stock <?= $stock_class ?>">
                        <i class="fas fa-box"></i>
                        <?= $stock_text ?>
                    </div>
                    
                    <!-- دکمه‌های عملیات -->
                    <div class="product-actions">
                        <a href="product-edit.php?id=<?= $product['id'] ?>" class="btn btn-primary">
                            <i class="fas fa-edit"></i>
                            ویرایش
                        </a>
                        <form method="POST" style="flex: 1;" onsubmit="return confirm('آیا از حذف این محصول مطمئن هستید؟');">
                            <input type="hidden" name="delete_id" value="<?= $product['id'] ?>">
                            <button type="submit" class="btn btn-danger">
                                <i class="fas fa-trash"></i>
                                حذف
                            </button>
                        </form>
                    </div>
                </div>
            </div>
            <?php endforeach; ?>
        </div>

        <!-- صفحه‌بندی -->
        <?php if ($total_pages > 1): ?>
        <div class="pagination">
            <?php if ($page > 1): ?>
            <a href="?<?= http_build_query(array_merge($_GET, ['page' => $page - 1])) ?>" class="page-link">
                <i class="fas fa-chevron-right"></i>
            </a>
            <?php endif; ?>
            
            <?php for ($i = 1; $i <= $total_pages; $i++): ?>
                <?php if ($i == 1 || $i == $total_pages || abs($page - $i) <= 2): ?>
                <a href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>" 
                   class="page-link <?= $i == $page ? 'active' : '' ?>">
                    <?= $i ?>
                </a>
                <?php elseif (abs($page - $i) == 3): ?>
                <span class="text-muted px-2">...</span>
                <?php endif; ?>
            <?php endfor; ?>
            
            <?php if ($page < $total_pages): ?>
            <a href="?<?= http_build_query(array_merge($_GET, ['page' => $page + 1])) ?>" class="page-link">
                <i class="fas fa-chevron-left"></i>
            </a>
            <?php endif; ?>
        </div>
        <?php endif; ?>

        <?php else: ?>
        <!-- حالت خالی -->
        <div class="empty-state">
            <i class="fas fa-box-open"></i>
            <h3>محصولی یافت نشد</h3>
            <p>هنوز محصولی اضافه نکرده‌اید یا با فیلترهای فعلی محصولی وجود ندارد.</p>
            <a href="product-add.php" class="btn btn-primary">
                <i class="fas fa-plus"></i>
                افزودن اولین محصول
            </a>
        </div>
        <?php endif; ?>
    </div>
</main>

<script src="assets/js/script.js"></script>
<script>
// جستجوی زنده
document.getElementById('globalSearch')?.addEventListener('input', debounce(function(e) {
    const term = e.target.value.toLowerCase();
    const cards = document.querySelectorAll('.product-card');
    cards.forEach(card => {
        const text = card.textContent.toLowerCase();
        card.style.display = text.includes(term) ? '' : 'none';
    });
}, 300));
</script>

<?php include 'includes/admin-footer.php'; ?>