import { Component, inject } from '@angular/core'; import { RouterLink } from '@angular/router'; import { FormsModule } from '@angular/forms'; import { MailService } from '../../services/mail.service'; import { Router, ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-compose', standalone: true, imports: [RouterLink, FormsModule], providers: [MailService], template: `

COMPOSE MESSAGE

@if (success) {
Message sent successfully!
}
@if (isHtml) {

Supports Markdown: **bold**, *italic*, - lists,  code 

}
CANCEL
`, styles: `` }) export default class ComposeComponent { private mailService = inject(MailService); private router = inject(Router); private route = inject(ActivatedRoute); to = ''; subject = ''; body = ''; isHtml = false; sending = false; success = false; constructor() { // Поддержка Reply и Forward через queryParams this.route.queryParams.subscribe(params => { if (params['replyTo']) { this.to = params['replyTo']; } if (params['subject']) { this.subject = params['subject']; } if (params['forwardSubject']) { this.subject = params['forwardSubject']; } if (params['forwardBody']) { this.body = '\n\n--- Forwarded message ---\n' + params['forwardBody']; } }); } onSend(): void { this.sending = true; this.mailService.send({ to: this.to, subject: this.subject, body: this.body, html: this.isHtml }).subscribe({ next: () => { this.success = true; this.sending = false; this.to = ''; this.subject = ''; this.body = ''; this.isHtml = false; setTimeout(() => this.router.navigate(['/inbox']), 1500); }, error: () => { this.sending = false; } }); } }