import GeoJSON from "ol/format/GeoJSON";
import { get } from "ol/proj";
import { register } from "ol/proj/proj4";
import { XYZ } from "ol/source";
import VectorSource from "ol/source/Vector";
import proj4 from "proj4";
proj4.defs('EPSG:3395', '+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs')
register(proj4);

const yandexProjection = get('EPSG:3395')?.setExtent([-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244]) || 'EPSG:3395'

const googleMapsSatelliteSource = new XYZ({
    url: `${import.meta.env.VITE_API_EMS_URL}/tiles/tile/google/{z}/{x}/{y}`,
    attributions: 'Map data © Google'
})

const yandexMapsSatelliteSource = new XYZ({
    url: `${import.meta.env.VITE_API_EMS_URL}/tiles/tile/yandex/{z}/{x}/{y}`,
    attributions: 'Map data © Yandex',
    projection: yandexProjection,
})

const customMapSource = new XYZ({
    url: `${import.meta.env.VITE_API_EMS_URL}/tiles/tile/custom/{z}/{x}/{y}`,
    attributions: 'Custom map data'
})

const regionsLayerSource = new VectorSource({
    url: 'sakha_republic.geojson',
    format: new GeoJSON(),
})

export {
    googleMapsSatelliteSource,
    yandexMapsSatelliteSource,
    regionsLayerSource,
    customMapSource
}