import {Component, OnInit} from '@angular/core';

import {Transaction, TransactionReadService} from 'm2-core';
import {CdDemoComponent} from '../../../abstract/CdDemoComponent';


@Component({
    template: `
        <div *ngIf="!isInitialized" class="h-100 busy-modal"></div>
        
        <div class="cd-demo-widget h-100 pt-4">
            <tx-details-lazy
                    *ngIf="transaction"
                    [transactionId]="transaction.id"
                    tabsClasses="form-tabs"
                    (initialized)="isInitialized = true"
            >
            </tx-details-lazy>
        </div>
    `
})
export class CdTxDetailsDemoComponent extends CdDemoComponent implements OnInit {

    constructor(
        private transactionReadService: TransactionReadService
    ) {
        super();
    }

    isInitialized = false;
    transaction?: Transaction;

    ngOnInit() {
        this.transactionReadService.findTransactions()
            .subscribe(transactions => this.transaction = transactions.find(t => t.hasChanges));
    }

}
