<?php
$page_title = 'Dashboard';
require_once 'includes/header.php';

// Get stats for current shop
$shop_id = $_SESSION['shop_id'];

// Total products
$stmt = $pdo->prepare("SELECT COUNT(*) FROM products WHERE shop_id = ? AND deleted_at IS NULL");
$stmt->execute([$shop_id]);
$totalProducts = $stmt->fetchColumn();

// Total brands
$stmt = $pdo->prepare("SELECT COUNT(*) FROM brand WHERE shop_id = ?");
$stmt->execute([$shop_id]);
$totalBrands = $stmt->fetchColumn();

// Total product groups
$stmt = $pdo->prepare("SELECT COUNT(*) FROM product_group WHERE shop_id = ?");
$stmt->execute([$shop_id]);
$totalGroups = $stmt->fetchColumn();

// Total suppliers
$stmt = $pdo->prepare("SELECT COUNT(*) FROM supplier WHERE shop_id = ?");
$stmt->execute([$shop_id]);
$totalSuppliers = $stmt->fetchColumn();
?>

<!-- Welcome Section -->
<div class="welcome-section">
    <h2>ຍິນດີຕ້ອນຮັບ,
        <?= htmlspecialchars($_SESSION['username'] ?? 'Manager') ?>!
    </h2>
    <p>ລະບົບຈັດການສະແກນເຂົ້າ-ອອກ MUANJAI — <?= htmlspecialchars($current_shop_name) ?></p>
</div>

<!-- Stats Grid -->
<div class="stats-grid">
    <div class="stat-card">
        <div class="stat-icon gold">
            <i class="fas fa-box"></i>
        </div>
        <div class="stat-info">
            <h3><?= number_format($totalProducts) ?></h3>
            <p>ສິນຄ້າທັງໝົດ</p>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon green">
            <i class="fas fa-certificate"></i>
        </div>
        <div class="stat-info">
            <h3><?= number_format($totalBrands) ?></h3>
            <p>Brand ທັງໝົດ</p>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon orange">
            <i class="fas fa-layer-group"></i>
        </div>
        <div class="stat-info">
            <h3><?= number_format($totalGroups) ?></h3>
            <p>ກຸ່ມສິນຄ້າ</p>
        </div>
    </div>

    <div class="stat-card">
        <div class="stat-icon purple">
            <i class="fas fa-truck"></i>
        </div>
        <div class="stat-info">
            <h3><?= number_format($totalSuppliers) ?></h3>
            <p>ຜູ້ສະໜອງ</p>
        </div>
    </div>
</div>

<!-- Recent Activity Card -->
<div class="card">
    <div class="card-header">
        <h3 class="card-title">
            <i class="fas fa-clock"></i> ກິດຈະກຳລ່າສຸດ
        </h3>
    </div>
    <div class="card-body">
        <p style="color: var(--text-secondary); text-align: center; padding: 30px 0;">
            <i class="fas fa-inbox" style="font-size: 40px; display: block; margin-bottom: 15px; opacity: 0.5;"></i>
            ຍັງບໍ່ມີກິດຈະກຳ
        </p>
    </div>
</div>

<?php require_once 'includes/footer.php'; ?>