<?php include 'header.php'; ?>

<div class="p-6 bg-slate-100 min-h-screen">

    <!-- Header -->
    <div class="flex justify-between items-center mb-6">
        <div>
            <h1 class="text-4xl font-bold text-slate-800">Dashboard</h1>
            <p class="text-slate-500">Welcome back, Admin! Here's what's happening today.</p>
        </div>
    </div>

    <!-- Top Cards -->
    <div class="grid grid-cols-1 md:grid-cols-2 xl:grid-cols-4 gap-6 mb-6">

        <div class="bg-white rounded-3xl p-6 shadow-sm">
            <div class="flex justify-between items-center">
                <div>
                    <p class="text-gray-500">Total Clients</p>
                    <h2 class="text-4xl font-bold mt-2">125</h2>
                </div>
                <div
                    class="h-16 w-16 rounded-full bg-blue-100 flex items-center justify-center">
                    <i class="ri-user-3-line text-3xl text-blue-600"></i>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-3xl p-6 shadow-sm">
            <div class="flex justify-between items-center">
                <div>
                    <p class="text-gray-500">Sales Invoice</p>
                    <h2 class="text-4xl font-bold mt-2">450</h2>
                </div>
                <div
                    class="h-16 w-16 rounded-full bg-green-100 flex items-center justify-center">
                    <i class="ri-file-list-3-line text-3xl text-green-600"></i>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-3xl p-6 shadow-sm">
            <div class="flex justify-between items-center">
                <div>
                    <p class="text-gray-500">Receivable</p>
                    <h2 class="text-4xl font-bold mt-2">₹1,25,000</h2>
                </div>
                <div
                    class="h-16 w-16 rounded-full bg-orange-100 flex items-center justify-center">
                    <i class="ri-money-rupee-circle-line text-3xl text-orange-600"></i>
                </div>
            </div>
        </div>

        <div class="bg-white rounded-3xl p-6 shadow-sm">
            <div class="flex justify-between items-center">
                <div>
                    <p class="text-gray-500">Payable</p>
                    <h2 class="text-4xl font-bold mt-2">₹75,000</h2>
                </div>
                <div
                    class="h-16 w-16 rounded-full bg-red-100 flex items-center justify-center">
                    <i class="ri-bank-card-line text-3xl text-red-600"></i>
                </div>
            </div>
        </div>

    </div>

    <!-- Middle Section -->
    <div class="grid grid-cols-1 xl:grid-cols-3 gap-6 mb-6">

        <!-- Business Overview -->
        <div class="xl:col-span-2 bg-white rounded-3xl p-6 shadow-sm">

            <div class="flex justify-between mb-6">
                <h3 class="font-bold text-xl">Business Overview</h3>

               <select id="periodFilter" onchange="changePeriod(this.value)" class="border border-gray-200 rounded-xl px-3 py-2">
                    <option value="month">This Month</option>
                    <option value="year">This Year</option>
                </select>
            </div>

<div class="grid grid-cols-3 gap-4 mb-5">
    
    <button onclick="changeChart('sales')"
        class="tab-btn bg-blue-50 text-blue-600 py-2 rounded-xl font-medium">
        Sales
    </button>

    <button onclick="changeChart('receipts')"
        class="tab-btn bg-gray-100 py-2 rounded-xl">
        Receipts
    </button>

    <button onclick="changeChart('expenses')"
        class="tab-btn bg-gray-100 py-2 rounded-xl">
        Expenses
    </button>

</div>

<div class="grid grid-cols-12 gap-6">

    <div class="col-span-12 lg:col-span-3">
        <p class="text-gray-500 text-sm" id="chartTitle">Total Sales</p>

        <h2 class="text-4xl font-bold mt-3" id="chartAmount">
            ₹5,25,000
        </h2>
    </div>

    <div class="col-span-12 lg:col-span-9">
        <canvas id="salesChart"></canvas>
    </div>

</div>


        </div>

<!-- Receivable + Payable -->
<div class="flex flex-col gap-6 h-full">

    <div class="bg-white rounded-3xl p-6 shadow-sm flex-1">
        <h3 class="font-bold text-xl mb-4">Top 5 Receivables</h3>

        <div class="space-y-3">
            <div class="flex justify-between">
                <span>ABC Corporation</span>
                <span class="text-red-500">₹35,000</span>
            </div>

            <div class="flex justify-between">
                <span>XYZ Traders</span>
                <span class="text-red-500">₹28,500</span>
            </div>

            <div class="flex justify-between">
                <span>PQR Solutions</span>
                <span class="text-red-500">₹19,500</span>
            </div>
            <div class="flex justify-between">
                <span>DEF Solutions</span>
                <span class="text-red-500">₹10,500</span>
            </div>
        </div>
    </div>

    <div class="bg-white rounded-3xl p-6 shadow-sm flex-1">
        <h3 class="font-bold text-xl mb-4">Top 5 Payables</h3>

        <div class="space-y-3">
            <div class="flex justify-between">
                <span>Shree Suppliers</span>
                <span class="text-red-500">₹25,000</span>
            </div>

            <div class="flex justify-between">
                <span>Kamal Traders</span>
                <span class="text-red-500">₹18,000</span>
            </div>

            <div class="flex justify-between">
                <span>Om Impex</span>
                <span class="text-red-500">₹15,000</span>
            </div>
            
            <div class="flex justify-between">
                <span>SS Traders</span>
                <span class="text-red-500">₹10,000</span>
            </div>
        </div>
    </div>

</div>

    </div>
<div class="bg-white rounded-3xl p-6 shadow-sm">

    <div class="flex items-center justify-between mb-5">
        <h3 class="font-bold text-xl">Quick Actions</h3>
    </div>

    <div class="grid grid-cols-5 gap-3">

        <a href="uturn_sales_invoice.php" class="flex flex-col items-center justify-center p-4 rounded-2xl bg-green-100 hover:bg-green-200 transition">
            <div class="w-12 h-12 bg-green-500 rounded-xl flex items-center justify-center">
                <i class="ri-file-list-3-line text-white text-xl"></i>
            </div>
            <span class="mt-3 text-sm font-medium">Sales Invoice</span>
        </a>

        <a href="uturn_purchase_bill.php" class="flex flex-col items-center justify-center p-4 rounded-2xl bg-orange-100 hover:bg-orange-200 transition">
            <div class="w-12 h-12 bg-orange-500 rounded-xl flex items-center justify-center">
                <i class="ri-wallet-3-line text-white text-xl"></i>
            </div>
            <span class="mt-3 text-sm font-medium">Purchase Bill</span>
        </a>

        <a href="uturn_ledger.php" class="flex flex-col items-center justify-center p-4 rounded-2xl bg-red-100 hover:bg-red-200 transition">
            <div class="w-12 h-12 bg-red-500 rounded-xl flex items-center justify-center">
                <i class="ri-bank-card-line text-white text-xl"></i>
            </div>
            <span class="mt-3 text-sm font-medium">Ledger</span>
        </a>

        <a href="uturn_payment_entry.php" class="flex flex-col items-center justify-center p-4 rounded-2xl bg-purple-100 hover:bg-purple-200 transition">
            <div class="w-12 h-12 bg-purple-500 rounded-xl flex items-center justify-center">
                <i class="ri-shopping-cart-2-line text-white text-xl"></i>
            </div>
            <span class="mt-3 text-sm font-medium">Payment Entry</span>
        </a>

        <a href="uturn_expense_entry.php" class="flex flex-col items-center justify-center p-4 rounded-2xl bg-pink-100 hover:bg-pink-200 transition">
            <div class="w-12 h-12 bg-pink-500 rounded-xl flex items-center justify-center">
                <i class="ri-money-dollar-circle-line text-white text-xl"></i>
            </div>
            <span class="mt-3 text-sm font-medium">Expense</span>
        </a>

    </div>

</div>

<!-- Recent Transactions -->
<div class="bg-white rounded-3xl p-6 shadow-sm border border-slate-200 mt-5">

    <div class="flex items-center justify-between mb-5">
        <h3 class="text-xl font-bold text-slate-800">
            Recent Transactions
        </h3>

    </div>

    <div class="overflow-x-auto">

        <table class="w-full min-w-[1000px]">

            <thead>
                <tr class="border-b border-slate-200">

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Entry No
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Type
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Name
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Category
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Amount
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Payment Mode
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Date
                    </th>

                    <th class="text-left py-4 px-4 text-xs font-semibold uppercase tracking-wider text-slate-500">
                        Status
                    </th>

                </tr>
            </thead>

            <tbody>

                <!-- Receipt -->
                <tr class="border-b border-slate-100 hover:bg-slate-50 transition">

                    <td class="py-5 px-4 font-medium text-slate-700">
                        REP-1001
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700">
                            Receipt
                        </span>
                    </td>

                    <td class="py-5 px-4 text-slate-700">
                        Shiv Trading
                    </td>

                    <td class="py-5 px-4 text-slate-500">
                        Invoice Payment
                    </td>

                    <td class="py-5 px-4 font-semibold">
                        ₹45,000
                    </td>

                    <td class="py-5 px-4">
                        Bank Transfer
                    </td>

                    <td class="py-5 px-4">
                        15 Aug 2026
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700">
                            Paid
                        </span>
                    </td>

                </tr>

                <!-- Payment -->
                <tr class="border-b border-slate-100 hover:bg-slate-50 transition">

                    <td class="py-5 px-4 font-medium text-slate-700">
                        PAY-1001
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-red-100 text-red-700">
                            Payment
                        </span>
                    </td>

                    <td class="py-5 px-4 text-slate-700">
                        Akshar Infotech
                    </td>

                    <td class="py-5 px-4 text-slate-500">
                        Vendor Payment
                    </td>

                    <td class="py-5 px-4 font-semibold">
                        ₹25,000
                    </td>

                    <td class="py-5 px-4">
                        UPI
                    </td>

                    <td class="py-5 px-4">
                        16 Aug 2026
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700">
                            Paid
                        </span>
                    </td>

                </tr>

                <!-- Expense -->
                <tr class="hover:bg-slate-50 transition">

                    <td class="py-5 px-4 font-medium text-slate-700">
                        EXP-1001
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-orange-100 text-orange-700">
                            Expense
                        </span>
                    </td>

                    <td class="py-5 px-4 text-slate-700">
                        Office Rent
                    </td>

                    <td class="py-5 px-4 text-slate-500">
                        Rent Expense
                    </td>

                    <td class="py-5 px-4 font-semibold">
                        ₹12,000
                    </td>

                    <td class="py-5 px-4">
                        Bank Transfer
                    </td>

                    <td class="py-5 px-4">
                        17 Aug 2026
                    </td>

                    <td class="py-5 px-4">
                        <span class="px-3 py-1 rounded-full text-xs font-medium bg-green-100 text-green-700">
                            Paid
                        </span>
                    </td>

                </tr>

            </tbody>

        </table>

    </div>

</div>

</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

<script>

let currentType = 'sales';

const monthlyData = {
    labels: [
        'Jan','Feb','Mar','Apr','May','Jun',
        'Jul','Aug','Sep','Oct','Nov','Dec'
    ],

    sales: [120,180,250,220,300,350,280,420,390,450,500,550],
    receipts: [90,120,170,160,210,250,220,300,280,350,400,450],
    expenses: [40,60,80,70,100,120,110,140,130,160,180,200]
};

const yearlyData = {
    labels: [
        '2021',
        '2022',
        '2023',
        '2024',
        '2025'
    ],

    sales: [2500,3200,4500,5800,7200],
    receipts: [2100,2800,3900,5000,6500],
    expenses: [900,1200,1800,2200,2800]
};

const ctx = document.getElementById('salesChart');

const chart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: monthlyData.labels,
        datasets: [{
            label: 'Sales',
            data: monthlyData.sales,
            borderColor: '#2563eb',
            backgroundColor: 'rgba(37,99,235,0.10)',
            fill: true,
            tension: 0.4,
            borderWidth: 3,
            pointRadius: 4
        }]
    },
    options: {
        responsive: true,
        plugins: {
            legend: {
                display: false
            }
        },
        scales: {
            y: {
                beginAtZero: true
            }
        }
    }
});

function changeChart(type) {

    currentType = type;

    const period =
        document.getElementById('periodFilter').value;

    const source =
        period === 'month'
        ? monthlyData
        : yearlyData;

    const title =
        document.getElementById('chartTitle');

    const amount =
        document.getElementById('chartAmount');

    const growth =
        document.getElementById('chartGrowth');

    document.querySelectorAll('.tab-btn').forEach(btn => {
        btn.classList.remove('bg-blue-50','text-blue-600');
        btn.classList.add('bg-gray-100');
    });

    event.currentTarget.classList.remove('bg-gray-100');
    event.currentTarget.classList.add('bg-blue-50','text-blue-600');

    if(type === 'sales') {

        title.innerHTML = 'Total Sales';

        amount.innerHTML =
            period === 'month'
            ? '₹5,25,000'
            : '₹52,50,000';

        growth.innerHTML = '▲ 25% Growth';

        chart.data.datasets[0].data =
            source.sales;
    }

    if(type === 'receipts') {

        title.innerHTML = 'Total Receipts';

        amount.innerHTML =
            period === 'month'
            ? '₹3,75,000'
            : '₹37,50,000';

        growth.innerHTML = '▲ 18% Growth';

        chart.data.datasets[0].data =
            source.receipts;
    }

    if(type === 'expenses') {

        title.innerHTML = 'Total Expenses';

        amount.innerHTML =
            period === 'month'
            ? '₹1,20,000'
            : '₹12,00,000';

        growth.innerHTML = '▼ 8% Growth';

        chart.data.datasets[0].data =
            source.expenses;
    }

    chart.data.labels = source.labels;

    chart.update();
}

function changePeriod(period) {

    const source =
        period === 'month'
        ? monthlyData
        : yearlyData;

    chart.data.labels = source.labels;

    chart.data.datasets[0].data =
        source[currentType];

    chart.update();

    if(currentType === 'sales') {

        document.getElementById('chartAmount').innerHTML =
            period === 'month'
            ? '₹5,25,000'
            : '₹52,50,000';
    }

    if(currentType === 'receipts') {

        document.getElementById('chartAmount').innerHTML =
            period === 'month'
            ? '₹3,75,000'
            : '₹37,50,000';
    }

    if(currentType === 'expenses') {

        document.getElementById('chartAmount').innerHTML =
            period === 'month'
            ? '₹1,20,000'
            : '₹12,00,000';
    }
}

</script>

<?php include 'footer.php'; ?>