import { Injectable } from '@angular/core';
import { environments } from '../../environment/environment';
import { HttpClient, HttpParams } from '@angular/common/http';
import { filter, map } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class ImagesService {
  private URL: string = environments.baseUrl;
  constructor(private http: HttpClient) { }

  getImages() {
    return this.http.get(`${this.URL}/tabla`);
  }

  finder(query: string) {
    let params = new HttpParams().set('q', query);
    return this.http.get(`${this.URL}/products/search`, { params });
  }

  getProducts(linea: string | null) {
    linea = linea === "Habitat" ? 'Hábitat' : linea;
    return this.http.get(`${this.URL}/products`).pipe(
      map((products: any) => products.filter((product: any) => product.LINEA === linea))
    );
  }

  findOne(id: string) {
    return this.http.get(`${this.URL}/product/${id}`);
  }

  productFile(submodelo: string) {
    return this.http.get(`${this.URL}/productFile/${submodelo}`);
  }

  getOptions() {
    return this.http.get(`${this.URL}/opciones`);
  }

  getCountries() {
    return this.http.get(`${this.URL}/countries`);
  }

  getStates(id: string) {
    return this.http.get(`${this.URL}/states/${id}`);
  }

  getCategory() {
    return this.http.get(`${this.URL}/categorias`);
  }
  getInfoBanner(cate: any) {
    return this.http.get(`${this.URL}/infobanner/${cate}`);
  }

}
