@extends('layouts.admin')

@section('title', 'Dashboard')

@section('content')
<div class="min-h-screen bg-slate-50">
    <div class="mx-auto max-w-7xl px-4 py-6 sm:px-6 lg:px-8">

        {{-- Header --}}
        <div class="mb-8 overflow-hidden rounded-3xl bg-gradient-to-r from-slate-900 via-slate-800 to-indigo-900 p-6 text-white shadow-xl">
            <div class="flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
                <div>
                    <h1 class="text-2xl font-bold md:text-3xl">Admin Dashboard</h1>
                    <p class="mt-2 text-sm text-slate-200 md:text-base"></p>
                </div>

                <div class="grid grid-cols-2 gap-3 sm:grid-cols-3">
                    <div class="rounded-2xl bg-white/10 px-4 py-3 backdrop-blur">
                        <p class="text-xs uppercase tracking-wide text-slate-200">Revenue</p>
                        <p class="mt-1 text-lg font-bold">৳ {{ number_format($totalRevenue, 2) }}</p>
                    </div>
                    <div class="rounded-2xl bg-white/10 px-4 py-3 backdrop-blur">
                        <p class="text-xs uppercase tracking-wide text-slate-200">Expense</p>
                        <p class="mt-1 text-lg font-bold">৳ {{ number_format($totalExpenses, 2) }}</p>
                    </div>
                    <div class="rounded-2xl bg-white/10 px-4 py-3 backdrop-blur col-span-2 sm:col-span-1">
                        <p class="text-xs uppercase tracking-wide text-slate-200">Profit</p>
                        <p class="mt-1 text-lg font-bold">৳ {{ number_format($profit, 2) }}</p>
                    </div>
                </div>
            </div>
        </div>

        {{-- Section Title --}}
        <div class="mb-5">
            <h2 class="text-xl font-bold text-slate-800">Dashboard Overview</h2>
            <p class="mt-1 text-sm text-slate-500"></p>
        </div>

        {{-- Stats Grid --}}
        <div class="grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-5">

            {{-- Revenue --}}
            <div class="group rounded-3xl border border-slate-200 bg-white p-5 shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl">
                <div class="flex items-center justify-between">
                    <div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-emerald-100 text-2xl">
                        💰
                    </div>
                    <span class="rounded-full bg-emerald-50 px-3 py-1 text-xs font-semibold text-emerald-700">
                        Revenue
                    </span>
                </div>
                <p class="mt-5 text-sm font-medium text-slate-500">Total Revenue</p>
                <h3 class="mt-2 text-2xl font-extrabold text-slate-800">
                    ৳ {{ number_format($totalRevenue, 2) }}
                </h3>
                <p class="mt-2 text-xs text-slate-400">সাবস্ক্রিপশন থেকে মোট আয়</p>
            </div>

            {{-- Expenses --}}
            <div class="group rounded-3xl border border-slate-200 bg-white p-5 shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl">
                <div class="flex items-center justify-between">
                    <div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-rose-100 text-2xl">
                        💸
                    </div>
                    <span class="rounded-full bg-rose-50 px-3 py-1 text-xs font-semibold text-rose-700">
                        Expense
                    </span>
                </div>
                <p class="mt-5 text-sm font-medium text-slate-500">Total Expenses</p>
                <h3 class="mt-2 text-2xl font-extrabold text-slate-800">
                    ৳ {{ number_format($totalExpenses, 2) }}
                </h3>
                <p class="mt-2 text-xs text-slate-400">অ্যাডমিন খরচের মোট পরিমাণ</p>
            </div>

            {{-- Profit --}}
            <div class="group rounded-3xl border border-slate-200 bg-white p-5 shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl">
                <div class="flex items-center justify-between">
                    <div class="flex h-12 w-12 items-center justify-center rounded-2xl {{ $profit >= 0 ? 'bg-blue-100' : 'bg-amber-100' }} text-2xl">
                        📈
                    </div>
                    <span class="rounded-full px-3 py-1 text-xs font-semibold {{ $profit >= 0 ? 'bg-blue-50 text-blue-700' : 'bg-amber-50 text-amber-700' }}">
                        {{ $profit >= 0 ? 'Profit' : 'Loss' }}
                    </span>
                </div>
                <p class="mt-5 text-sm font-medium text-slate-500">Net Result</p>
                <h3 class="mt-2 text-2xl font-extrabold {{ $profit >= 0 ? 'text-emerald-600' : 'text-red-600' }}">
                    ৳ {{ number_format($profit, 2) }}
                </h3>
                <p class="mt-2 text-xs text-slate-400">Revenue - Expenses</p>
            </div>

            {{-- Active Subscribers --}}
            <div class="group rounded-3xl border border-slate-200 bg-white p-5 shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl">
                <div class="flex items-center justify-between">
                    <div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-indigo-100 text-2xl">
                        ✅
                    </div>
                    <span class="rounded-full bg-indigo-50 px-3 py-1 text-xs font-semibold text-indigo-700">
                        Subscribers
                    </span>
                </div>
                <p class="mt-5 text-sm font-medium text-slate-500">Active Subscribers</p>
                <h3 class="mt-2 text-2xl font-extrabold text-slate-800">
                    {{ $activeSubscribers }}
                </h3>
                <p class="mt-2 text-xs text-slate-400">বর্তমানে সক্রিয় সাবস্ক্রাইবার</p>
            </div>

            {{-- Total Users --}}
            <div class="group rounded-3xl border border-slate-200 bg-white p-5 shadow-sm transition duration-300 hover:-translate-y-1 hover:shadow-xl">
                <div class="flex items-center justify-between">
                    <div class="flex h-12 w-12 items-center justify-center rounded-2xl bg-violet-100 text-2xl">
                        👤
                    </div>
                    <span class="rounded-full bg-violet-50 px-3 py-1 text-xs font-semibold text-violet-700">
                        Users
                    </span>
                </div>
                <p class="mt-5 text-sm font-medium text-slate-500">Total Users</p>
                <h3 class="mt-2 text-2xl font-extrabold text-slate-800">
                    {{ $totalUsers }}
                </h3>
                <p class="mt-2 text-xs text-slate-400">সিস্টেমে মোট নিবন্ধিত ইউজার</p>
            </div>
        </div>

        {{-- Bottom Summary Cards --}}
        <div class="mt-8 grid grid-cols-1 gap-6 lg:grid-cols-2">
            <div class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm">
                <h3 class="text-lg font-bold text-slate-800">Financial Summary</h3>
                <div class="mt-4 space-y-4">
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Total Revenue</span>
                        <span class="text-sm font-bold text-emerald-600">৳ {{ number_format($totalRevenue, 2) }}</span>
                    </div>
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Total Expenses</span>
                        <span class="text-sm font-bold text-rose-600">৳ {{ number_format($totalExpenses, 2) }}</span>
                    </div>
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Net {{ $profit >= 0 ? 'Profit' : 'Loss' }}</span>
                        <span class="text-sm font-bold {{ $profit >= 0 ? 'text-emerald-600' : 'text-red-600' }}">
                            ৳ {{ number_format($profit, 2) }}
                        </span>
                    </div>
                </div>
            </div>

            <div class="rounded-3xl border border-slate-200 bg-white p-6 shadow-sm">
                <h3 class="text-lg font-bold text-slate-800">User Summary</h3>
                <div class="mt-4 space-y-4">
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Active Subscribers</span>
                        <span class="text-sm font-bold text-indigo-600">{{ $activeSubscribers }}</span>
                    </div>
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Total Users</span>
                        <span class="text-sm font-bold text-violet-600">{{ $totalUsers }}</span>
                    </div>
                    <div class="flex items-center justify-between rounded-2xl bg-slate-50 px-4 py-3">
                        <span class="text-sm font-medium text-slate-600">Conversion View</span>
                        <span class="text-sm font-bold text-slate-800">
                            {{ $totalUsers > 0 ? number_format(($activeSubscribers / $totalUsers) * 100, 2) : '0.00' }}%
                        </span>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>
@endsection