import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { FormsModule } from '@angular/forms';
import { Router, ActivatedRoute, RouterModule } from '@angular/router';
import { Title } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { Authentication } from 'app/services/Authentication';
import { Company, Employee } from 'app/models/Company';

@Component({
  selector: 'main-company',
  templateUrl: './company.component.html',
  styleUrls: [ './company.component.css' ],
  imports: [ FormsModule, CommonModule, RouterModule ]
})
export class CompanyComponent {
  public ErrorMsg: string = "";

  public Employers: Employee[] = [];
  public Comp: Company | null = null;

  constructor( private http: HttpClient, private router: Router, private route: ActivatedRoute, private title: Title, public auth: Authentication  ) {
    this.title.setTitle("Companies | BoredCareers");
    http.get<Employee[]>("api/employee/").subscribe({
      next: data => {
        this.Employers = data;
      },
      error: err => {
        this.ErrorMsg = err.error;
      }
    });

  };

  changeSelectedCompany(companyID: number){
    this.http.get<Company>("api/company?CompanyID=" + companyID).subscribe({
      next: data => {
        this.Comp = data;
      },
      error: err => {
        this.ErrorMsg = err.error;
      }
    });
  }

}