import {Component, ViewChild} from '@angular/core';
import {ListComponent} from "@app/_components/list/list.component";
import {ListColDefinition} from "@app/_components/list/list-col-definition";
import {VesselService, ZoneJsonld} from "@app/core/api/v1";
import {Router} from "@angular/router";
import {AppHelperService} from "@app/_helpers/app-helper.service";
import {ListGetDataFunctionType} from "@app/_components/list/list-get-data-function-type";
import {ROUTE_VESSELS, ROUTE_ZONES} from "@app/app-routing.module";
import {VesselFormComponent} from "@app/_views/vessel/vessel-form/vessel-form.component";
import {SearchSelectComponent} from "@app/_components/search-select/search-select.component";

@Component({
  selector: 'app-vessel-list',
  templateUrl: './vessel-list.component.html',
  styleUrl: './vessel-list.component.scss'
})
export class VesselListComponent {
    @ViewChild("listComponent", {static: false}) listComponent!: ListComponent;

    protected readonly VesselFormComponent = VesselFormComponent;
    protected listColDefinitions!: ListColDefinition[];

    constructor(
        private vesselService: VesselService,
        private router: Router,
        protected appHelperService: AppHelperService,
    ) {

        this.listColDefinitions = SearchSelectComponent.getDefaultColDefVessels();
    }

    ngOnInit() {

    }

    ngAfterViewInit(): void {
        this.listComponent.getData();
    }

    getData: ListGetDataFunctionType = (
        index: number,
        pageSize: number,
        term?: string,
    ) => {
        return this.vesselService.vesselsGetCollection(
            index,
            pageSize,
            term,
            this.listComponent.getFilterJsonString(),
            this.listComponent.getSortingJsonString()
        );
    }

    getCustomDetailLink(element: ZoneJsonld) {
        return ROUTE_VESSELS + '/' + this.appHelperService.extractId(element?.id);
    }
}
