<!doctype html>
<html lang="ar" dir="rtl" data-theme="dim">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>مبيعات الفروع</title>

  <style>
    /* =========================
       Theme Variables (Default = DIM)  ✅ نفس الإعدادات
       ========================= */
    :root{ /* default = dim */
      --bg:#121826;
      --surface:#101827;
      --card:#151e30;
      --card2:#0f1a33;

      --text:#e5e7eb;
      --muted:#9ca3af;

      --border:rgba(255,255,255,.10);
      --border2:rgba(255,255,255,.14);
      --shadow:0 18px 40px rgba(0,0,0,.22);

      --primary:#6366f1;
      --primary2:#4f46e5;
      --success:#22c55e;
      --warning:#f59e0b;
      --danger:#ef4444;

      --input:#0b1327;
      --inputBorder:rgba(255,255,255,.12);
      --inputFocus:rgba(99,102,241,.35);

      --tableHead:rgba(255,255,255,.05);
      --rowHover:rgba(99,102,241,.08);
    }

    /* ✅ Dark (أغمق) */
    html[data-theme="dark"]{
      --bg:#070b14;
      --surface:#0b1220;
      --card:#0f172a;
      --card2:#0b1327;
    }

    /* ✅ Light (أبيض صافي مثل التصميم القديم) */
    html[data-theme="light"]{
      --bg:#ffffff;
      --surface:#ffffff;
      --card:#ffffff;
      --card2:#ffffff;

      --text:#111827;
      --muted:#6b7280;

      --border:rgba(17,24,39,.10);
      --border2:rgba(17,24,39,.14);
      --shadow:0 12px 28px rgba(0,0,0,.10);

      --primary:#111827;
      --primary2:#111827;

      --success:#16a34a;
      --warning:#d97706;
      --danger:#dc2626;

      --input:#ffffff;
      --inputBorder:rgba(17,24,39,.14);
      --inputFocus:rgba(17,24,39,.12);

      --tableHead:rgba(17,24,39,.03);
      --rowHover:rgba(17,24,39,.03);
    }

    *{box-sizing:border-box}

    body{
      font-family:Arial, sans-serif;
      margin:0;
      background:var(--bg);
      color:var(--text);
      padding:22px;
    }

    /* ✅ لو الثيم dim/dark نخلي خلفية لطيفة */
    html[data-theme="dim"] body,
    html[data-theme="dark"] body{
      background:linear-gradient(180deg, var(--bg), var(--bg));
    }

    .container{max-width:1200px;margin:0 auto}

    /* Header */
    .pageHeader{
      background:linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02));
      border:1px solid var(--border);
      border-radius:18px;
      box-shadow:var(--shadow);
      padding:16px 16px 12px;
      margin-bottom:14px;
    }
    html[data-theme="light"] .pageHeader{
      background:#ffffff;
      border-color:rgba(17,24,39,.10);
      box-shadow:0 12px 28px rgba(0,0,0,.08);
    }

    .headerTop{
      display:flex;align-items:flex-start;justify-content:space-between;gap:12px;flex-wrap:wrap
    }
    .title{font-weight:900;font-size:18px;letter-spacing:.2px}
    .subtitle{color:var(--muted);font-size:13px;margin-top:6px;line-height:1.6}

    .navRow{
      display:flex;gap:8px;flex-wrap:nowrap;overflow:auto;max-width:100%;
      padding-top:10px;padding-bottom:6px;-webkit-overflow-scrolling:touch;align-items:center
    }
    .navRow > *{flex:0 0 auto; white-space:nowrap;}

    /* Buttons */
    .btn{
      padding:10px 12px;border-radius:12px;border:1px solid transparent;
      cursor:pointer;font-weight:900;font-size:13px;line-height:1;
      display:inline-flex;align-items:center;gap:8px;text-decoration:none;
      transition:transform .05s ease, opacity .15s ease, border-color .15s ease;
      user-select:none;
    }
    .btn:active{transform:translateY(1px)}

    .btnPrimary{
      background:linear-gradient(180deg, var(--primary), var(--primary2));
      color:#fff;border-color:rgba(255,255,255,.10)
    }
    html[data-theme="light"] .btnPrimary{
      background:#111827; color:#fff; border-color:rgba(17,24,39,.12);
    }

    .btnGhost{
      background:rgba(255,255,255,.03);
      color:var(--text);
      border-color:var(--border2)
    }
    html[data-theme="light"] .btnGhost{
      background:#ffffff;
      border-color:rgba(17,24,39,.12);
    }
    .btnGhost:hover{border-color:rgba(255,255,255,.18)}
    html[data-theme="light"] .btnGhost:hover{border-color:rgba(17,24,39,.20)}

    .btnDanger{
      background:rgba(239,68,68,.14);
      color:#fff;border-color:rgba(239,68,68,.35)
    }
    html[data-theme="light"] .btnDanger{
      background:#ffffff;
      color:#dc2626;
      border-color:rgba(220,38,38,.25);
    }
    .btnDanger:hover{opacity:.95}

    .activeTab{
      background:rgba(99,102,241,.20);
      border-color:rgba(99,102,241,.55);
      color:#fff;
    }
    html[data-theme="light"] .activeTab{
      background:rgba(17,24,39,.05);
      border-color:rgba(17,24,39,.18);
      color:#111827;
    }

    /* Cards */
    .card{
      background:linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.02));
      border:1px solid var(--border);
      border-radius:18px;
      box-shadow:var(--shadow);
      padding:16px;
      margin-bottom:14px;
    }
    html[data-theme="light"] .card{
      background:#ffffff;
      border-color:rgba(17,24,39,.10);
      box-shadow:0 12px 28px rgba(0,0,0,.08);
    }

    /* Forms */
    label{display:block;font-size:12px;color:var(--muted);font-weight:900;margin-bottom:6px}
    input, select{
      width:100%;
      padding:11px 12px;
      border:1px solid var(--inputBorder);
      border-radius:12px;
      outline:none;
      font-size:14px;
      background:var(--input);
      color:var(--text);
    }
    input:focus, select:focus{
      border-color:rgba(99,102,241,.55);
      box-shadow:0 0 0 3px var(--inputFocus);
    }
    html[data-theme="light"] input:focus,
    html[data-theme="light"] select:focus{
      border-color:rgba(17,24,39,.22);
      box-shadow:0 0 0 3px rgba(17,24,39,.08);
    }

    .grid{
      display:grid;
      grid-template-columns: 1fr 0.8fr 0.8fr auto;
      gap:12px;
      align-items:end;
    }
    @media (max-width: 980px){
      body{padding:16px}
      .grid{grid-template-columns:1fr 1fr}
    }
    @media (max-width: 560px){
      .grid{grid-template-columns:1fr}
    }

    /* Table */
    .tableWrap{
      overflow:auto;
      border-radius:14px;
      border:1px solid var(--border);
      background:rgba(0,0,0,.10);
      margin-top:12px;
    }
    html[data-theme="light"] .tableWrap{
      background:#ffffff;
      border-color:rgba(17,24,39,.10);
    }

    table{
      width:100%;
      border-collapse:separate;
      border-spacing:0;
      min-width:980px;
    }
    thead th{
      position:sticky;top:0;z-index:2;
      background:var(--tableHead);
      border-bottom:1px solid var(--border);
      padding:12px 12px;
      font-weight:900;
      font-size:13px;
      white-space:nowrap;
      text-align:right;
    }
    tbody td{
      padding:12px 12px;
      border-bottom:1px solid rgba(255,255,255,.06);
      font-size:13px;
      vertical-align:middle;
    }
    html[data-theme="light"] tbody td{
      border-bottom:1px solid rgba(17,24,39,.08);
    }
    tbody tr:hover td{background:var(--rowHover)}

    .num{font-weight:900}
    .empty{color:var(--muted);font-weight:900;text-align:center;padding:16px}
  </style>

  <!-- ✅ Apply saved theme ASAP (avoid flash) -->
  <script>
    (function(){
      const themes = ["light","dim","dark"];
      const key = "ui_theme";
      const saved = localStorage.getItem(key);
      const t = (saved && themes.includes(saved)) ? saved : "dim";
      document.documentElement.setAttribute("data-theme", t);
    })();
  </script>
</head>

<body>
<div class="container">

  <!-- ✅ Top bar + Sub bar داخل Card أبيض/داكن (نفس الإعدادات) -->
  <div class="pageHeader">
    <div class="headerTop">
      <div>
        <div class="title">مبيعات الفروع</div>
        <div class="subtitle">ملخص المبيعات حسب الفرع + فلترة</div>
      </div>

      <div class="navRow">
        <a class="btn btnPrimary" href="<?php echo e(route('dashboard.sales')); ?>">الرئيسية</a>

        <a class="btn btnGhost activeTab" href="<?php echo e(route('dashboard.sales')); ?>">المبيعات</a>
        <a class="btn btnGhost" href="<?php echo e(route('purchases.index')); ?>">المشتريات</a>
        <a class="btn btnGhost" href="<?php echo e(route('expenses.index')); ?>">المصروفات</a>

        <a class="btn btnGhost" href="<?php echo e(route('dashboard.reports')); ?>">التقارير</a>
        <a class="btn btnGhost" href="<?php echo e(route('settings.index')); ?>">الإعدادات</a>

        <?php if(auth()->check() && (auth()->user()->role ?? 'user') === 'admin'): ?>
          <a class="btn btnGhost" href="<?php echo e(route('branches.index')); ?>">إدارة الفروع</a>
          <a class="btn btnGhost" href="<?php echo e(route('users.index')); ?>">إدارة المستخدمين</a>
        <?php endif; ?>

        <!-- ✅ زر واحد فقط (نفس الإعدادات) -->
        <button class="btn btnGhost" type="button" id="themeBtn">🎨 المظهر</button>

        <form method="POST" action="<?php echo e(route('logout')); ?>" style="display:inline">
          <?php echo csrf_field(); ?>
          <button class="btn btnDanger" type="submit">خروج</button>
        </form>
      </div>
    </div>
  </div>

  <?php
    // ✅ اعتمد على request لضمان أن الفرع المختار فعلاً هو اللي يستخدمه الزر
    $selectedBranchId = (int) request('branch_id', $branchId ?? 0);
  ?>

  <!-- ✅ Sub bar للأزرار السريعة -->
  <div class="card">
    <div class="navRow">
      <a class="btn btnGhost"
         href="<?php echo e(route('dashboard.sales.report', ['branch_id'=>$selectedBranchId,'from'=>$from,'to'=>$to])); ?>">
        تقرير المبيعات
      </a>

      <?php if($selectedBranchId > 0): ?>
        <a class="btn btnGhost"
           href="<?php echo e(route('dashboard.branch.details', ['branchId'=>$selectedBranchId, 'from'=>$from, 'to'=>$to])); ?>">
          فواتير المبيعات (مفصل)
        </a>
      <?php else: ?>
        <span class="btn btnGhost" style="opacity:.55; cursor:not-allowed;" title="اختر فرع من الفلاتر أولاً">
          فواتير المبيعات (مفصل)
        </span>
      <?php endif; ?>
    </div>
  </div>

  <!-- ✅ Filters -->
  <div class="card">
    <div style="font-weight:900;margin-bottom:10px">الفلاتر</div>

    <form method="GET" action="<?php echo e(route('dashboard.sales')); ?>">
      <div class="grid">
        <div>
          <label>الفرع</label>
          <select name="branch_id">
            <option value="0">كل الفروع</option>
            <?php $__currentLoopData = $branches; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $b): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
              <option value="<?php echo e($b->id); ?>" <?php if((int)$branchId === (int)$b->id): echo 'selected'; endif; ?>>
                <?php echo e($b->branch_no); ?> - <?php echo e($b->name); ?>

              </option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
        </div>

        <div>
          <label>من تاريخ</label>
          <input type="date" name="from" value="<?php echo e($from); ?>">
        </div>

        <div>
          <label>إلى تاريخ</label>
          <input type="date" name="to" value="<?php echo e($to); ?>">
        </div>

        <div style="display:flex;gap:8px;flex-wrap:wrap;justify-content:flex-end">
          <button class="btn btnPrimary" type="submit">تطبيق</button>
          <a class="btn btnGhost" href="<?php echo e(route('dashboard.sales')); ?>">مسح</a>
        </div>
      </div>
    </form>
  </div>

  <!-- ✅ Results -->
  <div class="card">
    <div style="font-weight:900;margin-bottom:10px">النتائج</div>

    <div class="tableWrap">
      <table>
        <thead>
          <tr>
            <th>رقم الفرع</th>
            <th>اسم الفرع</th>
            <th>مبيعات اليوم</th>
            <th>مبيعات الشهر</th>
            <th>مبيعات الفترة</th>
            <th>إجمالي المبيعات</th>
          </tr>
        </thead>
        <tbody>
          <?php $__empty_1 = true; $__currentLoopData = $rows; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $r): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
              <td class="num"><?php echo e($r->branch_no); ?></td>
              <td style="font-weight:900">
                <a href="<?php echo e(route('dashboard.branch.details', ['branchId'=>$r->id, 'from'=>$from, 'to'=>$to])); ?>"
                   style="color:inherit;text-decoration:none">
                  <?php echo e($r->name); ?>

                </a>
              </td>
              <td class="num"><?php echo e(number_format((float)$r->total_today, 2)); ?></td>
              <td class="num"><?php echo e(number_format((float)$r->total_month, 2)); ?></td>
              <td class="num"><?php echo e(number_format((float)$r->total_range, 2)); ?></td>
              <td class="num"><?php echo e(number_format((float)$r->total_all, 2)); ?></td>
            </tr>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr><td colspan="6" class="empty">لا توجد بيانات</td></tr>
          <?php endif; ?>
        </tbody>
      </table>
    </div>
  </div>

</div>

<script>
(function(){
  const themes = ["light","dim","dark"];
  const key = "ui_theme";
  const html = document.documentElement;
  const btn = document.getElementById("themeBtn");

  function label(t){
    if(t === "light") return "☀️ فاتح";
    if(t === "dark") return "🌙 داكن";
    return "🌗 مريح";
  }

  function apply(t){
    html.setAttribute("data-theme", t);
    localStorage.setItem(key, t);
    if(btn) btn.textContent = "🎨 " + label(t);
  }

  const saved = localStorage.getItem(key);
  const t = (saved && themes.includes(saved)) ? saved : (html.getAttribute("data-theme") || "dim");
  apply(t);

  if(btn){
    btn.addEventListener("click", function(){
      const cur = html.getAttribute("data-theme") || "dim";
      const idx = themes.indexOf(cur);
      const next = themes[(idx + 1) % themes.length];
      apply(next);
    });
  }
})();
</script>

</body>
</html>
<?php /**PATH /home/mylaundry26/public_html/apps/billion/resources/views/dashboard_sales.blade.php ENDPATH**/ ?>