{{-- resources/views/admin/dashboard.blade.php --}}
@extends('layout.admin')

@section('title','Admin Dashboard')

@section('content')
@php
  $dashboardMetricAllowed = array_values((array) ($dashboardMetricAllowed ?? \App\Support\AdminDashboardMetricRegistry::metricKeys()));
  $canDashboardMetric = static fn (string $key): bool => in_array($key, $dashboardMetricAllowed, true);
  $hasDashboardSection = static function (string $sectionKey) use ($dashboardMetricAllowed): bool {
    $sectionKeys = \App\Support\AdminDashboardMetricRegistry::metricKeysForSection($sectionKey);
    return count(array_intersect($sectionKeys, $dashboardMetricAllowed)) > 0;
  };
@endphp

<style>
  /* ===== Screenshot-like tile style for number cards ===== */
  .ss-tile{
    position:relative; border-radius:16px; padding:18px; overflow:hidden;
    box-shadow:0 10px 24px rgba(0,0,0,.14); display:flex; align-items:center; justify-content:space-between; min-height:112px
  }
  .ss-tile h6{margin:0; font-size:14px; font-weight:700; letter-spacing:.04em; color:#eaf1ff; opacity:.95}
  .ss-amt{margin:2px 0 0; font-size:34px; line-height:1; font-weight:900; color:#fff; text-shadow:0 2px 0 rgba(0,0,0,.15)}
  .ss-amt.small{font-size:28px}
  .ss-icon-ring{
    position:absolute; right:18px; top:18px; height:82px; width:82px; border-radius:9999px;
    display:grid; place-items:center; background:rgba(255,255,255,.09)
  }
  .ss-icon-ring i{font-size:28px; color:#ffffff9c}
  .ss-muted{font-size:12px; color:#e7efff; opacity:.9}
  .ss-row{display:grid; gap:16px}
  @media(min-width:640px){ .ss-row{grid-template-columns:repeat(2,1fr)} }
  @media(min-width:1024px){ .ss-row-4{grid-template-columns:repeat(4,1fr)} .ss-row-5{grid-template-columns:repeat(5,1fr)} }

  /* brand-like backgrounds (close to your screenshot) */
  .bg-ss-green{background:#2f5e2f}
  .bg-ss-yellow{background:#7a5c12}
  .bg-ss-red{background:#7a1f26}
  .bg-ss-indigo{background:#303a7e}
  .bg-ss-blue{background:#2d5edd}
  .bg-ss-deep{background:#203a4d}
  .bg-ss-purple{background:#3e1a64}
  .bg-ss-pink{background:#7a1f5b}
  .bg-ss-emerald{background:#0f6a46}
  .bg-ss-orange{background:#c05a0f}
  .bg-ss-teal{background:#0b6a66}
</style>

<div class="px-0 py-2 space-y-6">

  

  {{-- ========== Users: Small Stats (screenshot-style boxes) ========== --}}
  @if($hasDashboardSection('users'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">👥 ইউজার হিসাব</h3>
    <div class="ss-row ss-row-4 mt-3">
      @if($canDashboardMetric('users_active'))
      <div class="ss-tile bg-ss-green">
        <div>
          <h6>ভেরিফাইড</h6>
          <div class="ss-amt">{{ number_format($activeUsers) }}</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-check-circle"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('users_inactive'))
      <div class="ss-tile bg-ss-yellow">
        <div>
          <h6>আনভেরিফাইড</h6>
          <div class="ss-amt">{{ number_format($inactiveUsers) }}</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-clock"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('users_banned'))
      <div class="ss-tile bg-ss-red">
        <div>
          <h6>ব্যানড</h6>
          <div class="ss-amt">{{ number_format($bannedUsers) }}</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-ban"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('users_total'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>মোট</h6>
          <div class="ss-amt">{{ number_format($totalUsers) }}</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-users"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== User Funds ========== --}}
  @if($hasDashboardSection('funds'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">💰 বর্তমান ইউজার ফান্ড</h3>
    <div class="ss-row mt-3">
      @if($canDashboardMetric('funds_balance'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>ব্যালেন্স ফান্ড</h6>
          <div class="ss-amt small">{{ number_format($totalBalanceFund, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-wallet"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('funds_voucher'))
      <div class="ss-tile bg-ss-pink">
        <div>
          <h6>ভাউচার ফান্ড</h6>
          <div class="ss-amt small">{{ number_format($totalVoucherFund, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-ticket-alt"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== Gmail ========== --}}
  @if($hasDashboardSection('gmail'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">
      📧 জিমেইল পেমেন্ট হিসাব
      <span class="text-xs text-gray-500 font-normal">(Per Gmail Price: {{ number_format($gmailPrice, 2) }} ৳ | Admin Price: {{ number_format($gmailAdminPrice, 2) }} ৳)</span>
    </h3>
    <div class="ss-row ss-row-5 mt-3">
      @if($canDashboardMetric('gmail_today'))
      <div class="ss-tile bg-ss-blue">
        <div>
          <h6>আজ</h6>
          <div class="ss-amt small">{{ number_format($gmailTodayAmount, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-day"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('gmail_yesterday'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>গতকাল</h6>
          <div class="ss-amt small">{{ number_format($gmailYesterdayAmount, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-alt"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('gmail_last7'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>৭ দিন</h6>
          <div class="ss-amt small">{{ number_format($gmailLast7Amount, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-week"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('gmail_last30'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>৩০ দিন</h6>
          <div class="ss-amt small">{{ number_format($gmailLast30Amount, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('gmail_total'))
      <div class="ss-tile bg-ss-pink">
        <div>
          <h6>সর্বমোট</h6>
          <div class="ss-amt small">{{ number_format($gmailTotalAmount, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-wallet"></i></span>
      </div>
      @endif
    </div>
    <div class="ss-row mt-3">
      @if($canDashboardMetric('gmail_user_payment'))
      <div class="ss-tile bg-ss-orange">
        <div>
          <h6>ইউজার পেমেন্ট অল</h6>
          <div class="ss-amt small">{{ number_format($gmailUserPaymentAll, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">ইউজার রেট + অফলাইন কমিশন</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-money-bill-wave"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('gmail_admin_profit'))
        <div class="ss-tile bg-ss-teal">
        <div>
          <h6>এডমিন প্রফিট</h6>
          <div class="ss-amt small">{{ number_format($gmailAdminProfit, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">Admin Price - Per Gmail Price</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-chart-line"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== Facebook (User/Company) ========== --}}
  @if($hasDashboardSection('facebook'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">📘 ফেসবুক পেমেন্ট হিসাব</h3>
    <div class="ss-row ss-row-4 mt-3">
      @if($canDashboardMetric('facebook_today'))
      <div class="ss-tile bg-ss-blue">
        <div>
          <h6>আজ</h6>
          <div class="ss-amt small">{{ number_format($fbTodayUser, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">ইউজার / কোম্পানি: {{ number_format($fbTodayCompany,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-day"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('facebook_yesterday'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>গতকাল</h6>
          <div class="ss-amt small">{{ number_format($fbYesterdayUser, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($fbYesterdayCompany,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-alt"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('facebook_last7'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>৭ দিন</h6>
          <div class="ss-amt small">{{ number_format($fbLast7User, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($fbLast7Company,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-week"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('facebook_last30'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>৩০ দিন</h6>
          <div class="ss-amt small">{{ number_format($fbLast30User, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($fbLast30Company,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar"></i></span>
      </div>
      @endif
    </div>

    <div class="ss-row mt-3">
      @if($canDashboardMetric('facebook_user_payment'))
      <div class="ss-tile bg-ss-pink">
        <div>
          <h6>ইউজার পেমেন্ট (মোট)</h6>
          <div class="ss-amt small">{{ number_format($fbUserPayment, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-user"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('facebook_company_profit'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>কোম্পানি প্রফিট (মোট)</h6>
          <div class="ss-amt small">{{ number_format($fbCompanyProfit, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-building"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== Instagram (User/Company) ========== --}}
  @if($hasDashboardSection('instagram'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">📸 ইনস্টাগ্রাম পেমেন্ট হিসাব</h3>
    <div class="ss-row ss-row-4 mt-3">
      @if($canDashboardMetric('instagram_today'))
      <div class="ss-tile bg-ss-blue">
        <div>
          <h6>আজ</h6>
          <div class="ss-amt small">{{ number_format($inTodayUser, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($inTodayCompany,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-day"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('instagram_yesterday'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>গতকাল</h6>
          <div class="ss-amt small">{{ number_format($inYesterdayUser, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($inYesterdayCompany,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-alt"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('instagram_last7'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>৭ দিন</h6>
          <div class="ss-amt small">{{ number_format($inLast7User, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($inLast7Company,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-week"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('instagram_last30'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>৩০ দিন</h6>
          <div class="ss-amt small">{{ number_format($inLast30User, 2) }} <span class="ss-muted">৳</span></div>
          <div class="ss-muted">কোম্পানি: {{ number_format($inLast30Company,2) }} ৳</div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar"></i></span>
      </div>
      @endif
    </div>

    <div class="ss-row mt-3">
      @if($canDashboardMetric('instagram_user_payment'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>ইউজার পেমেন্ট (মোট)</h6>
          <div class="ss-amt small">{{ number_format($inUserPayment, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-user"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('instagram_company_profit'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>কোম্পানি প্রফিট (মোট)</h6>
          <div class="ss-amt small">{{ number_format($inCompanyProfit, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-building"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== Mobile Recharge (amounts + profit) ========== --}}
  @if($hasDashboardSection('recharge'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">📱 মোবাইল রিচার্জ হিসাব</h3>

    <div class="ss-row ss-row-5 mt-3">
      @if($canDashboardMetric('recharge_today'))
      <div class="ss-tile bg-ss-orange">
        <div>
          <h6>আজ</h6>
          <div class="ss-amt small">{{ number_format($rechargeToday, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-bolt"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('recharge_yesterday'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>গতকাল</h6>
          <div class="ss-amt small">{{ number_format($rechargeYesterday, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-alt"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('recharge_last7'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>৭ দিন</h6>
          <div class="ss-amt small">{{ number_format($rechargeLast7, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar-week"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('recharge_last30'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>৩০ দিন</h6>
          <div class="ss-amt small">{{ number_format($rechargeLast30, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-calendar"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('recharge_total'))
      <div class="ss-tile bg-ss-pink">
        <div>
          <h6>সর্বমোট</h6>
          <div class="ss-amt small">{{ number_format($rechargeTotal, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-wallet"></i></span>
      </div>
      @endif
    </div>

    <div class="ss-row mt-3">
      @if($canDashboardMetric('recharge_company_profit'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>রিচার্জ প্রফিট (হাজারে ২ টাকা)</h6>
          <div class="ss-amt small">{{ number_format($rechargeCompanyProfit, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-chart-line"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

  {{-- ========== Withdraws ========== --}}
  @if($hasDashboardSection('withdraw'))
  <section>
    <h3 class="text-base font-semibold text-gray-800 px-1">🧾 উইথড্র হিসাব</h3>
    <div class="ss-row ss-row-5 mt-3">
      @if($canDashboardMetric('withdraw_today'))
      <div class="ss-tile bg-ss-blue">
        <div>
          <h6>আজ</h6>
          <div class="ss-amt small">{{ number_format($todayWithdraw, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-hand-holding-usd"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('withdraw_yesterday'))
      <div class="ss-tile bg-ss-emerald">
        <div>
          <h6>গতকাল</h6>
          <div class="ss-amt small">{{ number_format($yesterdayWithdraw, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-hand-holding-usd"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('withdraw_last7'))
      <div class="ss-tile bg-ss-indigo">
        <div>
          <h6>৭ দিন</h6>
          <div class="ss-amt small">{{ number_format($last7Withdraw, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-hand-holding-usd"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('withdraw_last30'))
      <div class="ss-tile bg-ss-purple">
        <div>
          <h6>৩০ দিন</h6>
          <div class="ss-amt small">{{ number_format($last30Withdraw, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-hand-holding-usd"></i></span>
      </div>
      @endif
      @if($canDashboardMetric('withdraw_total'))
      <div class="ss-tile bg-ss-teal">
        <div>
          <h6>মোট</h6>
          <div class="ss-amt small">{{ number_format($totalWithdraw, 2) }} <span class="ss-muted">৳</span></div>
        </div>
        <span class="ss-icon-ring"><i class="fas fa-hand-holding-usd"></i></span>
      </div>
      @endif
    </div>
  </section>
  @endif

</div>
@endsection
