<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard & Laporan Penjualan</title>
    <!-- Google Fonts & Icons -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
    
    <!-- Library CSS -->
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/pivottable@2.23.0/dist/pivot.min.css">
    
    <!-- Custom CSS -->
    <link rel="stylesheet" href="dashboard.css">
</head>
<body>
    <div id="dashboardApp">
        <header class="app-header">
            <h1><span class="material-icons-outlined">dashboard</span> Dashboard Penjualan</h1>
        </header>

        <main class="container">
            <!-- Loading Indicator -->
            <div v-if="isLoading" class="loading-overlay">
                <div class="spinner"></div>
                <p>Memuat data laporan...</p>
            </div>

            <!-- Ringkasan Utama -->
            <section class="summary-cards">
                <div class="card">
                    <h4>Total Pendapatan</h4>
                    <p class="big-number">{{ formatCurrency(summary.totalRevenue) }}</p>
                </div>
                <div class="card">
                    <h4>Jumlah Transaksi</h4>
                    <p class="big-number">{{ summary.totalTransactions }}</p>
                </div>
                <div class="card">
                    <h4>Produk Terjual</h4>
                    <p class="big-number">{{ summary.totalItemsSold }}</p>
                </div>
            </section>

            <!-- Grafik Penjualan -->
            <section class="chart-container">
                <h3>Grafik Pendapatan Harian (7 Hari Terakhir)</h3>
                <canvas id="dailyRevenueChart"></canvas>
            </section>

             <!-- Laporan Pivot -->
            <section class="pivot-container">
                <h3>Laporan Penjualan Interaktif</h3>
                <p>Drag & drop atribut untuk membuat laporan. Contoh: Tarik 'product_name' ke baris, 'quantity' ke nilai.</p>
                <div id="pivotOutput"></div>
            </section>
        </main>
    </div>

    <!-- Libraries -->
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@3.2.47/dist/vue.global.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/pivottable@2.23.0/dist/pivot.min.js"></script>
    
    <!-- Global Variables & Custom Scripts -->
    <script>
        window.xcab = '002';
        window.xbrand = '001';
    </script>
    <script src="crud.js"></script>
    <script src="dashboard.js"></script>
</body>
</html>
