// company-profile.component.ts
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Company } from '../models/company.model';
import { CompanyService } from '../services/company.service';

@Component({
  selector: 'app-company-profile',
  standalone: true,
  imports: [CommonModule, FormsModule],
  templateUrl: './company-profile.html',
  styleUrls: ['./company-profile.scss']
})
export class CompanyProfile {
  company: Company;
  isEditing = false;
  newJob = { title: '', description: '', requirements: '' };

  constructor(private companyService: CompanyService) {
    this.company = this.companyService.getCompany();
  }

  toggleEdit() {
    this.isEditing = !this.isEditing;
    if (!this.isEditing) {
      this.companyService.updateCompany(this.company);
    }
  }

  addJob() {
    if (this.newJob.title && this.newJob.description) {
      this.company.jobOpenings.push({...this.newJob});
      this.newJob = { title: '', description: '', requirements: '' };
      this.companyService.updateCompany(this.company);
    }
  }

  removeJob(index: number) {
    this.company.jobOpenings.splice(index, 1);
    this.companyService.updateCompany(this.company);
  }
}