import TrafimageMapboxLayer from "../../layers/TrafimageMapboxLayer";
import MapboxStyleLayer from "../../layers/MapboxStyleLayer";
import HighlightRoutesLayer from "../../layers/StsHighlightRoutesLayer";
import DirektverbindungenLayer from "../../layers/DirektverbindungenLayer";
import { DV_HIT_TOLERANCE, DV_KEY, MapsGeltungsbereicheFilter, MapsGeltungsbereicheFilterValues, MapsStsFilter, MapsStsFilterValues, STS_HIT_TOLERANCE, SWISS_EXTENT } from "../../utils/constants";
import { DV_DAY_LAYER_KEY, DV_NIGHT_LAYER_KEY, getDirektverbindungenLayers } from "../ch.sbb.direktverbindungen";
const FILTER_KEY = MapsStsFilter;
const FILTER_GTTOS_VALUE = MapsStsFilterValues.STS_GTTOS;
const FILTER_HIGHLIGHT_VALUE = MapsStsFilterValues.STS_HIGHLIGHT;
const FILTER_OTHERS_VALUE = MapsStsFilterValues.STS_OTHERS;
const FILTER_LINE_VALUE = MapsGeltungsbereicheFilterValues.STS_LINE; // style using nova daten

const STS_VALIDITY_DATA_LAYER_KEY = "ch.sbb.sts.validity.data";
const STS_DIREKTVERBINDUNGEN_DATA_LAYER_KEY = "ch.sbb.direktverbindungen.data";
export const ROUTES_HIGHLIGHT_LAYER_KEY = "ch.sbb.sts.validity.routes_highlight";
const STS_HIDDEN_ROUTES_LAYER_KEY = "ch.sbb.sts.validity.hidden";
export const OTHER_LAYER_KEY = "ch.sbb.sts.validity.other";
export const GTTOS_LAYER_KEY = "ch.sbb.sts.validity.gttos";

// eslint-disable-next-line import/prefer-default-export
export const getStsLayers = () => {
  const dvLayers = getDirektverbindungenLayers();
  const dvDay = dvLayers.find(l => l.key === DV_DAY_LAYER_KEY);
  const dvNight = dvLayers.find(l => l.key === DV_NIGHT_LAYER_KEY);
  const stsValidityDataLayer = new TrafimageMapboxLayer({
    name: STS_VALIDITY_DATA_LAYER_KEY,
    key: STS_VALIDITY_DATA_LAYER_KEY,
    visible: true,
    preserveDrawingBuffer: false,
    zIndex: -1,
    // Add zIndex as the MapboxLayer would block tiled layers (buslines)
    style: "basemap_bright_ch.sbb.geltungsbereiche",
    hitTolerance: STS_HIT_TOLERANCE,
    properties: {
      isQueryable: false,
      isBaseLayer: true,
      hideInLegend: true
    }
  });
  const stsDirektverbindungenDataLayer = new TrafimageMapboxLayer({
    name: STS_DIREKTVERBINDUNGEN_DATA_LAYER_KEY,
    key: STS_DIREKTVERBINDUNGEN_DATA_LAYER_KEY,
    visible: false,
    preserveDrawingBuffer: false,
    zIndex: -1,
    // Add zIndex as the MapboxLayer would block tiled layers (buslines)
    style: "basemap_bright_direktverbindungen",
    hitTolerance: DV_HIT_TOLERANCE,
    properties: {
      isQueryable: false,
      isBaseLayer: true,
      hideInLegend: true
    }
  });
  const highlightRoutes = new HighlightRoutesLayer({
    name: "Highlight routes",
    key: ROUTES_HIGHLIGHT_LAYER_KEY,
    mapboxLayer: stsValidityDataLayer,
    visible: true,
    styleLayersFilter: _ref => {
      let {
        metadata
      } = _ref;
      return metadata && metadata[FILTER_KEY] === FILTER_HIGHLIGHT_VALUE;
    },
    properties: {
      isQueryable: false,
      disableSetFeatureInfoOnHover: true,
      maxExtent: SWISS_EXTENT,
      minZoom: 8
    }
  });

  // Hide the routes displayed by default like gqa ones
  const hiddenRoutes = new MapboxStyleLayer({
    name: "Hidden routes",
    key: STS_HIDDEN_ROUTES_LAYER_KEY,
    mapboxLayer: stsValidityDataLayer,
    visible: false,
    styleLayersFilter: _ref2 => {
      let {
        metadata,
        id
      } = _ref2;
      return /^gb_Fanas_Bus/.test(id) || !!(metadata && metadata[MapsGeltungsbereicheFilter] && /(hta|ga|tk)\.line/.test(metadata[MapsGeltungsbereicheFilter] || ""));
    },
    properties: {
      isQueryable: true,
      minZoom: 8
    }
  });
  const otherRoutes = new MapboxStyleLayer({
    name: "Other routes",
    key: OTHER_LAYER_KEY,
    mapboxLayer: stsValidityDataLayer,
    visible: true,
    styleLayersFilter: _ref3 => {
      let {
        metadata
      } = _ref3;
      return metadata && (metadata[FILTER_KEY] === FILTER_OTHERS_VALUE || metadata[MapsGeltungsbereicheFilter] && metadata[MapsGeltungsbereicheFilter].includes(FILTER_LINE_VALUE));
    },
    properties: {
      isQueryable: true,
      disableSetFeatureInfoOnHover: true,
      validPropertyName: "valid_sts",
      getTextFromValid: valid => {
        if (valid === 50) {
          return "50% Ermässigung";
        }
        if (valid === 25) {
          return "25% Ermässigung";
        }
        if (valid === -1) {
          return "Gültigkeit vor Ort erfragen";
        }
        return "Freie Fahrt";
      },
      maxExtent: SWISS_EXTENT,
      minZoom: 8,
      products: ["ch.sbb.geltungsbereiche.products.sts", "ch.sbb.geltungsbereiche.products.sts-half"],
      lineDashArray50: [6, 8],
      lineDashArray25: [6, 8, 1, 8, 1, 8]
    }
  });
  const gttos = new MapboxStyleLayer({
    name: "Grand Train Tour of Switzerland",
    key: GTTOS_LAYER_KEY,
    mapboxLayer: stsValidityDataLayer,
    visible: true,
    styleLayersFilter: _ref4 => {
      let {
        metadata
      } = _ref4;
      return metadata && metadata[FILTER_KEY] === FILTER_GTTOS_VALUE;
    },
    group: "ch.sbb.sts.validity.group",
    properties: {
      isQueryable: true,
      disableSetFeatureInfoOnHover: true,
      maxExtent: SWISS_EXTENT,
      minZoom: 8
    }
  });
  const stsDvDay = dvDay.clone({
    mapboxLayer: stsDirektverbindungenDataLayer,
    visible: false
  });
  const stsDvNight = dvNight.clone({
    mapboxLayer: stsDirektverbindungenDataLayer,
    visible: false
  });
  const stsDvMain = new DirektverbindungenLayer({
    visible: false,
    name: "".concat(DV_KEY, ".main"),
    key: "".concat(DV_KEY, ".main"),
    mapboxLayer: stsDirektverbindungenDataLayer,
    properties: {
      isQueryable: true,
      hideInLegend: true,
      dayLayer: stsDvDay,
      nightLayer: stsDvNight,
      popupComponent: "DvPopup",
      useOverlay: true,
      priorityFeatureInfo: true,
      // This property will block display of others featureInfos
      highlightPointFeatureFilter: () => false
    }
  });
  return [stsValidityDataLayer, stsDirektverbindungenDataLayer, hiddenRoutes, otherRoutes, highlightRoutes, gttos, stsDvMain, stsDvDay, stsDvNight];
};
//# sourceMappingURL=index.js.map