<?php require_once __DIR__ . '/../layout.php'; ?>

<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem;">
    <div>
        <h3 style="margin: 0 0 0.5rem; color: white;">SMTP Settings Configuration</h3>
        <p style="color: var(--text-muted); margin: 0;">Configure outbound mail transport credentials checked by the system mailers.</p>
    </div>
    <a href="/superadmin/smtpCreate" class="btn-gold">
        <i class="ph ph-plus" style="font-weight: bold;"></i> Add SMTP Setting
    </a>
</div>

<div class="card responsive-table-container" style="padding: 0; overflow-x: auto; border: none; margin-bottom: 2rem; border-radius: 12px;">
    <table class="data-table" style="width: 100%; border-collapse: collapse;">
        <thead>
            <tr>
                <th style="width: 5%;">ID</th>
                <th style="width: 25%;">Host</th>
                <th style="width: 10%;">Port</th>
                <th style="width: 25%;">Username</th>
                <th style="width: 25%;">From Identity</th>
                <th style="width: 10%; text-align: center;">Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (empty($records)): ?>
                <tr>
                    <td colspan="6" style="text-align: center; color: var(--text-muted); padding: 2rem;">No SMTP profiles configured.</td>
                </tr>
            <?php else: ?>
                <?php foreach ($records as $rec): ?>
                    <tr>
                        <td style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['id']); ?></td>
                        <td><strong style="color: white;"><?php echo htmlspecialchars($rec['smtp_host']); ?></strong></td>
                        <td style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['smtp_port']); ?></td>
                        <td><code style="background: rgba(255,255,255,0.05); padding: 0.2rem 0.5rem; border-radius: 4px; color: var(--text-light);"><?php echo htmlspecialchars($rec['smtp_username']); ?></code></td>
                        <td>
                            <strong><?php echo htmlspecialchars($rec['from_name']); ?></strong><br>
                            <small style="color: var(--text-muted);"><?php echo htmlspecialchars($rec['from_email'] ?: $rec['smtp_username']); ?></small>
                        </td>
                        <td style="text-align: center; white-space: nowrap;">
                            <a href="/superadmin/smtpEdit/<?php echo $rec['id']; ?>" class="action-icon edit" title="Edit">
                                <i class="ph ph-pencil-simple"></i>
                            </a>
                            <a href="/superadmin/smtpDelete/<?php echo $rec['id']; ?>" class="action-icon delete" title="Delete" onclick="return confirm('Are you sure you want to delete this SMTP profile? Sending emails might fail if there are no other configurations.');">
                                <i class="ph ph-trash"></i>
                            </a>
                        </td>
                    </tr>
                <?php endforeach; ?>
            <?php endif; ?>
        </tbody>
    </table>
</div>

</div> <!-- main-content -->
</div> <!-- dashboard-layout -->
</body>
</html>
