import {Component, EventEmitter, Input, Output} from "@angular/core";
import {ActivatedRoute, ParamMap} from "@angular/router";
import { FlashmessagesService } from "../../../layout/flashmessages/flashmessages.service";

@Component({
    templateUrl: 'card.component.html',
    selector: 'base-card',
})
export class BaseCrudCardComponent {
    @Input() resource: string | undefined;
    @Input() resource_id: string | null = null;
    @Input() schema: string | undefined;

    @Output() resourceReceived: EventEmitter<any> = new EventEmitter();

    constructor(
        private route: ActivatedRoute,
        public flashService: FlashmessagesService
    ) {}

    ngOnInit(): void {
        if (this.resource_id === null) {
            this.route.paramMap.subscribe((params: ParamMap) => {
                this.resource_id = params.get('id')
            })
        }
    }

    onResourceReceived(model: any) {
        this.resourceReceived.emit(model);
    }
}
