import {Component, Input, OnInit} from "@angular/core";
import {ComponentLifecycleEventEmitter} from "@synerty/vortexjs";
import {PeekCanvasEditor} from "../canvas/PeekCanvasEditor.web";
import {EditorContextType} from "../canvas/PeekCanvasEditorProps";


@Component({
    selector: 'pl-diagram-edit-props-toolbar',
    templateUrl: 'edit-props-toolbar.component.web.html',
    styleUrls: ['edit-props-toolbar.component.web.scss'],
    moduleId: module.id
})
export class EditPropsToolbarComponent extends ComponentLifecycleEventEmitter
    implements OnInit {

    @Input("canvasEditor")
    canvasEditor: PeekCanvasEditor;

    currentContext: EditorContextType = EditorContextType.NONE;

    constructor() {
        super();

    }

    ngOnInit() {

        this.canvasEditor.props.contextPanelObservable
            .takeUntil(this.onDestroyEvent)
            .subscribe((val: EditorContextType) => {
                this.currentContext = val;
            });

    }


    isToolbarShown(): boolean {
        return this.canvasEditor.isEditing();
    }

    // Branch Properties
    showBranchProperties(): void {
        this.canvasEditor.props.showBranchProperties();
    }

    isBranchPropertiesActive(): boolean {
        return this.currentContext == EditorContextType.BRANCH_PROPERTIES;
    }

    // Shape Properties
    showShapeProperties(): void {
        this.canvasEditor.props.showShapeProperties();
    }

    isShapePropertiesActive(): boolean {
        return this.currentContext == EditorContextType.SHAPE_PROPERTIES;
    }

    isShapePropertiesShown(): boolean {
        return this.canvasEditor.props.shapePanelContext != null;
    }

    // GroupPtr Properties
    showGroupPtrProperties(): void {
        this.canvasEditor.props.showGroupPtrProperties();
    }

    isGroupPtrPropertiesActive(): boolean {
        return this.currentContext == EditorContextType.GROUP_PTR_PROPERTIES;
    }

    isGroupPtrPropertiesShown(): boolean {
        return this.canvasEditor.props.groupPtrPanelContext != null;
    }

    // LiveDB Properties
    showLiveDbProperties(): void {
        this.canvasEditor.props.showLiveDbProperties();
    }

    isLiveDbPropertiesActive(): boolean {
        return false;
    }

    isLiveDbPropertiesShown(): boolean {
        return false; //this.canvasEditor.isShapeSelected();
    }
}
