import { Component, Input } from '@angular/core';
import { firstValueFrom } from 'rxjs';
import { Dossier } from '@red/domain';
import { ComponentLogService } from '@services/files/component-log.service';
import { MatTooltip } from '@angular/material/tooltip';
import { TranslateModule } from '@ngx-translate/core';
import { MatMenu, MatMenuItem, MatMenuTrigger } from '@angular/material/menu';

@Component({
    selector: 'redaction-documine-export',
    templateUrl: './documine-export.component.html',
    standalone: true,
    imports: [MatTooltip, TranslateModule, MatMenuTrigger, MatMenu, MatMenuItem],
})
export class DocumineExportComponent {
    @Input() dossier: Dossier;

    constructor(private readonly _componentLogService: ComponentLogService) {}

    downloadComponentAsJSON() {
        return firstValueFrom(this._componentLogService.exportJSON(this.dossier.dossierTemplateId, this.dossier.dossierId));
    }

    async downloadComponentAsXML() {
        return firstValueFrom(this._componentLogService.exportXML(this.dossier.dossierTemplateId, this.dossier.dossierId));
    }
}
