{{define "title"}}Edit Sender - 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-person-fill-gear me-2"></i>Edit Sender</h5></div>
            <div class="card-body">
                <form method="POST">
                    <div class="mb-3">
                        <label for="local_part" class="form-label">Email Address</label>
                        <div class="input-group">
                            <input type="text" class="form-control" id="local_part" name="local_part" value="{{.local_part}}" required
                                   pattern="[a-zA-Z0-9._%+-]+" title="Letters, numbers, and . _ % + - only">
                            <span class="input-group-text">@</span>
                            <select class="form-select" id="domain_id" name="domain_id" required style="max-width: 260px;">
                                <option value="">Select a domain</option>
                                {{range .domains}}<option value="{{.ID}}" {{if eq .ID $.sender.DomainID}}selected{{end}}>{{.DomainName}}</option>{{end}}
                            </select>
                        </div>
                        <div class="form-text">The sender always belongs to the domain selected here.</div>
                    </div>
                    <div class="mb-3">
                        <label for="password" class="form-label">Password</label>
                        <input type="password" class="form-control" id="password" name="password" placeholder="Leave blank to keep current password">
                        <div class="form-text">Only enter a password if you want to change it</div>
                    </div>
                    <div class="mb-3">
                        <div class="form-check">
                            <input class="form-check-input" type="checkbox" id="can_send_as_domain" name="can_send_as_domain" {{if .sender.CanSendAsDomain}}checked{{end}}>
                            <label class="form-check-label" for="can_send_as_domain"><strong>Can send as any email from domain</strong></label>
                            <div class="form-text">Allow this sender to send emails using any address within their domain</div>
                        </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 .sender.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 Sender</button>
                        <a href="/pymta-manager/senders" 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 Sender Details</h6></div>
            <div class="card-body">
                <dl class="row mb-0">
                    <dt class="col-sm-4">Email:</dt><dd class="col-sm-8"><code>{{.sender.Email}}</code></dd>
                    <dt class="col-sm-4">Domain:</dt>
                    <dd class="col-sm-8">{{range .domains}}{{if eq .ID $.sender.DomainID}}<span class="badge bg-secondary">{{.DomainName}}</span>{{end}}{{end}}</dd>
                    <dt class="col-sm-4">Status:</dt>
                    <dd class="col-sm-8">{{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}}</dd>
                    <dt class="col-sm-4">Domain Sender:</dt>
                    <dd class="col-sm-8">{{if .sender.CanSendAsDomain}}<span class="badge bg-success"><i class="bi bi-check-circle me-1"></i>Yes</span>{{else}}<span class="badge bg-secondary"><i class="bi bi-x-circle me-1"></i>No</span>{{end}}</dd>
                    <dt class="col-sm-4">Store Message:</dt>
                    <dd class="col-sm-8">{{if .sender.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" .sender.CreatedAt}}</small></dd>
                </dl>
            </div>
        </div>
    </div>
</div>
{{end}}

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