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

import {ItemDetails, TransactionService} from 'm2-core';
import {CdDemoComponent} from '../../../abstract/CdDemoComponent';
import {CdHelperService} from '../../../../../service/cd-helper.service';


@Component({
    template: `
        <div *ngIf="!isInitialized" class="h-100 busy-modal"></div>
        
        <div class="cd-demo-widget">
            <item-card-lazy 
                    [itemId]="itemId" 
                    [editModeON]="editModeON$ | async"
                    (itemLoaded)="onItemLoaded($event)"
                    (initialized)="isInitialized = true"
            >
            </item-card-lazy>
        </div>
    `
})
export class CdItemCardDemoComponent extends CdDemoComponent implements OnInit {

    constructor(
        private cdHelperService: CdHelperService,
        private transactionService: TransactionService
    ) {
        super();
    }

    isInitialized = false;
    itemId?: number;
    editModeON$ = this.transactionService.editModeON$;

    async ngOnInit() {
        this.itemId = await this.cdHelperService.getAnyItemId();
    }

    onItemLoaded(details: ItemDetails): void {
        // do smth...
    }

}
