<style>
  .badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    border-radius: 999px;
    background: #ef4444;
    color: #fff
  }

  /* .btn-ghost{background:transparent;border:none}
    .container{max-width:900px;margin:0 auto;padding:20px} */
</style>
<header class="m-header">
  <div class="hdr-top " style="display: none;">
    <button class="btn-ghost" id="openSidebar" aria-label="Menu"><i class="ri-menu-line"></i></button>
    <div class="logo"><img src="http://rkmotorsbike.top/storage/settings/3jfAezSCma5vK6oTjBY7E8fgymdjuaSShroybDPk.jpg"
        alt="logo"><span>Wallet</span></div>
    <div class="hdr-actions">

      <button class="btn-ghost" aria-label="Notifications"><i class="ri-notification-3-line"></i></button>


      <form id="logout-form" action="<?php echo e(route('logout')); ?>" method="POST" style="display: inline;">
        <?php echo csrf_field(); ?>
        <button class="btn-ghost" aria-label="Scan"
          onclick="event.preventDefault(); document.getElementById('logout-form').submit();"><i
            class="ri-logout-circle-line"></i></button>
      </form>
    </div>
  </div>
  <?php
    $companySetup = \App\Models\CompanySetup::first();
  ?>
   
 

  <div class="user-row">
    <div class="avatar"><img style="width: 100%;
    height: 100%;" src="<?php echo e(asset('storage/'.$companySetup->logo)); ?>" alt="User">
    </div>
    <div style="display: flex
;
    justify-content: center;
    align-items: center;
    flex-direction: column;position: relative;
    left: 36px;">
      <div class="title" style="font-size: 17px!important;"><?php echo e(auth()->user()->name ?? 'Test User'); ?></div>
      <div class="phone" style="font-size: 16px!important;"><?php echo e(auth()->user()->phone ?? 'Test User'); ?></div>
      <div class="meta"><i class="ri-map-pin-2-fill"></i>Bangladesh</div>
    </div>
    <div style="margin-left: 69px;position:relative">
      
      <a href="<?php echo e(route('notices.index')); ?>" id="" style="" class="btn-ghost">
        <i class="ri-notification-3-line" style="font-size:22px"></i>
        <span id="notice-count" class="badge">0</span>
      </a>


    </div>
    
  </div>


  <?php $balance = number_format((auth()->user()->balance ?? 0), 2); ?>

  <div class="balance-wrap" style="display:flex;justify-content:center;align-items:center;">
    <div class="balance-pill" id="balancePill" style="width:240px;">
      <div class="knob"><i class="ri-hand-coin-line"></i></div>
      <div class="balance-text" id="balanceText" data-balance="<?php echo e($balance); ?>">Check Balance</div>
      
    </div>
  </div>
</header>


<script>
  const CSRF = '<?php echo e(csrf_token()); ?>';
  const elCount = document.getElementById('notice-count');
  const elBtn = document.getElementById('noticeBtn');
  const elPanel = document.getElementById('noticePanel');
  const elList = document.getElementById('noticeList');
  const elClose = document.getElementById('closeNotice');

  // unread count = মোট unread
  async function refreshUnreadCount() {
    try {
      const r = await fetch(`<?php echo e(url('/notices/unread-count')); ?>`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
      const j = await r.json(); elCount.textContent = j.count;
    } catch (e) { }
  }

  // list render
  function renderList(items) {
    if (!items.length) {
      elList.innerHTML = `<p style="color:#6b7280">No notices.</p>`;
      return;
    }
    elList.innerHTML = items.map(it => `
      <article style="border:1px solid #eee;border-radius:10px;padding:12px;margin-bottom:10px; ${it.is_read ? 'background:#fff' : 'background:#fff7da'}">
        <div style="display:flex;justify-content:space-between;gap:12px">
          <div>
            <div style="font-weight:600;margin-bottom:4px">${it.title}</div>
            <div style="color:#6b7280;font-size:12px">${it.time}</div>
          </div>
        </div>
        ${it.body ? `<p style="margin-top:8px;white-space:pre-line">${it.body}</p>` : ``}
      </article>
    `).join('');
  }

  // প্যানেল ওপেন => লিস্ট ফেচ + সাথে সাথে auto read (count কমে যাবে)
  async function openPanel() {
    elPanel.style.display = 'block';
    // Load list
    try {
      const res = await fetch(`<?php echo e(route('notices.list')); ?>`, { headers: { 'X-Requested-With': 'XMLHttpRequest' } });
      const data = await res.json(); renderList(data.items);
    } catch (e) { elList.innerHTML = `<p style="color:#ef4444">Failed to load.</p>`; }

    // AUTO READ (পেজ রিলোড ছাড়া)
    try {
      const res2 = await fetch(`<?php echo e(route('notices.readAll')); ?>`, {
        method: 'POST',
        headers: { 'X-CSRF-TOKEN': CSRF, 'X-Requested-With': 'XMLHttpRequest' }
      });
      const j2 = await res2.json();
      if (j2.ok) { elCount.textContent = j2.count; }
    } catch (e) { }
  }

  function closePanel() { elPanel.style.display = 'none'; }

  elBtn.addEventListener('click', (e) => {
    e.preventDefault();
    if (elPanel.style.display === 'block') { closePanel(); } else { openPanel(); }
  });
  elClose.addEventListener('click', closePanel);
  document.addEventListener('click', (e) => {
    if (!elPanel.contains(e.target) && !elBtn.contains(e.target)) closePanel();
  });

  // প্রথম লোড + ইন্টারভালে unread count আপডেট (নতুন নোটিস এলে ব্যাজ বাড়বে)
  refreshUnreadCount();
  setInterval(refreshUnreadCount, 10000);
</script><?php /**PATH C:\xampp\htdocs\new-development-re-banking\re_banking_2\resources\views/frontend/common/header.blade.php ENDPATH**/ ?>