{{define "title"}}Senders - Email Server Management{{end}}
{{define "page_title"}}Sender Management{{end}}

{{define "content"}}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-people me-2"></i>Senders</h2>
    <a href="/pymta-manager/senders/add" class="btn btn-primary"><i class="bi bi-person-plus me-2"></i>Add Sender</a>
</div>

<div class="card">
    <div class="card-header"><h5 class="mb-0"><i class="bi bi-list-ul me-2"></i>All Senders</h5></div>
    <div class="card-body p-0">
        {{if .senders}}
            <div class="table-responsive">
                <table class="table table-dark table-hover mb-0">
                    <thead><tr><th>Email</th><th>Domain</th><th>Permissions</th><th>Status</th><th>Storage</th><th>Created</th><th>Actions</th></tr></thead>
                    <tbody>
                        {{range .senders}}
                        {{$sender := index . 0}}{{$domain := index . 1}}
                        <tr>
                            <td><div class="fw-bold">{{$sender.Email}}</div></td>
                            <td><span class="badge bg-secondary">{{$domain.domain_name}}</span></td>
                            <td>
                                {{if $sender.CanSendAsDomain}}
                                    <span class="badge bg-warning" style="color: black;"><i class="bi bi-star me-1"></i>Domain Sender</span><br>
                                    <small class="text-muted">Can send as *@{{$domain.domain_name}}</small>
                                {{else}}
                                    <span class="badge bg-info" style="color: black;"><i class="bi bi-person me-1"></i>Regular Sender</span><br>
                                    <small class="text-muted">Can only send as {{$sender.Email}}</small>
                                {{end}}
                            </td>
                            <td>
                                {{if $sender.IsActive}}<span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>Active</span>
                                {{else}}<span class="badge bg-danger"><i class="bi bi-x-circle me-1"></i>Inactive</span>{{end}}
                            </td>
                            <td>
                                {{if $sender.StoreMessageContent}}<span class="badge bg-info text-dark"><i class="bi bi-file-earmark-text me-1"></i>Stores Full Message</span>
                                {{else}}<span class="badge bg-secondary"><i class="bi bi-file-earmark me-1"></i>Headers Only</span>{{end}}
                            </td>
                            <td><small class="text-muted">{{strftime "%Y-%m-%d %H:%M" $sender.CreatedAt}}</small></td>
                            <td>
                                <div class="btn-group" role="group">
                                    <a href="/pymta-manager/senders/{{$sender.ID}}/edit" class="btn btn-outline-primary btn-sm" title="Edit Sender"><i class="bi bi-pencil"></i></a>
                                    {{if $sender.IsActive}}
                                        <form method="post" action="/pymta-manager/senders/{{$sender.ID}}/delete" class="d-inline">
                                            <button type="submit" class="btn btn-outline-warning btn-sm" title="Disable Sender" data-confirm="Disable user {{$sender.Email}}?"><i class="bi bi-pause-circle"></i></button>
                                        </form>
                                    {{else}}
                                        <form method="post" action="/pymta-manager/senders/{{$sender.ID}}/enable" class="d-inline">
                                            <button type="submit" class="btn btn-outline-success btn-sm" title="Enable Sender" data-confirm="Enable user {{$sender.Email}}?"><i class="bi bi-play-circle"></i></button>
                                        </form>
                                    {{end}}
                                    <form method="post" action="/pymta-manager/senders/{{$sender.ID}}/remove" class="d-inline">
                                        <button type="submit" class="btn btn-outline-danger btn-sm" title="Permanently Remove Sender" data-confirm="Permanently remove user {{$sender.Email}}? This cannot be undone!"><i class="bi bi-trash"></i></button>
                                    </form>
                                </div>
                            </td>
                        </tr>
                        {{end}}
                    </tbody>
                </table>
            </div>
        {{else}}
            <div class="text-center py-5">
                <i class="bi bi-people text-muted" style="font-size: 4rem;"></i>
                <h4 class="text-muted mt-3">No senders configured</h4>
                <p class="text-muted">Add sender to enable username/password authentication</p>
                <a href="/pymta-manager/senders/add" class="btn btn-primary"><i class="bi bi-person-plus me-2"></i>Add Your First Sender</a>
            </div>
        {{end}}
    </div>
</div>
{{end}}
