<?php $__env->startSection('title', $viewAll ? 'Design tracking' : 'My design tasks'); ?>
<?php $__env->startSection('page_title', $viewAll ? 'Design tracking' : 'My design tasks'); ?>

<?php $__env->startSection('content'); ?>
    <div class="portal-page-header">
        <p class="subtitle mb-0">
            <?php if($viewAll): ?>
                All design assignments in one place — track designer, status, due dates, and remarks.
            <?php else: ?>
                Your assigned design work — update status, due date, and add tracking remarks.
            <?php endif; ?>
        </p>
    </div>

    <div class="row g-3 mb-4">
        <div class="col-6 col-md">
            <div class="portal-stat" style="--stat-accent: #4f46e5;">
                <div class="portal-stat-value"><?php echo e($stats['total']); ?></div>
                <div class="portal-stat-label">Total tasks</div>
            </div>
        </div>
        <div class="col-6 col-md">
            <div class="portal-stat" style="--stat-accent: #f59e0b;">
                <div class="portal-stat-value"><?php echo e($stats['in_progress']); ?></div>
                <div class="portal-stat-label">In progress</div>
            </div>
        </div>
        <div class="col-6 col-md">
            <div class="portal-stat" style="--stat-accent: #ef4444;">
                <div class="portal-stat-value"><?php echo e($stats['overdue']); ?></div>
                <div class="portal-stat-label">Overdue</div>
            </div>
        </div>
        <div class="col-6 col-md">
            <div class="portal-stat" style="--stat-accent: #10b981;">
                <div class="portal-stat-value"><?php echo e($stats['completed']); ?></div>
                <div class="portal-stat-label">Completed</div>
            </div>
        </div>
    </div>

    <div class="portal-card">
        <div class="portal-table-wrap">
            <table class="table portal-table mb-0 align-middle">
                <thead>
                <tr>
                    <th>Fair / Lead</th>
                    <?php if($viewAll): ?><th>Designer</th><?php endif; ?>
                    <th>Marketing</th>
                    <th>Assigned</th>
                    <th>Due date</th>
                    <th>Status</th>
                    <th>Latest remark</th>
                    <th class="text-end">Actions</th>
                </tr>
                </thead>
                <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $leads; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $lead): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                    <tr class="<?php echo e($lead->isDesignOverdue() ? 'table-warning' : ''); ?>">
                        <td>
                            <a href="<?php echo e(route('leads.show', $lead)); ?>" class="lead-link fw-semibold"><?php echo e($lead->displayFairName() ?: 'Lead #' . $lead->id); ?></a>
                            <?php if($lead->company_name): ?>
                                <div class="small text-muted"><?php echo e($lead->company_name); ?></div>
                            <?php endif; ?>
                        </td>
                        <?php if($viewAll): ?>
                            <td><?php echo e(optional($lead->designAssignedTo)->name ?: '—'); ?></td>
                        <?php endif; ?>
                        <td class="small"><?php echo e(optional($lead->assignedTo)->name ?: '—'); ?></td>
                        <td class="small text-nowrap"><?php echo e(optional($lead->design_assigned_at)->format('M d, Y') ?: '—'); ?></td>
                        <td class="text-nowrap">
                            <?php if($lead->design_due_date): ?>
                                <span class="<?php echo e($lead->isDesignOverdue() ? 'text-danger fw-semibold' : ''); ?>">
                                    <?php echo e($lead->design_due_date->format('M d, Y')); ?>

                                </span>
                            <?php else: ?>
                                <span class="text-muted">Not set</span>
                            <?php endif; ?>
                        </td>
                        <td><?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(); ?></td>
                        <td class="small" style="max-width: 200px;">
                            <?php $dr = $lead->designRemarks->first(); ?>
                            <?php if($dr): ?>
                                <span class="text-muted"><?php echo e(optional($dr->user)->name); ?>:</span>
                                <?php echo e(\Illuminate\Support\Str::limit($dr->remark, 60)); ?>

                            <?php else: ?>
                                <span class="text-muted">—</span>
                            <?php endif; ?>
                        </td>
                        <td class="text-end">
                            <button type="button"
                                    class="btn btn-portal-outline btn-sm btn-update-design-task"
                                    data-bs-toggle="modal"
                                    data-bs-target="#updateDesignTaskModal"
                                    data-lead-id="<?php echo e($lead->id); ?>"
                                    data-lead-name="<?php echo e($lead->displayFairName() ?: 'Lead #' . $lead->id); ?>"
                                    data-status="<?php echo e($lead->clean_design_task_status); ?>"
                                    data-due="<?php echo e(optional($lead->design_due_date)->format('Y-m-d')); ?>">
                                Update
                            </button>
                            <a href="<?php echo e(route('leads.show', $lead)); ?>" class="btn btn-portal-primary btn-sm">View</a>
                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                    <tr>
                        <td colspan="<?php echo e($viewAll ? 8 : 7); ?>">
                            <div class="portal-empty py-4">No design tasks assigned yet.</div>
                        </td>
                    </tr>
                <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>

    <div class="modal fade" id="updateDesignTaskModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content border-0 shadow">
                <form method="POST" id="updateDesignTaskForm" action="">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PATCH'); ?>
                    <div class="modal-header border-0 pb-0">
                        <h5 class="modal-title fw-bold">Update design task</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                    </div>
                    <div class="modal-body">
                        <p class="text-muted small mb-3">Lead: <strong id="updateDesignLeadName">—</strong></p>
                        <div class="mb-3">
                            <label class="form-label fw-semibold small">Status</label>
                            <select name="design_task_status" id="updateDesignStatus" class="form-select" required>
                                <?php $__currentLoopData = $designStatuses; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $st): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <option value="<?php echo e($st); ?>"><?php echo e($st); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </div>
                        <div class="mb-3">
                            <label class="form-label fw-semibold small">Due date</label>
                            <input type="date" name="design_due_date" id="updateDesignDue" class="form-control">
                        </div>
                        <div class="mb-0">
                            <label class="form-label fw-semibold small">Tracking remark</label>
                            <textarea name="design_remark" class="form-control" rows="3" placeholder="Progress update, blocker, handoff notes…"></textarea>
                        </div>
                    </div>
                    <div class="modal-footer border-0 pt-0">
                        <button type="button" class="btn btn-portal-outline" data-bs-dismiss="modal">Cancel</button>
                        <button type="submit" class="btn btn-portal-primary">Save</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
<script>
(function () {
    var form = document.getElementById('updateDesignTaskForm');
    var base = <?php echo json_encode(url('/leads'), 15, 512) ?>;
    document.querySelectorAll('.btn-update-design-task').forEach(function (btn) {
        btn.addEventListener('click', function () {
            if (form) form.action = base + '/' + btn.getAttribute('data-lead-id') + '/design-task';
            var nameEl = document.getElementById('updateDesignLeadName');
            if (nameEl) nameEl.textContent = btn.getAttribute('data-lead-name') || '';
            var statusEl = document.getElementById('updateDesignStatus');
            if (statusEl) statusEl.value = btn.getAttribute('data-status') || 'Pending';
            var dueEl = document.getElementById('updateDesignDue');
            if (dueEl) dueEl.value = btn.getAttribute('data-due') || '';
        });
    });
})();
</script>
<?php $__env->stopPush(); ?>

<?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/design-tasks.blade.php ENDPATH**/ ?>