{{define "title"}}Allow/Block List - Email Server{{end}}
{{define "page_title"}}Allow/Block List{{end}}

{{define "content"}}
<div class="d-flex justify-content-between align-items-center mb-4">
    <h2><i class="bi bi-shield-exclamation me-2"></i>Allow/Block List <small class="text-muted fs-6">{{.mailbox.Email}}</small></h2>
    <a href="/pymta-manager/mailboxes" class="btn btn-secondary"><i class="bi bi-arrow-left me-2"></i>Back to Mailboxes</a>
</div>

<div class="alert alert-info">
    <i class="bi bi-info-circle me-2"></i>A pattern is either an exact address (<code>spam@evil.com</code>) or a whole domain (<code>@evil.com</code>). Block entries reject mail at RCPT time; allow entries bypass spam scoring entirely for that sender.
</div>

<div class="row">
    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header"><h5 class="mb-0 text-success"><i class="bi bi-check-circle me-2"></i>Allow List</h5></div>
            <div class="card-body">
                <form method="POST" action="/pymta-manager/mailboxes/{{.mailbox.ID}}/lists/add" class="d-flex gap-2 mb-3">
                    <input type="hidden" name="list_type" value="allow">
                    <input type="text" class="form-control" name="pattern" placeholder="friend@example.com or @example.com" required>
                    <button type="submit" class="btn btn-success"><i class="bi bi-plus-lg"></i></button>
                </form>
                {{if .allow}}
                <ul class="list-group list-group-flush">
                    {{range .allow}}
                    <li class="list-group-item list-group-item-dark d-flex justify-content-between align-items-center">
                        <code>{{.Pattern}}</code>
                        <form method="post" action="/pymta-manager/mailboxes/{{$.mailbox.ID}}/lists/{{.ID}}/remove" class="d-inline">
                            <button type="submit" class="btn btn-outline-danger btn-sm" data-confirm="Remove {{.Pattern}} from the allow list?"><i class="bi bi-trash"></i></button>
                        </form>
                    </li>
                    {{end}}
                </ul>
                {{else}}
                <p class="text-muted mb-0">No allow-list entries.</p>
                {{end}}
            </div>
        </div>
    </div>

    <div class="col-md-6 mb-4">
        <div class="card">
            <div class="card-header"><h5 class="mb-0 text-danger"><i class="bi bi-x-circle me-2"></i>Block List</h5></div>
            <div class="card-body">
                <form method="POST" action="/pymta-manager/mailboxes/{{.mailbox.ID}}/lists/add" class="d-flex gap-2 mb-3">
                    <input type="hidden" name="list_type" value="block">
                    <input type="text" class="form-control" name="pattern" placeholder="spam@evil.com or @evil.com" required>
                    <button type="submit" class="btn btn-danger"><i class="bi bi-plus-lg"></i></button>
                </form>
                {{if .block}}
                <ul class="list-group list-group-flush">
                    {{range .block}}
                    <li class="list-group-item list-group-item-dark d-flex justify-content-between align-items-center">
                        <code>{{.Pattern}}</code>
                        <form method="post" action="/pymta-manager/mailboxes/{{$.mailbox.ID}}/lists/{{.ID}}/remove" class="d-inline">
                            <button type="submit" class="btn btn-outline-danger btn-sm" data-confirm="Remove {{.Pattern}} from the block list?"><i class="bi bi-trash"></i></button>
                        </form>
                    </li>
                    {{end}}
                </ul>
                {{else}}
                <p class="text-muted mb-0">No block-list entries.</p>
                {{end}}
            </div>
        </div>
    </div>
</div>
{{end}}
