{{define "title"}}Edit IP Whitelist - SMTP Management{{end}}

{{define "content"}}
<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header"><h5 class="mb-0"><i class="bi bi-pencil-square me-2"></i>Edit IP Whitelist Entry</h5></div>
            <div class="card-body">
                <form method="POST">
                    <div class="mb-3">
                        <label for="ip_address" class="form-label">IP Address</label>
                        <input type="text" class="form-control" id="ip_address" name="ip_address" value="{{.ip_record.IPAddress}}" placeholder="e.g., 192.168.1.1" required>
                        <div class="form-text">Enter a single IPv4 address</div>
                    </div>
                    <div class="mb-3">
                        <label for="domain_id" class="form-label">Domain</label>
                        <select class="form-select" id="domain_id" name="domain_id" required>
                            <option value="">Select a domain</option>
                            {{range .domains}}<option value="{{.ID}}" {{if eq .ID $.ip_record.DomainID}}selected{{end}}>{{.DomainName}}</option>{{end}}
                        </select>
                        <div class="form-text">This IP will be able to send emails for the selected domain</div>
                    </div>
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="store_message_content" name="store_message_content" {{if .ip_record.StoreMessageContent}}checked{{end}}>
                            <label class="form-check-label" for="store_message_content"><strong>Store Full Message Content</strong></label>
                            <div class="form-text">If enabled, the full message body and attachments will be stored and viewable in logs.</div>
                        </div>
                    </div>
                    <div class="d-flex gap-2">
                        <button type="submit" class="btn btn-primary"><i class="bi bi-check-lg me-1"></i>Update IP Whitelist</button>
                        <a href="/pymta-manager/ips" class="btn btn-secondary"><i class="bi bi-x-lg me-1"></i>Cancel</a>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="col-md-4">
        <div class="card">
            <div class="card-header"><h6 class="mb-0"><i class="bi bi-info-circle me-2"></i>Current Configuration</h6></div>
            <div class="card-body">
                <dl class="row mb-0">
                    <dt class="col-sm-4">Current IP:</dt><dd class="col-sm-8"><code>{{.ip_record.IPAddress}}</code></dd>
                    <dt class="col-sm-4">Domain:</dt>
                    <dd class="col-sm-8">{{range .domains}}{{if eq .ID $.ip_record.DomainID}}<span class="badge bg-secondary">{{.DomainName}}</span>{{end}}{{end}}</dd>
                    <dt class="col-sm-4">Status:</dt>
                    <dd class="col-sm-8">{{if .ip_record.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}}</dd>
                    <dt class="col-sm-4">Store Message:</dt>
                    <dd class="col-sm-8">{{if .ip_record.StoreMessageContent}}<span class="badge bg-info text-dark"><i class="bi bi-file-earmark-text me-1"></i>Full Message</span>{{else}}<span class="badge bg-secondary"><i class="bi bi-file-earmark me-1"></i>Headers Only</span>{{end}}</dd>
                    <dt class="col-sm-4">Created:</dt><dd class="col-sm-8"><small class="text-muted">{{strftime "%Y-%m-%d %H:%M" .ip_record.CreatedAt}}</small></dd>
                </dl>
            </div>
        </div>
    </div>
</div>
{{end}}

{{define "extra_js"}}
<script>
document.addEventListener('DOMContentLoaded', function() { document.getElementById('ip_address').focus(); });
</script>
{{end}}
