
<?php $__env->startSection('title', 'Send Promotion'); ?>
<?php $__env->startSection('content'); ?>
<?php $clients = \App\Models\User::where('role', \App\Enums\UserRole::User)->orderBy('name')->get(); ?>

<div class="page-header"><h1>Send Promotional Email</h1><p>Broadcast updates to verified clients</p></div>

<div class="md-card" style="margin-bottom:1.5rem">
    <div class="md-card-body">
        <form method="POST" action="<?php echo e(route('admin.promotions.store')); ?>">
            <?php echo csrf_field(); ?>
            <div class="form-field">
                <label>Select Recipients</label>
                <select name="recipient_type" class="md-select" id="recipientType">
                    <option value="all_verified">All Verified Users</option>
                    <option value="selected_users">Selected Users</option>
                </select>
            </div>
            <div class="form-field" id="userPicker" style="display:none">
                <label>Users</label>
                <select name="recipient_ids[]" class="md-select" multiple size="6">
                    <?php $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $c): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?><option value="<?php echo e($c->id); ?>"><?php echo e($c->name); ?> (<?php echo e($c->email); ?>)</option><?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </select>
            </div>
            <div class="form-field"><label>Subject</label><input name="subject" class="md-input" required></div>
            <div class="form-field"><label>Message</label><textarea name="body" class="md-textarea" placeholder="Hello {name}..." required></textarea></div>
            <button type="submit" class="md-btn md-btn-filled">Send Promotion</button>
        </form>
    </div>
</div>

<div class="md-card">
    <div class="md-card-header">Promotion History</div>
    <div class="table-wrap">
        <table class="md-table">
            <thead><tr><th>Subject</th><th>Sent To</th><th>Sent At</th><th>Action</th></tr></thead>
            <tbody>
                <?php $__empty_1 = true; $__currentLoopData = $promotions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $p): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                <tr>
                    <td><?php echo e($p->subject); ?></td>
                    <td><?php echo e(str_replace('_', ' ', ucfirst($p->recipient_type))); ?></td>
                    <td><?php echo e($p->sent_at?->format('Y-m-d H:i:s')); ?></td>
                    <td>
                        <form method="POST" action="<?php echo e(route('admin.promotions.resend', $p)); ?>"><?php echo csrf_field(); ?>
                            <button class="md-btn md-btn-tonal md-btn-sm">Resend</button>
                        </form>
                    </td>
                </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                <tr><td colspan="4" style="text-align:center;padding:2rem">No promotions sent yet</td></tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__env->startPush('scripts'); ?>
<script>
document.getElementById('recipientType')?.addEventListener('change', function() {
    document.getElementById('userPicker').style.display = this.value === 'selected_users' ? 'block' : 'none';
});
</script>
<?php $__env->stopPush(); ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH D:\SkyApps\Projects\web3derp\resources\views/admin/promotions/index.blade.php ENDPATH**/ ?>