// @ts-nocheck import { Component, Input, OnInit, OnChanges, SimpleChanges } from "@angular/core"; /** * CodeSnippetComponent * Angular wrapper component representing the Code Snippet viewer and clipboard actions. */ @Component({ selector: "mayvio-code-snippet", template: `
{{ snippets[activeTab] }}
` }) export class CodeSnippetComponent implements OnInit, OnChanges { @Input() snippets: Record = {}; availableTabs: string[] = []; activeTab = ""; copied = false; ngOnInit() { this.updateTabs(); } ngOnChanges(changes: SimpleChanges) { if (changes["snippets"]) { this.updateTabs(); } } private updateTabs() { if (this.snippets) { this.availableTabs = Object.keys(this.snippets).filter( (k) => this.snippets[k] ); if ( this.availableTabs.length > 0 && !this.availableTabs.includes(this.activeTab) ) { this.activeTab = this.availableTabs[0]; } } else { this.availableTabs = []; this.activeTab = ""; } } copyCode() { const code = this.snippets[this.activeTab] || ""; navigator.clipboard.writeText(code).then(() => { this.copied = true; setTimeout(() => (this.copied = false), 2000); }); } }