import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {TabsComponent} from '../../../components/tabs/tabs.component';
import {Factory} from '../../../factory/factory';
import {IProduction} from '../../../model/entities/production';
import {IProductionContact} from '../../../model/entities/production-contact';
import {IProductionNote} from '../../../model/entities/production-note';
import {IProductionMeeting} from '../../../model/entities/production-meeting';
import {
    ProductionContactPersonViewComponent
} from './production-contact-person-view/production-contact-person-view.component';
import {ProductionNoteViewComponent} from './production-note-view/production-note-view.component';
import {ProductionMeetingViewComponent} from './production-meeting-view/production-meeting-view.component';

@Component({
  selector: 'app-production-view',
  templateUrl: './production-view.component.html',
  styleUrls: ['./production-view.component.scss']
})

export class ProductionViewComponent implements OnInit {

    @Output() editProduction: EventEmitter<IProduction> = new EventEmitter<IProduction>();
    @Output() createProductionContact: EventEmitter<IProductionContact> = new EventEmitter<IProductionContact>();
    @Output() editProductionContact: EventEmitter<IProductionContact> = new EventEmitter<IProductionContact>();
    @Output() deleteProductionContact: EventEmitter<number> = new EventEmitter<number>();
    @Output() createNote: EventEmitter<IProductionNote> = new EventEmitter<IProductionNote>();
    @Output() editNote: EventEmitter<IProductionNote> = new EventEmitter<IProductionNote>();
    @Output() deleteNote: EventEmitter<number> = new EventEmitter<number>();
    @Output() createMeeting: EventEmitter<IProductionMeeting> = new EventEmitter<IProductionMeeting>();
    @Output() editMeeting: EventEmitter<IProductionMeeting> = new EventEmitter<IProductionMeeting>();
    @Output() deleteMeeting: EventEmitter<number> = new EventEmitter<number>();
    @Output() editMeetingReport: EventEmitter<number> = new EventEmitter<number>();
    @Output() shortcut: EventEmitter<IProduction> = new EventEmitter<IProduction>();
    @ViewChild('tabsProductionView', { static: true }) tabsProductionView: TabsComponent;
    @ViewChild('productionDataView', { static: true }) productionDataView: ProductionViewComponent;
    @ViewChild('productionContactPersonView', { static: true }) productionContactPersonView: ProductionContactPersonViewComponent;
    @ViewChild('productionNoteView', { static: true }) productionNoteView: ProductionNoteViewComponent;
    @ViewChild('productionMeetingView', { static: true }) productionMeetingView: ProductionMeetingViewComponent;

    public production: IProduction;

    constructor() { }

    ngOnInit() {
        this.production = Factory.getEmptyProduction();
    }

    /**
     * Sets data
     * @param production
     * @param isUpdate
     */
    public setData(production: IProduction, isUpdate: boolean = false): void {
        this.production = production;
        this.productionDataView.setData(this.production);
        this.productionContactPersonView.setData(this.production, isUpdate);
        this.productionNoteView.setData(this.production, isUpdate);
        this.productionMeetingView.setData(this.production, isUpdate);
    }

    /**
     * Saves production
     * @param production
     */
    public editProductionFunction(production: IProduction): void {
        this.editProduction.emit(production);
    }

    /**
     * Creates production contact
     * @param productionContact
     */
    public createProductionContactFunction(productionContact: IProductionContact): void {
        this.createProductionContact.emit(productionContact);
    }

    /**
     * Edit production contact
     * @param productionContact
     */
    public editProductionContactFunction(productionContact: IProductionContact): void {
        this.editProductionContact.emit(productionContact);
    }

    /**
     * Creates production note
     * @param productionNote
     */
    public createProductionNoteFunction(productionNote: IProductionNote): void {
        this.createNote.emit(productionNote);
    }

    /**
     * Edits note entry
     * @param productionNote
     */
    public editProductionNoteFunction(productionNote: IProductionNote) {
        this.editNote.emit(productionNote);
    }

    /**
     * Deletes production note
     * @param noteId
     */
    public deleteProductionNoteFunction(noteId: number): void {
        this.deleteNote.emit(noteId);
    }

    /**
     * Deletes production contact
     * @param productionId
     */
    public deleteProductionContactFunction(productionId: number): void {
        this.deleteProductionContact.emit(productionId);
    }

    /**
     * Creates production meeting
     * @param productionMeeting
     */
    public createProductionMeetingFunction(productionMeeting: IProductionMeeting): void {
        this.createMeeting.emit(productionMeeting);
    }

    /**
     * Edits meeting entry
     * @param productionMeeting
     */
    public editProductionMeetingFunction(productionMeeting: IProductionMeeting) {
        this.editMeeting.emit(productionMeeting);
    }

    /**
     * Deletes production meeting
     * @param meetingId
     */
    public deleteProductionMeetingFunction(meetingId: number): void {
        this.deleteMeeting.emit(meetingId);
    }

    /**
     * Edit report after meeting has started
     * @param reportValues
     */
    public editProductionMeetingReportFunction(reportValues: any): void {
        this.editMeetingReport.emit(reportValues);
    }

    /**
     * Shortcut to production detail
     * @param production
     */
    public shortcutFunction(production: IProduction): void {
        this.shortcut.emit(production);
    }

}
