{{-- resources/views/agent/leads/partials/purchased.blade.php --}} @php use Illuminate\Support\Facades\Route; // Safe fallback if the controller didn't pass $data $purchasedData = is_array($data ?? null) ? $data : []; // Tabs we support $types = [ 'life' => 'Life', 'mortgage' => 'Mortgage Protection', 'health' => 'Health', ]; // ── Archive normalization ──────────────────────────────────────────────── // These are safe defaults; controller can pass $fromArchive and $activeGroup $fromArchive = isset($fromArchive) ? (bool) $fromArchive : false; // Normalize any requested group label $__ag = isset($activeGroup) ? strtolower(trim((string) $activeGroup)) : null; if ($__ag === 'mortgage protection' || $__ag === 'mortgage_protection' || $__ag === 'mp') { $__ag = 'mortgage'; } $activeGroup = in_array($__ag, ['life', 'mortgage', 'health'], true) ? $__ag : 'life'; // If at least one dataset exists, start there; else default to Life. // If $activeGroup is provided and valid, force that as the initial tab. $available = array_values(array_filter(array_keys($types), fn($k) => array_key_exists($k, $purchasedData))); $firstActive = $activeGroup && isset($types[$activeGroup]) ? $activeGroup : $available[0] ?? 'life'; // Unique IDs so these don't collide with the outer tabs (closures for PHP 7.3+ compat) $paneId = function ($key) { return "purchased-{$key}"; }; $tabId = function ($key) { return "purchased-{$key}-tab"; }; // Toolbar links $purchaseUrl = Route::has('agent.leads.purchase') ? route('agent.leads.purchase') : url('/agent/leads/purchase'); // Export $exportRouteName = Route::has('agent.leads.purchased.export') ? 'agent.leads.purchased.export' : (Route::has('agent.purchased.export') ? 'agent.purchased.export' : null); $exportHref = $exportRouteName ? route($exportRouteName, ['type' => $firstActive]) : null; $exportLabel = 'Export ' . ($types[$firstActive] ?? ucfirst($firstActive)) . ' (CSV)'; $exportUrls = []; if ($exportRouteName) { foreach (array_keys($types) as $k) { $exportUrls[$k] = route($exportRouteName, ['type' => $k]); } } // Bulk Update (Save) – outer form action $bulkUpdateAction = Route::has('agent.purchased.bulkUpdate') ? route('agent.purchased.bulkUpdate') : url('/agent/leads/purchased/bulk-update'); // Row-level Convert endpoint (per-row) $rowConvertBase = function ($key, $id) { return Route::has('agent.leads.purchased.convert') ? route('agent.leads.purchased.convert', ['type' => $key, 'lead' => $id]) : url("/agent/leads/purchased/{$key}/{$id}/convert"); }; // Per-group Insurance Types (Mortgage Protection removed as selectable type itself) $insuranceTypesByGroup = [ 'life' => ['Term Life', 'Whole Life', 'Final Expense', 'Universal Life', 'Other'], 'mortgage' => ['Term Life', 'Final Expense', 'Universal Life', 'Other'], 'health' => ['Dental Insurance', 'Medicare', 'ACA', 'Supplemental', 'Other'], ]; // Generic Statuses (shared across all groups) $statusOptions = [ 'new' => 'New', 'contacted' => 'Contacted', 'follow_up' => 'Follow Up', 'interested' => 'Interested', 'not_interested' => 'Not Interested', 'converted' => 'Converted', 'archived' => 'Archived', ]; $norm = fn($v) => strtolower(preg_replace('/\s+/', '_', trim((string) $v))); // Optional: when opened from an archive, controller can pass the archive file id $archiveFileId = $archiveFileId ?? ($archive_file_id ?? null); @endphp {{-- Toolbar --}}