import { Layer } from "react-map-gl";
import { approvePointLayer } from "./layers-config";
import { useLayersVisibility } from "../../stores/useLayersVisibility";
import { STATUSES } from "../../config";
import { useRegionFilterExpression } from "./useRegionFilterExpression";
import { LAYER_IDS } from "./constants";

const statusExpression = ["==", ["get", "status"], STATUSES.approve];

export const ApprovePoints = () => {
  const { isVisible } = useLayersVisibility();
  const regionFilterExpression = useRegionFilterExpression();

  const filter = regionFilterExpression
    ? ["all", statusExpression, regionFilterExpression]
    : statusExpression;

  return (
    <>
      <Layer
        {...approvePointLayer}
        id={LAYER_IDS.approve}
        source={"points"}
        source-layer={"public.service_placementpoint"}
        layout={{
          visibility: isVisible[LAYER_IDS.approve] ? "visible" : "none",
        }}
        filter={filter}
      />
    </>
  );
};
