<?php
/** @var yii\web\View $this */
/** @var common\models\Testimonial[] $testimonials */

use yii\helpers\Html;
use yii\helpers\Url;

$this->title = 'Testimonials';
?>

<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:2rem">
    <div>
        <h2 style="font-size:1.4rem;font-weight:700;color:#0f172a;margin:0">Testimonials</h2>
        <p style="color:#64748b;font-size:.875rem;margin:.3rem 0 0">Manage client reviews shown on your website.</p>
    </div>
    <a href="<?= Url::to(['/webcms/testimonial/create']) ?>" class="btn-cms-primary" style="display:inline-flex;align-items:center;gap:.4rem;text-decoration:none">
        <i class="bi bi-plus-lg"></i> Add Testimonial
    </a>
</div>

<?php if (empty($testimonials)): ?>
<div class="cms-card">
    <div class="cms-card-body" style="text-align:center;padding:3rem">
        <i class="bi bi-chat-quote" style="font-size:3rem;color:#cbd5e1;display:block;margin-bottom:1rem"></i>
        <div style="font-weight:600;color:#0f172a;margin-bottom:.4rem">No testimonials yet</div>
        <div style="color:#64748b;font-size:.875rem;margin-bottom:1.5rem">Add your first client testimonial to display it on the website.</div>
        <a href="<?= Url::to(['/webcms/testimonial/create']) ?>" class="btn-cms-primary" style="text-decoration:none;display:inline-flex;align-items:center;gap:.4rem">
            <i class="bi bi-plus-lg"></i> Add Testimonial
        </a>
    </div>
</div>
<?php else: ?>
<div class="cms-card">
    <div class="cms-card-header">
        <h5>All Testimonials (<?= count($testimonials) ?>)</h5>
        <span style="font-size:.78rem;color:#94a3b8"><i class="bi bi-info-circle me-1"></i>Active testimonials appear on the website</span>
    </div>
    <div style="overflow-x:auto">
        <table style="width:100%;border-collapse:collapse">
            <thead>
                <tr style="background:#f8fafc">
                    <th style="padding:.85rem 1.5rem;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:#64748b;font-weight:600;text-align:left;border-bottom:1px solid #e2e8f0">#</th>
                    <th style="padding:.85rem 1rem;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:#64748b;font-weight:600;text-align:left;border-bottom:1px solid #e2e8f0">Client</th>
                    <th style="padding:.85rem 1rem;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:#64748b;font-weight:600;text-align:left;border-bottom:1px solid #e2e8f0">Quote</th>
                    <th style="padding:.85rem 1rem;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:#64748b;font-weight:600;text-align:center;border-bottom:1px solid #e2e8f0">Status</th>
                    <th style="padding:.85rem 1rem;font-size:.72rem;text-transform:uppercase;letter-spacing:.06em;color:#64748b;font-weight:600;text-align:right;border-bottom:1px solid #e2e8f0">Actions</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($testimonials as $t): ?>
                <tr style="border-bottom:1px solid #f1f5f9;transition:background .1s" onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background=''">
                    <td style="padding:.9rem 1.5rem;font-size:.85rem;color:#94a3b8"><?= $t->sort_order ?></td>
                    <td style="padding:.9rem 1rem">
                        <div style="display:flex;align-items:center;gap:.75rem">
                            <div style="width:38px;height:38px;border-radius:50%;background:linear-gradient(135deg,#2d6a4f,#52b788);display:flex;align-items:center;justify-content:center;color:#fff;font-weight:700;font-size:.9rem;flex-shrink:0">
                                <?= Html::encode($t->avatar_letter) ?>
                            </div>
                            <div>
                                <div style="font-weight:600;font-size:.9rem;color:#0f172a"><?= Html::encode($t->name) ?></div>
                                <div style="font-size:.78rem;color:#64748b"><?= Html::encode($t->role) ?></div>
                            </div>
                        </div>
                    </td>
                    <td style="padding:.9rem 1rem;max-width:360px">
                        <div style="font-size:.85rem;color:#475569;line-height:1.5;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden">
                            <?= Html::encode($t->quote) ?>
                        </div>
                    </td>
                    <td style="padding:.9rem 1rem;text-align:center">
                        <a href="<?= Url::to(['/webcms/testimonial/toggle', 'id' => $t->id]) ?>"
                           style="text-decoration:none"
                           title="Click to toggle">
                            <?php if ($t->is_active): ?>
                            <span class="cms-badge-active"><i class="bi bi-eye me-1"></i>Visible</span>
                            <?php else: ?>
                            <span class="cms-badge-inactive"><i class="bi bi-eye-slash me-1"></i>Hidden</span>
                            <?php endif; ?>
                        </a>
                    </td>
                    <td style="padding:.9rem 1rem;text-align:right">
                        <div style="display:flex;align-items:center;gap:.5rem;justify-content:flex-end">
                            <a href="<?= Url::to(['/webcms/testimonial/update', 'id' => $t->id]) ?>"
                               style="display:inline-flex;align-items:center;gap:.3rem;background:#f1f5f9;color:#475569;border-radius:7px;padding:.4rem .8rem;font-size:.78rem;font-weight:600;text-decoration:none;transition:background .2s"
                               onmouseover="this.style.background='#e2e8f0'" onmouseout="this.style.background='#f1f5f9'">
                                <i class="bi bi-pencil"></i> Edit
                            </a>
                            <?= Html::beginForm(['/webcms/testimonial/delete', 'id' => $t->id], 'post', ['style' => 'display:inline']) ?>
                            <?= Html::hiddenInput(Yii::$app->request->csrfParam, Yii::$app->request->csrfToken) ?>
                            <button type="submit" class="btn-cms-danger"
                                    onclick="return confirm('Delete this testimonial?')">
                                <i class="bi bi-trash"></i>
                            </button>
                            <?= Html::endForm() ?>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>

<p style="font-size:.78rem;color:#94a3b8;margin-top:.75rem;padding-left:.25rem">
    <i class="bi bi-lightbulb me-1"></i>
    Tip: Click the <strong>Visible / Hidden</strong> badge to toggle a testimonial on or off without deleting it.
    Edit <strong>Sort Order</strong> to control the display sequence.
</p>
<?php endif; ?>
