import {AfterViewInit, Component, OnInit, ViewChild} from '@angular/core';
import {ICellEditorParams} from 'ag-grid-community';
import {ApiService} from '../../../../../service/api.service';
import {IonicSelectableComponent} from "ionic-selectable";

@Component({
    selector: 'editor-cel-page-link',
    templateUrl: './page-link-editor.component.html',
    styleUrls: ['./page-link-editor.component.scss'],
})
export class PageLinkEditorComponent implements OnInit {
    @ViewChild('selectable') selectable: IonicSelectableComponent;
    public params: ICellEditorParams;
    public value: any;
    public pages: any[] = [];

    constructor(
        public readonly api: ApiService,
    ) { }

    agInit(params: ICellEditorParams): void {
        this.params = params;
        this.value = { id: this.params.value };

        // @ts-ignore
        this.pages = params._pagesData || [];

        console.log('page link editor comp', this);

        setTimeout(() => {
            this.selectable.open();
        });
    }

    getValue(): any {
        return this.value.id;
    }

    async ngOnInit() {}

    finishEdit() {
        this.params.stopEditing();
    }
}
