import { useDzkhFilters } from "../../stores/useDzkhFilters.js";
import { useWeatherFilter } from "../WeatherSlider/useWeatherFilter.js";
import { tempMapper } from "../../config.js";

export const useConsumerLayerFilterExpression = () => {
  const {consumer_filter, consumer_type, energy_class, wall_material} = useDzkhFilters();
  const {value: temperature} = useWeatherFilter();
  const t = tempMapper[temperature]
  const consumerFilterExpression = () => {
    const res = [];
    if (consumer_filter) {
      const key = `${consumer_filter.key}_${t}`;

      res.push(
        ...[
          [">=", ["get", key], consumer_filter.gt],
          ["<=", ["get", key], consumer_filter.lt],
        ]
      )
    }
    if (consumer_type) {
      res.push(["==", ["get", "potreb_type"], consumer_type.value]);
    }
    if (energy_class) {
      res.push(["==", ["get", "fi_energy_class"], energy_class.value]);
    }
    if (wall_material) {
      res.push(["==", ["get", "wall_materials"], wall_material.value]);
    }
    return res;
  }

  return [
    ...consumerFilterExpression()
  ]
}
