import type VectorTileSource from "ol/source/VectorTile";

export const getLoadedVectorTiles = (source: VectorTileSource): any[] => {
  const sourceTiles = (source as any).sourceTiles_;
  if (!sourceTiles) return [];
  return sourceTiles instanceof Map
    ? Array.from(sourceTiles.values())
    : Object.values(sourceTiles);
};

export const getVectorTileFeatureProperties = (
  feature: any,
): Record<string, any> =>
  feature.properties_ ?? feature.getProperties?.() ?? {};

export const getVectorTileFeatureId = (feature: any): string | null => {
  const properties = getVectorTileFeatureProperties(feature);
  const id =
    feature.get?.("id") ??
    feature.get?.("ID") ??
    properties.id ??
    properties.ID;
  return id === undefined || id === null || id === "" ? null : String(id);
};
