

<?php $__env->startSection('title', ($lead->displayFairName() ?: 'Lead') . ' — Detail'); ?>

<?php $__env->startSection('content'); ?>
    <div class="portal-page-header d-flex justify-content-between align-items-start flex-wrap gap-2">
        <div>
            <h1 class="h4 mb-0"><?php echo e($lead->displayFairName() ?: 'Lead'); ?></h1>
            <p class="subtitle mb-0"><?php echo e($lead->company_name ?: 'No company name'); ?></p>
            <?php if($lead->assignedTo): ?>
                <p class="small text-muted mb-0 mt-1">
                    Marketing: <strong><?php echo e($lead->assignedTo->name); ?></strong>
                    <?php if($lead->assigned_at): ?> · <?php echo e($lead->assigned_at->format('M d, Y')); ?> <?php endif; ?>
                </p>
            <?php endif; ?>
            <?php if($lead->designAssignedTo): ?>
                <p class="small text-muted mb-0 mt-1">
                    Design: <strong><?php echo e($lead->designAssignedTo->name); ?></strong>
                    <?php echo $__env->make('partials.design-task-status-badge', ['status' => $lead->clean_design_task_status], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
                    <?php if($lead->design_due_date): ?>
                        · Due <?php echo e($lead->design_due_date->format('M d, Y')); ?>

                        <?php if($lead->isDesignOverdue()): ?> <span class="text-danger fw-semibold">(overdue)</span> <?php endif; ?>
                    <?php endif; ?>
                </p>
            <?php endif; ?>
        </div>
        <div class="portal-actions">
            <?php if(can_edit_lead($lead)): ?>
                <a href="<?php echo e(route('leads.edit', $lead)); ?>" class="btn btn-portal-primary">Edit lead</a>
            <?php endif; ?>
            <?php if(can_access_module('leads.listing')): ?>
                <a href="<?php echo e(route('leads.listing')); ?>" class="btn btn-portal-outline">Back to listing</a>
            <?php elseif(can_access_module('leads.my_tasks')): ?>
                <a href="<?php echo e(route('leads.my-tasks')); ?>" class="btn btn-portal-outline">Back to my tasks</a>
            <?php elseif(can_access_module('leads.design_tasks')): ?>
                <a href="<?php echo e(route('leads.design-tasks')); ?>" class="btn btn-portal-outline">Back to design tasks</a>
            <?php endif; ?>
        </div>
    </div>

    <div class="row g-4">
        <div class="col-lg-4">
            <div class="portal-card mb-4">
                <div class="card-header">Lead information</div>
                <div class="card-body">
                    <div class="portal-detail-grid">
                        <div class="portal-detail-item">
                            <div class="label">Fair name</div>
                            <div class="value"><?php echo e($lead->displayFairName() ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Company</div>
                            <div class="value"><?php echo e($lead->company_name ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Contact person</div>
                            <div class="value"><?php echo e($lead->contact_person_name ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Venue</div>
                            <div class="value"><?php echo e($lead->displayVenue()); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Country</div>
                            <div class="value"><?php echo e(optional(optional($lead->tradefair)->fairCountry)->name ?: $lead->country ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Fair start</div>
                            <div class="value"><?php echo e(optional($lead->effectiveFairStartDate())->format('M d, Y') ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Fair end</div>
                            <div class="value"><?php echo e(optional($lead->effectiveFairEndDate())->format('M d, Y') ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Source location</div>
                            <div class="value"><?php echo e($lead->source_location ?: '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Budget</div>
                            <div class="value"><?php echo e($lead->lead_budget !== null ? number_format($lead->lead_budget, 2) : '—'); ?></div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Booth area</div>
                            <div class="value">
                                <?php if($lead->booth_area_sqm !== null): ?>
                                    <?php echo e(number_format($lead->booth_area_sqm, 2)); ?> sqm
                                <?php else: ?>
                                    —
                                <?php endif; ?>
                                <?php if($lead->booth_area_sqft !== null): ?>
                                    <span class="text-muted"> / <?php echo e(number_format($lead->booth_area_sqft, 2)); ?> sqft</span>
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Email</div>
                            <div class="value">
                                <?php if($lead->email_id): ?>
                                    <a href="mailto:<?php echo e($lead->email_id); ?>"><?php echo e($lead->email_id); ?></a>
                                <?php else: ?>
                                    —
                                <?php endif; ?>
                            </div>
                        </div>
                        <div class="portal-detail-item">
                            <div class="label">Phone</div>
                            <div class="value">
                                <?php echo e($lead->phone_number ?: '—'); ?>

                                <?php if($lead->phone_number): ?>
                                    <div class="portal-actions mt-2">
                                        <a class="btn btn-sm btn-portal-outline" href="tel:<?php echo e($lead->phone_number); ?>">Call</a>
                                        <?php if($lead->whatsappPhoneNumber()): ?>
                                            <a class="btn btn-sm btn-portal-outline" target="_blank" rel="noopener" href="https://wa.me/<?php echo e($lead->whatsappPhoneNumber()); ?>">WhatsApp</a>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                            </div>
                        </div>
                    </div>

                    <?php if($lead->description): ?>
                        <div class="mt-3 pt-3 border-top">
                            <div class="portal-section-title">Description</div>
                            <p class="mb-0 small"><?php echo e($lead->description); ?></p>
                        </div>
                    <?php endif; ?>

                    <div class="mt-3 pt-3 border-top">
                        <?php if(can_access_module('leads.status')): ?>
                            <form method="POST" action="<?php echo e(route('leads.status.update', $lead)); ?>" class="row g-2">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('PATCH'); ?>
                                <div class="col-12">
                                    <label class="form-label small fw-semibold">Lead status</label>
                                    <select name="lead_status" class="form-select form-select-sm">
                                        <?php $__currentLoopData = $statuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $status): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                            <option value="<?php echo e($status); ?>" <?php echo e($lead->clean_lead_status === $status ? 'selected' : ''); ?>><?php echo e($status); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                                <div class="col-12">
                                    <button class="btn btn-portal-primary btn-sm w-100">Update status</button>
                                </div>
                            </form>
                        <?php else: ?>
                            <div class="label">Status</div>
                            <div class="mt-1"><?php echo $__env->make('partials.lead-status-badge', ['status' => $lead->clean_lead_status], \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?></div>
                        <?php endif; ?>
                    </div>
                </div>
            </div>

            <?php if($lead->designAssignedTo && $lead->designRemarks->isNotEmpty()): ?>
            <div class="portal-card mb-4">
                <div class="card-header">Design tracking remarks</div>
                <div class="card-body">
                    <?php $__currentLoopData = $lead->designRemarks->take(5); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $remark): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <div class="border rounded p-2 mb-2" style="border-color: var(--portal-border) !important;">
                            <div class="small text-muted">
                                <?php echo e(optional($remark->user)->name); ?> · <?php echo e(optional($remark->created_at)->format('M d, Y H:i')); ?>

                            </div>
                            <div class="small"><?php echo e($remark->remark); ?></div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    <a href="<?php echo e(route('leads.design-tasks')); ?>" class="small">View on design tracking →</a>
                </div>
            </div>
            <?php endif; ?>

            <?php if(can_access_module('leads.remarks')): ?>
            <div class="portal-card mb-4">
                <div class="card-header">Remarks</div>
                <div class="card-body">
                    <form method="POST" action="<?php echo e(route('leads.remarks.store', $lead)); ?>" class="mb-3">
                        <?php echo csrf_field(); ?>
                        <textarea name="remark" class="form-control form-control-sm" rows="3" required placeholder="Add client discussion notes..."></textarea>
                        <button class="btn btn-portal-primary btn-sm mt-2">Save remark</button>
                    </form>
                    <?php $__empty_1 = true; $__currentLoopData = $lead->remarks; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $remark): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <div class="border rounded p-2 mb-2" style="border-color: var(--portal-border) !important;">
                            <div class="small text-muted">
                                <?php echo e(optional($remark->user)->name ?: 'Unknown'); ?> · <?php echo e(optional($remark->created_at)->format('M d, Y H:i')); ?>

                            </div>
                            <div class="small"><?php echo e($remark->remark); ?></div>
                        </div>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <p class="text-muted small mb-0">No remarks yet.</p>
                    <?php endif; ?>
                </div>
            </div>
            <?php endif; ?>

            <?php if(can_manage_vendor_quotes($lead)): ?>
            <div class="portal-card mb-4">
                <div class="card-header">Add vendor quote</div>
                <div class="card-body">
                    <form method="POST" action="<?php echo e(route('vendor-quotes.store', $lead)); ?>" class="row g-2">
                        <?php echo csrf_field(); ?>
                        <div class="col-12">
                            <label class="form-label small">Vendor name</label>
                            <input name="vendor_name" class="form-control form-control-sm" required>
                        </div>
                        <div class="col-12">
                            <label class="form-label small">Raw cost</label>
                            <input type="number" step="0.01" name="vendor_raw_cost" class="form-control form-control-sm" required>
                        </div>
                        <div class="col-12">
                            <label class="form-label small">Markup %</label>
                            <input type="number" step="0.01" name="our_markup_percent" class="form-control form-control-sm" required>
                        </div>
                        <div class="col-12 form-check ms-1">
                            <input class="form-check-input" type="checkbox" value="1" name="selection_toggle" id="selected-new">
                            <label class="form-check-label small" for="selected-new">Select as chosen vendor</label>
                        </div>
                        <div class="col-12">
                            <button class="btn btn-portal-primary btn-sm w-100">Add quote</button>
                        </div>
                    </form>
                </div>
            </div>
            <?php endif; ?>

            <?php if(auth()->user()->isPlatformAdmin()): ?>
            <div class="portal-card">
                <div class="card-header">View tracking</div>
                <div class="portal-table-wrap">
                    <table class="table portal-table table-sm mb-0">
                        <thead>
                        <tr>
                            <th>User</th>
                            <th>Opens</th>
                            <th>Last</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $lead->leadViews; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $view): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <tr>
                                <td><?php echo e(optional($view->user)->name ?: '—'); ?></td>
                                <td><?php echo e($view->view_count); ?></td>
                                <td><?php echo e(optional($view->last_viewed_at)->format('M d, H:i') ?: '—'); ?></td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr><td colspan="3" class="text-center text-muted py-3 small">No views yet.</td></tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>
            <?php endif; ?>
        </div>

        <div class="col-lg-8">
            <div class="portal-card">
                <div class="card-header">Vendor comparison</div>
                <div class="portal-table-wrap">
                    <table class="table portal-table mb-0">
                        <thead>
                        <tr>
                            <th>Vendor</th>
                            <th>Raw cost</th>
                            <th>Markup %</th>
                            <th>Client price</th>
                            <th>Profit</th>
                            <th>Selected</th>
                            <?php if(can_manage_vendor_quotes($lead)): ?>
                                <th></th>
                            <?php endif; ?>
                        </tr>
                        </thead>
                        <tbody>
                        <?php $__empty_1 = true; $__currentLoopData = $lead->vendorQuotes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $quote): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                            <?php
                                $final = $quote->client_final_price;
                                $profit = $final - $quote->vendor_raw_cost;
                            ?>
                            <tr>
                                <?php if(can_manage_vendor_quotes($lead)): ?>
                                    <form method="POST" action="<?php echo e(route('vendor-quotes.update', [$lead, $quote])); ?>">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('PATCH'); ?>
                                        <td><input name="vendor_name" value="<?php echo e($quote->vendor_name); ?>" class="form-control form-control-sm" required></td>
                                        <td><input type="number" step="0.01" name="vendor_raw_cost" value="<?php echo e($quote->vendor_raw_cost); ?>" class="form-control form-control-sm" required></td>
                                        <td><input type="number" step="0.01" name="our_markup_percent" value="<?php echo e($quote->our_markup_percent); ?>" class="form-control form-control-sm" required></td>
                                        <td><strong><?php echo e(number_format($final, 2)); ?></strong></td>
                                        <td><?php echo e(number_format($profit, 2)); ?></td>
                                        <td class="text-center">
                                            <input type="checkbox" name="selection_toggle" value="1" <?php echo e($quote->selection_toggle ? 'checked' : ''); ?>>
                                        </td>
                                        <td><button class="btn btn-portal-primary btn-sm">Save</button></td>
                                    </form>
                                <?php else: ?>
                                    <td><?php echo e($quote->vendor_name); ?></td>
                                    <td><?php echo e(number_format($quote->vendor_raw_cost, 2)); ?></td>
                                    <td><?php echo e(number_format($quote->our_markup_percent, 2)); ?></td>
                                    <td><strong><?php echo e(number_format($final, 2)); ?></strong></td>
                                    <td><?php echo e(number_format($profit, 2)); ?></td>
                                    <td><?php echo e($quote->selection_toggle ? 'Yes' : 'No'); ?></td>
                                <?php endif; ?>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                            <tr><td colspan="7"><div class="portal-empty">Add vendor quotes to start comparison.</div></td></tr>
                        <?php endif; ?>
                        </tbody>
                    </table>
                </div>
            </div>

            <div class="alert border-0 mt-4 mb-0 rounded-3" style="background: var(--portal-primary-soft); color: var(--portal-primary);">
                <strong>Workflow:</strong> Costing → add 3 vendor quotes → compare prices → select vendor → set status to <strong>Won/Ongoing</strong>.
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\lt\resources\views/leads/show.blade.php ENDPATH**/ ?>