import { CommonModule } from '@angular/common'; import { Component, Input, OnInit } from '@angular/core'; import { SeoService } from '../../services/seo.service'; export interface FAQItem { question: string; answer: string; } @Component({ selector: 'app-faq', standalone: true, imports: [CommonModule], template: `

Frequently Asked Questions

@for (item of faqItems; track $index) {
@if (openIndex === $index) {

}
}
`, styles: [` .rotate-180 { transform: rotate(180deg); } `] }) export class FaqComponent implements OnInit { @Input() faqItems: FAQItem[] = []; openIndex: number | null = null; constructor(private seoService: SeoService) {} ngOnInit() { // Generate and inject FAQ Schema for rich snippets if (this.faqItems.length > 0) { const faqSchema = { '@context': 'https://schema.org', '@type': 'FAQPage', 'mainEntity': this.faqItems.map(item => ({ '@type': 'Question', 'name': item.question, 'acceptedAnswer': { '@type': 'Answer', 'text': this.stripHtml(item.answer) } })) }; this.seoService.injectStructuredData(faqSchema); } } toggle(index: number) { this.openIndex = this.openIndex === index ? null : index; } private stripHtml(html: string): string { const tmp = document.createElement('DIV'); tmp.innerHTML = html; return tmp.textContent || tmp.innerText || ''; } ngOnDestroy() { this.seoService.clearStructuredData(); } }