import { Component, OnInit } from '@angular/core';
import {Crop, Keyword, Language, Pest, Project, Region, Resource, ResourceType, Sector} from "../../model/resource";
import {ResourceService} from "../../service/resource.service";
import {Message} from "primeng/api";
import {environment} from "../../../environments/environment";
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  resources: Resource[] = [];
  sectors: Sector[] = [];
  regions: Region[] = [];
  projects: Project[] = [];
  crops:Crop[] = [];
  pests: Pest[] = [];
  pestType: object[] = [{name:"weeds"}, {name:"disease"},{name:"invertebrate"}];
  contentTypes: ResourceType[] = [];
  languages: Language[] = [];
  keywords: Keyword[] = [];
  disclaimer: Message[] = [];
  selectedSectors: Sector[] = [];
  selectedRegions: Region[] = [];
  selectedTypes: ResourceType[] = [];
  selectedLanguages: Language[] = [];
  selectedProjects: Project[] = [];
  selectedCrops: Crop[] = [];
  selectedPests:Pest[] = [];
  selectedPestType: string | undefined;

  searchTerm: string = "";
  more= false;
  imagePath = environment.baseUrl+"/resource/image";

  constructor(private resourceService:ResourceService) { }

  ngOnInit(): void {
    this.resourceService.getAllProjects().subscribe((projects: Project[]) => {
      this.projects = projects;});
    this.resourceService.getAllSectors().subscribe((sectors: Sector[]) => {
      this.sectors = sectors;});
    this.resourceService.getAllRegions().subscribe((regions: Region[]) => {
      this.regions = regions;});
    this.resourceService.getAllResourceTypes().subscribe((contentTypes: ResourceType[]) => {
      this.contentTypes = contentTypes;});
    this.resourceService.getAllLanguages().subscribe((languages: Language[]) => {
      this.languages = languages;});
    this.resourceService.getAllPests().subscribe((pests: Pest[]) => {
      this.pests = pests;});
    this.resourceService.getAllCrops().subscribe((crops: Crop[]) => {
      this.crops = crops;});
    this.resourceService.getAllResources().subscribe((resources: Resource[]) => {
      this.resources = resources;});
    this.disclaimer = [{severity:"info", summary:"Disclaimer", detail:"This IPMWORKS Resource Toolbox is a repository for IPM resource developed by the EU IPMWORKS project (101000339). The cooperating partners have no economic responsibility whatsoever for losses due to using this service."}];
    }

    public toggleFilters(){
    //kada se zatvore dodatni filteri isprazniti ako je nesto bilo selektovano u tim filterima
    this.more = !this.more;
    }
}
