import { Component, Inject, OnInit } from "@angular/core";

import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { TranslateModule } from "@ngx-translate/core";
import { MatCheckboxModule } from "@angular/material/checkbox";
import { MatFormFieldModule } from "@angular/material/form-field";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatInputModule } from "@angular/material/input";
import { MatButtonModule } from "@angular/material/button";

import { AddAction } from "../../models/add-action.enum";
import { JumpResp } from "../../models/jump";

import { JumpService } from "../../services/jump.service";
import { ServiceComm } from "../../services/service-comm.service";

@Component({
    selector: "app-jump-infos",
    templateUrl: "./jump-infos.component.html",
    styleUrls: ["./jump-infos.component.css"],
    imports: [
        TranslateModule,
        FormsModule,
        MatCheckboxModule,
        MatFormFieldModule,
        ReactiveFormsModule,
        MatInputModule,
        MatButtonModule,
    ],
})
export class JumpInfosComponent implements OnInit {
    public editMode: boolean;
    public jump: JumpResp;

    constructor(
        @Inject(MAT_DIALOG_DATA) public data: any,
        private serviceJump: JumpService,
        private serviceComm: ServiceComm,
    ) {
        this.jump = new JumpResp(data.jump);
        this.editMode = data.editMode;
    }

    ngOnInit(): void {}

    public updateJump() {
        this.serviceJump
            .updateJump(
                this.jump.id,
                this.jump.isSpecial,
                this.jump.withCutaway,
                this.jump.notes,
            )
            .subscribe(() => {
                this.serviceComm.refreshData(AddAction.Jump);
            });
    }
}
