import { Component } from "@angular/core";
import { CommonModule } from "@angular/common";
import { BaseCrudComponent } from "src/app/cores/class-templates/base-crud.component";
import {
  Laporan,
  LaporanService,
} from "src/app/cores/api-services/laporan/laporan.service";
import { HelpersService } from "src/app/cores/services/helpers.service";
import { LoadingService } from "src/app/cores/services/loading.service";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { Router } from "@angular/router";
import { AuthService } from "src/app/cores/services/auth.service";

@Component({
  selector: "laporan-baru",
  standalone: true,
  imports: [CommonModule],
  templateUrl: "./laporan-baru.component.html",
  styleUrls: ["./laporan-baru.component.scss"],
})
export class LaporanBaruComponent extends BaseCrudComponent<Laporan> {
  constructor(
    private router: Router,
    protected auth: AuthService,
    public override modal: NgbModal,
    public override helpers: HelpersService,
    public override api: LaporanService,
    public override loading: LoadingService
  ) {
    super(helpers, loading, api, modal);
    this.queries = {
      page: 1,
      limit: 3,
      sort: "-created_at",
      embed: "status_report,user,segmens,segmens.segmen,segmens.photos",
    };
    if (this.auth.getLoggedUser().role.code == "SADM") {
    } else if (this.auth.getLoggedUser().role.code == "PNGL") {
      this.queries.filter = { status_id: { ne: `PROG,RJT` } };
    } else {
      this.api.endpoint = `report-list/surveyor/${auth.getLoggedUser().id}`;
    }
  }

  goToDetail(id: string) {
    if (this.auth.getLoggedUser().role.code === "SVEI") {
      this.router.navigate([
        "dashboard",
        "surveyor",
        this.auth.getLoggedUser().id,
      ]);
    }
    this.router.navigate(["dashboard", "data-laporan", id]);
  }
}
