

<?php $__env->startSection('title', 'Promotion Logs'); ?>

<?php $__env->startSection('content'); ?>
<div class="d-flex justify-content-between align-items-center mb-4">
    <h4 class="mb-0">Promotion Logs</h4>
</div>

<!-- Filters -->
<div class="card mb-4">
    <div class="card-body">
        <form action="<?php echo e(route('dashboard.promotion-logs')); ?>" method="GET" class="row g-3">
            <div class="col-md-3">
                <label class="form-label">User</label>
                <select class="form-select" name="user_id">
                    <option value="">All Users</option>
                    <?php $__currentLoopData = $users; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $user): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($user->id); ?>" <?php echo e(request('user_id') == $user->id ? 'selected' : ''); ?>>
                        <?php echo e($user->name); ?>

                    </option>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>

            <div class="col-md-2">
                <label class="form-label">Status</label>
                <select class="form-select" name="status">
                    <option value="">All</option>
                    <option value="sent" <?php echo e(request('status') == 'sent' ? 'selected' : ''); ?>>Sent</option>
                    <option value="pending" <?php echo e(request('status') == 'pending' ? 'selected' : ''); ?>>Pending</option>
                    <option value="failed" <?php echo e(request('status') == 'failed' ? 'selected' : ''); ?>>Failed</option>
                </select>
            </div>

            <div class="col-md-2">
                <label class="form-label">Trigger Type</label>
                <select class="form-select" name="trigger_type">
                    <option value="">All</option>
                    <option value="incoming" <?php echo e(request('trigger_type') == 'incoming' ? 'selected' : ''); ?>>Incoming</option>
                    <option value="outgoing" <?php echo e(request('trigger_type') == 'outgoing' ? 'selected' : ''); ?>>Outgoing</option>
                    <option value="missed" <?php echo e(request('trigger_type') == 'missed' ? 'selected' : ''); ?>>Missed</option>
                </select>
            </div>

            <div class="col-md-2">
                <label class="form-label">From Date</label>
                <input type="date" class="form-control" name="from_date" value="<?php echo e(request('from_date')); ?>">
            </div>

            <div class="col-md-2">
                <label class="form-label">To Date</label>
                <input type="date" class="form-control" name="to_date" value="<?php echo e(request('to_date')); ?>">
            </div>

            <div class="col-md-1 d-flex align-items-end">
                <button type="submit" class="btn btn-primary w-100">
                    <i class="bi bi-search"></i>
                </button>
            </div>
        </form>
    </div>
</div>

<!-- Logs Table -->
<div class="card">
    <div class="card-body">
        <?php if($promotionLogs->isEmpty()): ?>
        <div class="text-center py-5 text-muted">
            <i class="bi bi-megaphone display-4"></i>
            <p class="mt-3">No promotion logs found</p>
        </div>
        <?php else: ?>
        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>User</th>
                        <th>Phone</th>
                        <th>Message</th>
                        <th>Trigger</th>
                        <th>Template</th>
                        <th>Status</th>
                        <th>Sent At</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__currentLoopData = $promotionLogs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $log): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr>
                        <td><?php echo e($log->id); ?></td>
                        <td>
                            <?php if($log->user): ?>
                            <a href="<?php echo e(route('dashboard.user-details', $log->user_id)); ?>">
                                <?php echo e($log->user->name); ?>

                            </a>
                            <?php else: ?>
                            <span class="text-muted">N/A</span>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($log->phone_number); ?></td>
                        <td>
                            <span class="text-truncate d-inline-block" style="max-width: 200px;"
                                title="<?php echo e($log->message); ?>">
                                <?php echo e($log->message); ?>

                            </span>
                        </td>
                        <td>
                            <span class="badge bg-<?php echo e($log->trigger_type == 'missed' ? 'warning' : ($log->trigger_type == 'incoming' ? 'info' : 'success')); ?>">
                                <?php echo e(ucfirst($log->trigger_type)); ?>

                            </span>
                        </td>
                        <td>
                            <?php if($log->template): ?>
                            <?php echo e($log->template->name); ?>

                            <?php else: ?>
                            <span class="text-muted">N/A</span>
                            <?php endif; ?>
                        </td>
                        <td>
                            <?php if($log->status == 'sent'): ?>
                            <span class="badge bg-success">Sent</span>
                            <?php elseif($log->status == 'pending'): ?>
                            <span class="badge bg-warning">Pending</span>
                            <?php else: ?>
                            <span class="badge bg-danger" title="<?php echo e($log->error_message); ?>">Failed</span>
                            <?php endif; ?>
                        </td>
                        <td><?php echo e($log->sent_at?->format('M d, Y H:i') ?? '-'); ?></td>
                    </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody>
            </table>
        </div>

        <div class="d-flex justify-content-center mt-4">
            <?php echo e($promotionLogs->appends(request()->query())->links()); ?>

        </div>
        <?php endif; ?>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.dashboard', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\xampp82\htdocs\AutoPromix\backend\resources\views\dashboard\promotion-logs.blade.php ENDPATH**/ ?>