<?php $__env->startSection('content'); ?>
<?php
    $totalQuestions = $questions->count();
    $activeQuestions = $questions->where('status', 1)->count();
    $inactiveQuestions = $totalQuestions - $activeQuestions;
    $withActions = $questions->filter(function ($question) {
        return !empty($question->action_text) && !empty($question->action_url);
    })->count();
?>

<div class="row mb-4 align-items-center">
    <div class="col-lg-7">
        <h2 class="fw-bold text-dark mb-1">Chatbot Questions</h2>
        <p class="text-secondary mb-0">Manage quick replies, answers, action buttons, and display order for your portfolio chatbot.</p>
    </div>
    <div class="col-lg-5 text-lg-end mt-3 mt-lg-0">
        <a href="<?php echo e(route('chatbot.create')); ?>" class="btn btn-primary btn-lg shadow-sm rounded-3 px-4 py-2">
            <i class="bi bi-plus-circle-fill me-2"></i> Add New Question
        </a>
    </div>
</div>

<?php if(session('success')): ?>
    <div class="alert alert-success alert-dismissible fade show rounded-4 shadow-sm mb-4 border-0 p-3" role="alert">
        <div class="d-flex align-items-center">
            <div class="bg-success text-white rounded-circle p-2 me-3 d-flex align-items-center justify-content-center success-icon">
                <i class="bi bi-check-lg"></i>
            </div>
            <div>
                <strong class="d-block">Success!</strong>
                <span class="small"><?php echo e(session('success')); ?></span>
            </div>
        </div>
        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
    </div>
<?php endif; ?>

<div class="row g-3 mb-4">
    <div class="col-md-6 col-xl-3">
        <div class="card border-0 shadow-sm rounded-4 h-100 stats-card">
            <div class="card-body p-4">
                <span class="stats-label">Total Questions</span>
                <div class="d-flex align-items-end justify-content-between mt-3">
                    <h3 class="fw-bold text-dark mb-0"><?php echo e($totalQuestions); ?></h3>
                    <div class="stats-icon bg-primary-subtle text-primary">
                        <i class="bi bi-chat-dots"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="card border-0 shadow-sm rounded-4 h-100 stats-card">
            <div class="card-body p-4">
                <span class="stats-label">Active</span>
                <div class="d-flex align-items-end justify-content-between mt-3">
                    <h3 class="fw-bold text-dark mb-0"><?php echo e($activeQuestions); ?></h3>
                    <div class="stats-icon bg-success-subtle text-success">
                        <i class="bi bi-check2-circle"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="card border-0 shadow-sm rounded-4 h-100 stats-card">
            <div class="card-body p-4">
                <span class="stats-label">Inactive</span>
                <div class="d-flex align-items-end justify-content-between mt-3">
                    <h3 class="fw-bold text-dark mb-0"><?php echo e($inactiveQuestions); ?></h3>
                    <div class="stats-icon bg-warning-subtle text-warning">
                        <i class="bi bi-pause-circle"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-6 col-xl-3">
        <div class="card border-0 shadow-sm rounded-4 h-100 stats-card">
            <div class="card-body p-4">
                <span class="stats-label">With Actions</span>
                <div class="d-flex align-items-end justify-content-between mt-3">
                    <h3 class="fw-bold text-dark mb-0"><?php echo e($withActions); ?></h3>
                    <div class="stats-icon bg-info-subtle text-info">
                        <i class="bi bi-cursor"></i>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="card border-0 shadow-sm rounded-4 overflow-hidden">
    <div class="card-header bg-white border-bottom py-3 px-4 d-flex align-items-center justify-content-between">
        <h6 class="m-0 fw-bold text-dark">Question Library</h6>
        <span class="badge bg-light text-dark border rounded-pill px-3 py-2"><?php echo e($totalQuestions); ?> records</span>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="text-secondary small text-uppercase fw-bold" style="background-color: #f8fafc;">
                    <tr>
                        <th class="px-4 py-3" style="width: 80px;">Order</th>
                        <th class="py-3">Question & Answer</th>
                        <th class="py-3">Action</th>
                        <th class="py-3">Status</th>
                        <th class="py-3">Updated</th>
                        <th class="px-4 py-3 text-end">Management</th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $questions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $question): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $isActive = (int) $question->status === 1;
                        ?>
                        <tr class="transition-all">
                            <td class="px-4 py-4">
                                <span class="order-badge"><?php echo e($question->sort_order); ?></span>
                            </td>
                            <td class="py-4">
                                <div class="d-flex align-items-start gap-3">
                                    <div class="question-icon bg-primary-subtle text-primary">
                                        <i class="bi bi-robot"></i>
                                    </div>
                                    <div>
                                        <span class="d-block fw-bold text-dark h6 mb-1"><?php echo e($question->question); ?></span>
                                        <p class="text-secondary small mb-0"><?php echo e(\Illuminate\Support\Str::limit($question->answer, 115)); ?></p>
                                    </div>
                                </div>
                            </td>
                            <td class="py-4">
                                <?php if($question->action_text && $question->action_url): ?>
                                    <a href="<?php echo e($question->action_url); ?>" target="_blank" rel="noopener" class="action-link text-decoration-none">
                                        <i class="bi bi-box-arrow-up-right"></i> <?php echo e($question->action_text); ?>

                                    </a>
                                <?php else: ?>
                                    <span class="badge bg-light text-secondary border rounded-pill px-3 py-2">No action</span>
                                <?php endif; ?>
                            </td>
                            <td class="py-4">
                                <span class="badge rounded-pill px-3 py-2 <?php echo e($isActive ? 'bg-success-subtle text-success' : 'bg-warning-subtle text-warning'); ?>">
                                    <?php echo e($isActive ? 'Active' : 'Inactive'); ?>

                                </span>
                            </td>
                            <td class="py-4 text-secondary">
                                <span class="d-block small fw-bold text-dark mb-1">
                                    <?php echo e($question->updated_at ? $question->updated_at->format('d M, Y') : 'Not updated yet'); ?>

                                </span>
                                <span class="small">
                                    <?php echo e($question->updated_at ? $question->updated_at->diffForHumans() : 'Fresh draft'); ?>

                                </span>
                            </td>
                            <td class="px-4 py-4 text-end">
                                <div class="d-flex justify-content-end gap-2">
                                    <a href="<?php echo e(route('chatbot.edit', $question->id)); ?>" class="btn btn-light btn-sm rounded-3 border text-primary" title="Edit Question">
                                        <i class="bi bi-pencil-square"></i>
                                    </a>
                                    <button
                                        type="button"
                                        class="btn btn-light btn-sm rounded-3 border text-danger"
                                        title="Delete Question"
                                        data-bs-toggle="modal"
                                        data-bs-target="#deleteQuestionModal"
                                        data-question-title="<?php echo e($question->question); ?>"
                                        data-delete-url="<?php echo e(route('chatbot.destroy', $question->id)); ?>"
                                    >
                                        <i class="bi bi-trash3"></i>
                                    </button>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="6" class="text-center py-5">
                                <div class="empty-state-icon mx-auto mb-4">
                                    <i class="bi bi-chat-square-text"></i>
                                </div>
                                <h5 class="text-dark fw-bold">No Chatbot Questions Yet</h5>
                                <p class="text-secondary mb-4">Create your first quick reply to help visitors find the right portfolio details faster.</p>
                                <a href="<?php echo e(route('chatbot.create')); ?>" class="btn btn-primary rounded-3 px-4">Create First Question</a>
                            </td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<div class="modal fade" id="deleteQuestionModal" tabindex="-1" aria-labelledby="deleteQuestionModalLabel" aria-hidden="true">
    <div class="modal-dialog modal-dialog-centered">
        <div class="modal-content border-0 shadow-lg rounded-4 overflow-hidden">
            <div class="modal-body p-4 p-md-5">
                <div class="delete-modal-icon mx-auto mb-4">
                    <i class="bi bi-trash3"></i>
                </div>
                <div class="text-center">
                    <h5 class="fw-bold text-dark mb-2" id="deleteQuestionModalLabel">Delete this question?</h5>
                    <p class="text-secondary mb-2">This will permanently remove the selected chatbot question and its answer.</p>
                    <p class="text-dark fw-semibold mb-0" id="deleteQuestionName"></p>
                </div>
            </div>
            <div class="modal-footer border-0 pt-0 px-4 px-md-5 pb-4 pb-md-5 d-flex justify-content-center gap-2">
                <button type="button" class="btn btn-light border rounded-3 px-4" data-bs-dismiss="modal">Cancel</button>
                <form id="deleteQuestionForm" method="POST" class="m-0">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('DELETE'); ?>
                    <button type="submit" class="btn btn-danger rounded-3 px-4 shadow-sm">
                        Delete Question
                    </button>
                </form>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('styles'); ?>
<style>
    .transition-all { transition: all 0.2s ease-in-out; }
    .table tbody tr:hover { background-color: #f8fafc !important; transform: scale(1.002); }
    .stats-card { background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%); }
    .stats-label { color: #64748b; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; }
    .stats-icon, .success-icon, .question-icon { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; border-radius: 14px; font-size: 1.15rem; flex-shrink: 0; }
    .order-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 46px; height: 34px; border-radius: 999px; background: #f8fafc; border: 1px solid #e2e8f0; color: #475569; font-weight: 700; font-size: 0.85rem; }
    .action-link { display: inline-flex; align-items: center; gap: 0.45rem; color: #1d4ed8; font-size: 0.9rem; font-weight: 700; }
    .action-link:hover { color: #1e40af; }
    .bg-primary-subtle { background-color: #eff6ff !important; }
    .bg-success-subtle { background-color: #ecfdf5 !important; }
    .bg-warning-subtle { background-color: #fffbeb !important; }
    .bg-info-subtle { background-color: #ecfeff !important; }
    .text-success { color: #10b981 !important; }
    .text-warning { color: #d97706 !important; }
    .text-info { color: #0891b2 !important; }
    .empty-state-icon, .delete-modal-icon { width: 72px; height: 72px; display: flex; align-items: center; justify-content: center; border-radius: 24px; font-size: 1.8rem; }
    .empty-state-icon { background: linear-gradient(145deg, #dbeafe 0%, #eff6ff 100%); color: #2563eb; }
    .delete-modal-icon { background: linear-gradient(145deg, #fee2e2 0%, #fecaca 100%); color: #dc2626; }
</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
    document.addEventListener('DOMContentLoaded', function () {
        const deleteQuestionModal = document.getElementById('deleteQuestionModal');
        const deleteQuestionForm = document.getElementById('deleteQuestionForm');
        const deleteQuestionName = document.getElementById('deleteQuestionName');

        if (!deleteQuestionModal || !deleteQuestionForm || !deleteQuestionName) {
            return;
        }

        deleteQuestionModal.addEventListener('show.bs.modal', function (event) {
            const triggerButton = event.relatedTarget;

            if (!triggerButton) {
                return;
            }

            deleteQuestionForm.setAttribute('action', triggerButton.getAttribute('data-delete-url'));
            deleteQuestionName.textContent = triggerButton.getAttribute('data-question-title')
                ? '"' + triggerButton.getAttribute('data-question-title') + '"'
                : '';
        });
    });
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\portfolio\resources\views/chatbot/index.blade.php ENDPATH**/ ?>