import { Component } from '@angular/core';
import {
    LocationService,
    TripJsonld,
    TripLocationService,
    TripService, UserService,
    UserTripJsonld,
    UserTripService
} from "@app/core/api/v1";
import {AppHelperService} from "@app/_helpers/app-helper.service";
import {ActivatedRoute} from "@angular/router";
import {FormBuilder} from "@angular/forms";
import {FormMode, FormSubmitEvent} from "@app/_components/_abstract/abstract-data-form-component";
import {ModalStatus} from "@app/_helpers/modal.states";

@Component({
  selector: 'app-user-trip-detail',
  templateUrl: './user-trip-detail.component.html',
  styleUrl: './user-trip-detail.component.scss'
})
export class UserTripDetailComponent {
    protected userTrip!: UserTripJsonld;
    protected readonly FormMode = FormMode;

    constructor(
        private tripService: TripService,
        private tripLocationService: TripLocationService,
        private locationService: LocationService,
        private userTripService: UserTripService,
        private userService: UserService,
        protected appHelperService: AppHelperService,
        private route: ActivatedRoute,
        private fb: FormBuilder
    ) {}

    ngOnInit() {
        this.route.params.subscribe(params => {
            this.userTripService.userTripsIdGet(params['id']).subscribe(
                data => {
                    this.userTrip = data;
                }
            );
        });
    }

    onFormUpdate(event: FormSubmitEvent<UserTripJsonld>) {
        if (event.status === ModalStatus.Submitted && event.data) {
            this.userTrip = event.data;
        }
    }

}
