<?php
require_once dirname(__DIR__).'/config.php';
$u = current_user(); if(!$u){header('Location: ' . url('?login=1'));exit;}
?><!DOCTYPE html><html lang="ar" dir="rtl"><head>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>لوحة تحكم المزود — سودانا</title>
<style>:root{--g:#00d97e;--dark:#073328;--bg:#f0fdf4;--card:#fff;--text:#1e293b;--muted:#64748b;--border:#e2e8f0;--red:#dc2626;--sb:env(safe-area-inset-bottom,0px)}
*{box-sizing:border-box;margin:0;padding:0}body{font-family:'Cairo',system-ui,sans-serif;background:var(--bg);min-height:100vh;padding-bottom:calc(70px + var(--sb))}
.hdr{background:var(--dark);height:56px;display:flex;align-items:center;justify-content:space-between;padding:0 16px;position:sticky;top:0;z-index:100}
.hdr-t{color:#fff;font-weight:900;font-size:.95rem}.back{color:rgba(255,255,255,.6);font-size:.82rem;text-decoration:none}
.con{max-width:640px;margin:0 auto;padding:16px}
.card{background:var(--card);border:1px solid var(--border);border-radius:16px;padding:16px;margin-bottom:14px}
.ct{font-size:.9rem;font-weight:800;color:var(--dark);margin-bottom:12px}
.btn{background:linear-gradient(135deg,var(--g),#059669);color:#fff;border:none;border-radius:12px;padding:12px;font-family:inherit;font-weight:800;font-size:.88rem;cursor:pointer;width:100%;margin-top:8px}
.field{margin-bottom:12px}.field label{display:block;font-size:.72rem;font-weight:700;color:var(--muted);margin-bottom:4px}
.field input,.field select,.field textarea{width:100%;background:#f8fafc;border:1.5px solid var(--border);border-radius:10px;padding:10px 12px;font-family:inherit;font-size:15px}
.field textarea{resize:none;height:80px}
.skel{background:linear-gradient(90deg,#f0f0f0 25%,#e8e8e8 50%,#f0f0f0 75%);background-size:200% 100%;animation:sk 1.2s infinite;border-radius:12px;height:80px;margin-bottom:8px}@keyframes sk{0%{background-position:200% 0}100%{background-position:-200% 0}}
</style></head><body>
<header class="hdr"><div class="hdr-t">لوحة تحكم المزود</div><a href="/app/hub.php" class="back">← الهب</a></header>
<div class="con">
<div style="background:linear-gradient(135deg,var(--dark),#0a3d2a);border-radius:16px;padding:20px;margin-bottom:14px;color:#fff">
  <div style="font-size:.72rem;color:rgba(255,255,255,.5);margin-bottom:4px">أرباحك الصافية</div>
  <div style="font-size:2rem;font-weight:900" id="p-net">— SDG</div>
  <div style="display:flex;gap:16px;margin-top:12px;font-size:.72rem">
    <div><div style="color:rgba(255,255,255,.5)">اليوم</div><div style="font-weight:700" id="p-today">—</div></div>
    <div><div style="color:rgba(255,255,255,.5)">الشهر</div><div style="font-weight:700" id="p-month">—</div></div>
    <div><div style="color:rgba(255,255,255,.5)">خدمات</div><div style="font-weight:700" id="p-count">—</div></div>
  </div>
</div>
<div class="card"><div class="ct">📋 الحجوزات الجديدة</div><div id="p-bookings"><div class="skel"></div></div></div>
<div class="card"><div class="ct">📊 آخر المدفوعات</div><div id="p-payments"><div class="skel"></div></div></div>
<div class="card">
  <div class="ct">⚙️ إعدادات ملفك</div>
  <a href="/app/provider-register.php" style="display:block;background:#f0fdf4;border:1px solid #bbf7d0;border-radius:10px;padding:10px;text-align:center;font-size:.8rem;font-weight:700;color:var(--dark);text-decoration:none;margin-bottom:8px">✏️ تعديل الملف الشخصي</a>
  <a href="/app/settings.php" style="display:block;background:#f8fafc;border:1px solid var(--border);border-radius:10px;padding:10px;text-align:center;font-size:.8rem;font-weight:700;color:var(--dark);text-decoration:none">🔐 إعدادات الأمان</a>
</div>
</div>
<nav style="position:fixed;bottom:0;left:0;right:0;background:#fff;border-top:1px solid var(--border);display:flex;padding:8px 0 calc(8px + var(--sb));z-index:100">
  <a href="/app/hub.php" style="flex:1;text-align:center;text-decoration:none;color:#64748b;font-size:.6rem"><span style="font-size:1.1rem;display:block">&#127968;</span>الهب</a>
  <a href="/app/pay.php" style="flex:1;text-align:center;text-decoration:none;color:#64748b;font-size:.6rem"><span style="font-size:1.1rem;display:block">&#128179;</span>Pay</a>
  <a href="/app/services.php" style="flex:1;text-align:center;text-decoration:none;color:#64748b;font-size:.6rem"><span style="font-size:1.1rem;display:block">&#128295;</span>خدمات</a>
  <a href="/app/support.php" style="flex:1;text-align:center;text-decoration:none;color:#64748b;font-size:.6rem"><span style="font-size:1.1rem;display:block">&#127993;</span>الدعم</a>
  <a href="/app/profile.php" style="flex:1;text-align:center;text-decoration:none;color:#64748b;font-size:.6rem"><span style="font-size:1.1rem;display:block">&#128100;</span>حسابي</a>
</nav>
<script>
async function loadDash(){
  try{
    const r = await fetch('/api/services/provider_earnings.php');
    const d = await r.json();
    const e = d.data||{};
    const fmt = n=>Number(n||0).toLocaleString('ar-SA');
    document.getElementById('p-net').textContent   = fmt(e.total_net)+' SDG';
    document.getElementById('p-month').textContent = fmt(e.month_net)+' SDG';
    document.getElementById('p-count').textContent = (e.service_count||0)+' خدمة';
    const r2 = await fetch('/api/services/history.php?limit=5');
    const d2 = await r2.json();
    const hist = d2.data||[];
    document.getElementById('p-bookings').innerHTML = hist.length?hist.slice(0,4).map(h=>`
      <div style="display:flex;justify-content:space-between;padding:8px;border-bottom:1px solid var(--border);font-size:.75rem">
        <div style="font-weight:600">${h.service_type||'خدمة'}</div>
        <div style="color:#059669;font-weight:700">${fmt(h.amount_sdg)} SDG</div>
      </div>`).join(''):'<p style="color:var(--muted);text-align:center;font-size:.78rem;padding:12px">لا خدمات بعد</p>';
  }catch(e){}
}
loadDash();
</script></body></html>