import { Component, OnInit } from '@angular/core';
import {Keyword, Language, 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[] = [];
  contentTypes: ResourceType[] = [];
  languages: Language[] = [];
  keywords: Keyword[] = [];
  disclaimer: Message[] = [];
  selectedSectors: Sector[] = [];
  selectedRegions: Region[] = [];
  selectedTypes: ResourceType[] = [];
  selectedLanguages: Language[] = [];
  selectedKeywords: Keyword[] = [];
  selectedProjects: Project[] = [];

  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.getAllKeywords().subscribe((keywords: Keyword[]) => {
      this.keywords = keywords;})
    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;
    }
}
