
<?php
$avColors = ['#1a73e8','#8b5cf6','#10b981','#f59e0b','#ef4444','#0ea5e9','#f97316','#ec4899'];
$col = $avColors[$lead->id % count($avColors)];
$allStages = ['New','Contacted','Positive','Follow Up','Negotiation','Won','Lost'];
$tlColors = ['Phone Call'=>'#1e40af','WhatsApp'=>'#10b981','Email'=>'#5b21b6','Meeting'=>'#059669','Note'=>'#687182','Walk-in'=>'#f59e0b'];
?>

<div class="dr-hd">
  <div class="dr-av" style="background:<?php echo e($col); ?>22;color:<?php echo e($col); ?>"><?php echo e($lead->initials); ?></div>
  <div>
    <div class="dr-name"><?php echo e($lead->name); ?></div>
    <div class="dr-sub">
      <?php echo e($lead->company ?? '--'); ?> &middot;
      <span class="badge <?php echo e(\App\Models\Lead::stageBadge($lead->stage)); ?>"><?php echo e($lead->stage); ?></span> &middot;
      <strong><?php echo e($lead->budget_formatted); ?></strong>
    </div>
  </div>
  <button class="dr-close" onclick="closeDrawer()">
    <svg viewBox="0 0 24 24"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
  </button>
</div>

<div class="dr-tabs">
  <button class="dtab active" onclick="drawerTab(this,'tab-overview')">Overview</button>
  <button class="dtab" onclick="drawerTab(this,'tab-notes')">Notes &amp; Activity</button>
  <button class="dtab" onclick="drawerTab(this,'tab-timeline')">Timeline</button>
</div>

<div class="dr-body">

  
  <div id="tab-overview">
    <div class="ig">
      <?php $__currentLoopData = [
        ['Phone', $lead->phone],
        ['Email', $lead->email ?? '--'],
        ['Company', $lead->company ?? '--'],
        ['Source', $lead->source],
        ['Service', $lead->service ?? '--'],
        ['Budget', $lead->budget_formatted],
        ['Priority', $lead->priority],
        ['Last Contact', optional($lead->last_contact)->format('d M Y') ?? '--'],
      ]; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as [$lbl, $val]): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
      <div class="ig-cell">
        <div class="lbl"><?php echo e($lbl); ?></div>
        <div class="val"><?php echo e($val); ?></div>
      </div>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <div class="qa-row">
      <?php $__currentLoopData = ['WhatsApp','Phone Call','Email','Meeting']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $via): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
      <form method="POST" action="<?php echo e(route('notes.store', $lead)); ?>" style="display:contents">
        <?php echo csrf_field(); ?>
        <input type="hidden" name="via" value="<?php echo e($via); ?>">
        <input type="hidden" name="note" value="<?php echo e($via); ?> initiated with <?php echo e($lead->name); ?>.">
        <button type="submit" class="qa <?php echo e($via=='WhatsApp'?'qa-wa':''); ?>">
          <?php echo e($via=='WhatsApp'?'📱':($via=='Phone Call'?'📞':($via=='Email'?'📧':'📅'))); ?> <?php echo e($via); ?>

        </button>
      </form>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
      <a href="<?php echo e(route('leads.edit', $lead)); ?>" class="qa qa-pri">✏ Edit Lead</a>
    </div>

    <div class="upd-grid">
      <div class="fld">
        <label>Change Status</label>
        <form method="POST" action="<?php echo e(route('leads.stage', $lead)); ?>" id="drawer-stage-form">
          <?php echo csrf_field(); ?>
          <select name="stage" class="ssel <?php echo e(\App\Models\Lead::stageSelectClass($lead->stage)); ?>" onchange="document.getElementById('drawer-stage-form').submit()" style="width:100%;max-width:100%">
            <?php $__currentLoopData = $allStages; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $s): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option <?php echo e($lead->stage===$s?'selected':''); ?>><?php echo e($s); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
        </form>
      </div>
      <div class="fld">
        <label>Assign To</label>
        <form method="POST" action="<?php echo e(route('leads.assign', $lead)); ?>" id="drawer-assign-form">
          <?php echo csrf_field(); ?>
          <select name="assigned_to" class="asel" onchange="document.getElementById('drawer-assign-form').submit()" style="width:100%;max-width:100%">
            <?php $__currentLoopData = $employees; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $e): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($e->id); ?>" <?php echo e($lead->assigned_to===$e->id?'selected':''); ?>><?php echo e($e->name); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
        </form>
      </div>
    </div>

    <div style="display:flex;gap:7px;flex-wrap:wrap">
      <form method="POST" action="<?php echo e(route('leads.stage', $lead)); ?>">
        <?php echo csrf_field(); ?><input type="hidden" name="stage" value="Won">
        <button type="submit" class="qa qa-won">✓ Mark Won</button>
      </form>
      <form method="POST" action="<?php echo e(route('leads.stage', $lead)); ?>">
        <?php echo csrf_field(); ?><input type="hidden" name="stage" value="Lost">
        <button type="submit" class="qa qa-lost">✕ Mark Lost</button>
      </form>
      <form method="POST" action="<?php echo e(route('leads.destroy', $lead)); ?>" onsubmit="return confirm('Delete this lead?')" style="margin-left:auto">
        <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
        <button type="submit" class="qa qa-del">🗑 Delete</button>
      </form>
    </div>
  </div>

  
  <div id="tab-notes" style="display:none">
    <?php $__empty_1 = true; $__currentLoopData = $lead->notes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $note): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
    <div class="note-item">
      <div class="note-hd">
        <div class="note-av" style="background:<?php echo e($note->avatar_color); ?>"><?php echo e($note->initials); ?></div>
        <span class="note-by"><?php echo e($note->added_by); ?></span>
        <span class="badge <?php echo e(\App\Models\LeadNote::viaBadge($note->via)); ?>" style="margin-left:4px;font-size:9.5px"><?php echo e($note->via); ?></span>
        <span class="note-time"><?php echo e($note->created_at->format('d M Y, g:i A')); ?></span>
      </div>
      <div class="note-text"><?php echo e($note->note); ?></div>
    </div>
    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
    <div style="color:#9aa5b4;font-size:13px;padding:8px 0 12px">No notes yet. Add the first one below.</div>
    <?php endif; ?>

    <div class="note-add">
      <h5>Add New Note</h5>
      <form method="POST" action="<?php echo e(route('notes.store', $lead)); ?>">
        <?php echo csrf_field(); ?>
        <select name="via">
          <?php $__currentLoopData = ['Phone Call','WhatsApp','Email','Meeting','Walk-in','Note']; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $v): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
          <option><?php echo e($v); ?></option>
          <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
        </select>
        <textarea name="note" placeholder="What happened? What was discussed? What is the next step?"></textarea>
        <button type="submit" class="btn btn-pri btn-sm">
          <svg viewBox="0 0 24 24"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>Add Note
        </button>
      </form>
    </div>
  </div>

  
  <div id="tab-timeline" style="display:none">
    <div class="tl-wrap">
      <div class="tl-item">
        <div class="tl-dot" style="background:#1a73e8;box-shadow:0 0 0 1.5px #1a73e8"></div>
        <div class="tl-card">
          <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:3px">
            <span class="tl-title">Lead Created</span>
            <span class="tl-time"><?php echo e($lead->created_at->format('d M Y, g:i A')); ?></span>
          </div>
          <div class="tl-desc"><?php echo e($lead->source); ?> enquiry assigned to <?php echo e($lead->employee->name ?? '--'); ?></div>
        </div>
      </div>
      <?php $__currentLoopData = $lead->notes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $note): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
      <?php $tlCol = $tlColors[$note->via] ?? '#687182'; ?>
      <div class="tl-item">
        <div class="tl-dot" style="background:<?php echo e($tlCol); ?>;box-shadow:0 0 0 1.5px <?php echo e($tlCol); ?>"></div>
        <div class="tl-card">
          <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:3px">
            <span class="tl-title"><?php echo e($note->via); ?> – <?php echo e($note->added_by); ?></span>
            <span class="tl-time"><?php echo e($note->created_at->format('d M Y, g:i A')); ?></span>
          </div>
          <div class="tl-desc"><?php echo e($note->note); ?></div>
        </div>
      </div>
      <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>
  </div>

</div><?php /**PATH C:\xampp\htdocs\leads-worksheet\resources\views/leads/show-drawer.blade.php ENDPATH**/ ?>