// resume-filter.component.ts
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { Resume } from '../models/resume.model';
import { ResumeService } from '../services/resume.service';

@Component({
  selector: 'app-resume-filter',
  standalone: true,
  imports: [CommonModule, FormsModule],
  templateUrl: './resume-filter.html',
  styleUrls: ['./resume-filter.scss']
})
export class ResumeFilter {
  resumes: Resume[] = [];
  filteredResumes: Resume[] = [];
  filters = {
    education: '',
    experience: '',
    status: '',
    search: ''
  };

  constructor(private resumeService: ResumeService) {
    this.resumes = this.resumeService.getResumes();
    this.filteredResumes = [...this.resumes];
  }

  applyFilters() {
    this.filteredResumes = this.resumes.filter(resume => {
      return (
        (this.filters.education === '' || resume.education === this.filters.education) &&
        (this.filters.experience === '' || resume.experience >= +this.filters.experience) &&
        (this.filters.status === '' || resume.status === this.filters.status) &&
        (this.filters.search === '' || 
         resume.name.toLowerCase().includes(this.filters.search.toLowerCase()) ||
         resume.position.toLowerCase().includes(this.filters.search.toLowerCase()))
      );
    });
  }

  updateStatus(resume: Resume, status: 'pending' | 'approved' | 'rejected') {
    resume.status = status;
    this.applyFilters();
  }
}