

<?php $__env->startSection('title', 'Message Templates'); ?>
<?php $__env->startSection('page-title', 'Message Templates'); ?>

<?php $__env->startSection('content'); ?>
<div class="table-container">
    <!-- Filters -->
    <form action="<?php echo e(route('dashboard.templates')); ?>" method="GET" class="row g-3 mb-4">
        <div class="col-md-3">
            <select name="client_id" class="form-select">
                <option value="">All Organizations</option>
                <?php $__currentLoopData = $clients; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $client): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                <option value="<?php echo e($client->id); ?>" <?php echo e(request('client_id') == $client->id ? 'selected' : ''); ?>>
                    <?php echo e($client->name); ?>

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

        <div class="col-md-2">
            <select name="type" class="form-select">
                <option value="">All Types</option>
                <option value="auto_reply" <?php echo e(request('type') == 'auto_reply' ? 'selected' : ''); ?>>Auto Reply</option>
                <option value="promotion" <?php echo e(request('type') == 'promotion' ? 'selected' : ''); ?>>Promotion</option>
            </select>
        </div>

        <div class="col-md-2">
            <select name="call_type" class="form-select">
                <option value="">All Call Types</option>
                <option value="incoming" <?php echo e(request('call_type') == 'incoming' ? 'selected' : ''); ?>>Incoming</option>
                <option value="outgoing" <?php echo e(request('call_type') == 'outgoing' ? 'selected' : ''); ?>>Outgoing</option>
                <option value="missed" <?php echo e(request('call_type') == 'missed' ? 'selected' : ''); ?>>Missed</option>
                <option value="all" <?php echo e(request('call_type') == 'all' ? 'selected' : ''); ?>>All Calls</option>
            </select>
        </div>

        <div class="col-md-2">
            <select name="channel" class="form-select">
                <option value="">All Channels</option>
                <option value="sms" <?php echo e(request('channel') == 'sms' ? 'selected' : ''); ?>>SMS</option>
                <option value="whatsapp" <?php echo e(request('channel') == 'whatsapp' ? 'selected' : ''); ?>>WhatsApp</option>
                <option value="both" <?php echo e(request('channel') == 'both' ? 'selected' : ''); ?>>Both</option>
            </select>
        </div>

        <div class="col-md-1">
            <button type="submit" class="btn btn-primary">
                <i class="bi bi-filter"></i>
            </button>
        </div>

        <div class="col-md-1 text-end">
            <a href="<?php echo e(route('dashboard.templates.create')); ?>" class="btn btn-success">
                <i class="bi bi-plus-lg"></i>
            </a>
        </div>
    </form>

    <!-- Results Info -->
    <div class="d-flex justify-content-between align-items-center mb-3">
        <span class="text-muted">Showing <?php echo e($templates->count()); ?> of <?php echo e($templates->total()); ?> templates</span>
    </div>

    <!-- Templates Grid -->
    <div class="row g-4">
        <?php $__empty_1 = true; $__currentLoopData = $templates; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $template): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
        <div class="col-md-6 col-lg-4">
            <div class="card h-100">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h6 class="mb-0"><?php echo e($template->name); ?></h6>
                    <div>
                        <?php if($template->is_default): ?>
                        <span class="badge bg-primary">Default</span>
                        <?php endif; ?>
                        <?php if($template->is_active): ?>
                        <span class="badge bg-success">Active</span>
                        <?php else: ?>
                        <span class="badge bg-secondary">Inactive</span>
                        <?php endif; ?>
                    </div>
                </div>
                <div class="card-body">
                    <div class="mb-2">
                        <span class="badge bg-<?php echo e($template->type == 'promotion' ? 'warning' : 'info'); ?>">
                            <?php echo e(ucfirst(str_replace('_', ' ', $template->type ?? 'auto_reply'))); ?>

                        </span>
                        <?php
                        $channelBadge = match($template->channel ?? 'sms') {
                        'whatsapp' => 'bg-success',
                        'both' => 'bg-info',
                        default => 'bg-primary',
                        };
                        $channelLabel = match($template->channel ?? 'sms') {
                        'whatsapp' => 'WhatsApp',
                        'both' => 'Both',
                        default => 'SMS',
                        };
                        ?>
                        <span class="badge <?php echo e($channelBadge); ?>">
                            <?php if(($template->channel ?? 'sms') == 'whatsapp'): ?>
                            <i class="bi bi-whatsapp"></i>
                            <?php elseif(($template->channel ?? 'sms') == 'both'): ?>
                            <i class="bi bi-chat-dots"></i>
                            <?php else: ?>
                            <i class="bi bi-chat-text"></i>
                            <?php endif; ?>
                            <?php echo e($channelLabel); ?>

                        </span>
                        <span class="badge bg-light text-dark">
                            <?php echo e(ucfirst($template->call_type ?? 'all')); ?>

                        </span>
                        <?php if($template->priority > 0): ?>
                        <span class="badge bg-secondary">Priority: <?php echo e($template->priority); ?></span>
                        <?php endif; ?>
                    </div>
                    <p class="card-text small"><?php echo e(Str::limit($template->content, 120)); ?></p>
                </div>
                <div class="card-footer bg-transparent">
                    <div class="d-flex justify-content-between align-items-center">
                        <small class="text-muted">
                            <i class="bi bi-building me-1"></i>
                            <?php echo e($template->client->name ?? 'Global'); ?>

                        </small>
                        <div class="btn-group btn-group-sm">
                            <a href="<?php echo e(route('dashboard.templates.edit', $template->id)); ?>"
                                class="btn btn-outline-secondary" title="Edit">
                                <i class="bi bi-pencil"></i>
                            </a>
                            <form action="<?php echo e(route('dashboard.templates.toggle-status', $template->id)); ?>" method="POST" class="d-inline">
                                <?php echo csrf_field(); ?>
                                <button type="submit" class="btn btn-outline-<?php echo e($template->is_active ? 'warning' : 'success'); ?>"
                                    title="<?php echo e($template->is_active ? 'Deactivate' : 'Activate'); ?>">
                                    <i class="bi bi-<?php echo e($template->is_active ? 'pause' : 'play'); ?>"></i>
                                </button>
                            </form>
                            <form action="<?php echo e(route('dashboard.templates.delete', $template->id)); ?>" method="POST" class="d-inline">
                                <?php echo csrf_field(); ?>
                                <?php echo method_field('DELETE'); ?>
                                <button type="submit" class="btn btn-outline-danger" title="Delete"
                                    data-confirm="Are you sure you want to delete this template?"
                                    data-confirm-title="Delete Template"
                                    data-confirm-btn="Delete"
                                    data-confirm-class="btn-danger">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
        <div class="col-12">
            <div class="text-center text-muted py-5">
                <i class="bi bi-file-text display-4"></i>
                <p class="mt-3">No message templates found</p>
                <a href="<?php echo e(route('dashboard.templates.create')); ?>" class="btn btn-primary">
                    <i class="bi bi-plus-lg"></i> Create Your First Template
                </a>
            </div>
        </div>
        <?php endif; ?>
    </div>

    <!-- Pagination -->
    <div class="d-flex justify-content-center mt-4">
        <?php echo e($templates->withQueryString()->links()); ?>

    </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\templates.blade.php ENDPATH**/ ?>