function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { defaults as defaultInteractions } from "ol/interaction";
import OLMap from "ol/Map";
import DragPan from "ol/interaction/DragPan";
import { loadI18n } from "../../i18n";
import DblClickDragZoom from "../../ol/interaction/DblClickDragZoom";
import DblPointerClickZoomOut from "../../ol/interaction/DblPointerClickZoomOut";
import { SET_TOPICS, SET_ACTIVE_TOPIC, SET_FEATURE_INFO, SET_LANGUAGE, SET_PROJECTION, SET_MENU_OPEN, SET_SEARCH_OPEN, SET_SELECTED_FOR_INFOS, SET_DIALOG_VISIBLE, SET_DIALOG_POSITION, SET_DEPARTURES_FILTER, SET_SEARCH_SERVICE, SET_PERMISSION_INFOS, SET_SCREEN_DIMENSIONS, SET_MAPSET_URL, SET_DRAW_URL, SET_DRAW_IDS, SET_SHORTENER_URL, SET_DRAW_EDIT_LINK_LOADING, SET_DRAW_EDIT_LINK, SET_DESTINATION_URL, SET_DEPARTURES_URL, SET_API_KEY, SET_CARTARO_URL, SET_SHOW_POPUPS, SET_ENABLE_TRACKING, SET_CONSENT_GIVEN, SET_EMBEDDED, SET_DISABLE_COOKIES, SET_SEARCH_URL, SET_SEARCH_INFO_OPEN, SET_APP_BASE_URL, SET_STATIC_FILES_URL, SET_VECTOR_TILES_URL, SET_LOGIN_URL, SET_VECTOR_TILES_KEY, SET_API_KEY_NAME, SET_REALTIME_URL, SET_REALTIME_KEY, SET_DISPLAY_MENU, SET_STOPS_URL, SET_MAX_CANVAS_SIZE, SET_EXPORT_PRINT_OPTIONS, SET_GEOLOCATING, SET_FOLLOWING, SET_OVERLAY_ELEMENT, SET_LINE_NAME } from "./actions";
import SearchService from "../../components/Search/SearchService";
import { isOpenedByMapset } from "../../utils/redirectHelper";
import { LS_SIZE_KEY } from "../../utils/constants";
import isValidUrl from "../../utils/isValidUrl";
const getInitialState = () => {
  const i18n = loadI18n();
  const dftlInteractions = defaultInteractions({
    altShiftDragRotate: false,
    pinchRotate: false,
    mouseWheelZoom: false
  });

  // It's important to put it before PinchZoom otherwise the pointerdown is stopped by the PinchZoom.
  dftlInteractions.insertAt(0, new DblPointerClickZoomOut());

  // It's important to put it just after DragPan otherwise the interaction also drag the map.
  const index = dftlInteractions.getArray().findIndex(interaction => interaction instanceof DragPan);
  dftlInteractions.insertAt(index + 1, new DblClickDragZoom());
  return {
    i18n,
    t: i18n.t,
    // We set the permission to null instead of a default empty object
    // to know when the request has been done.
    permissionInfos: null,
    topics: [],
    featureInfo: [],
    language: "de",
    projection: {
      label: "WGS 84",
      value: "EPSG:4326",
      format: c => c
    },
    dialogPosition: {
      x: 390,
      y: 110
    },
    // Open the menu when mapset has opened the page.
    menuOpen: isOpenedByMapset(),
    searchOpen: false,
    searchInfoOpen: false,
    selectedForInfos: null,
    map: new OLMap({
      controls: [],
      interactions: dftlInteractions
    }),
    searchService: new SearchService(),
    screenWidth: null,
    drawIds: null,
    destinationUrl: null,
    departuresUrl: null,
    apiKey: null,
    apiKeyName: "key",
    defaultVectorTilesUrl: null,
    showPopups: true,
    embeddded: false,
    consentGiven: false,
    disableCookies: false,
    displayMenu: true,
    maxCanvasSize: localStorage.getItem(LS_SIZE_KEY) && parseFloat(localStorage.getItem(LS_SIZE_KEY)),
    exportPrintOptions: null,
    isGeolocating: false,
    isFollowing: false
  };
};
export default function app() {
  var _action$data, _state$activeTopic;
  let state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getInitialState();
  let action = arguments.length > 1 ? arguments[1] : undefined;
  switch (action.type) {
    case SET_SEARCH_SERVICE:
      return _objectSpread(_objectSpread({}, state), {}, {
        searchService: action.data
      });
    case SET_TOPICS:
      return _objectSpread(_objectSpread({}, state), {}, {
        topics: action.data || []
      });
    case SET_LANGUAGE:
      state.i18n.changeLanguage(action.data);
      return _objectSpread(_objectSpread({}, state), {}, {
        language: action.data,
        t: function () {
          return state.i18n.t(...arguments);
        }
      });
    case SET_PROJECTION:
      return _objectSpread(_objectSpread({}, state), {}, {
        projection: action.data
      });
    case SET_GEOLOCATING:
      // eslint-disable-next-line no-case-declarations
      const statee = _objectSpread(_objectSpread({}, state), {}, {
        isGeolocating: action.data
      });
      if (action.data === true) {
        statee.isFollowing = false;
      }
      return statee;
    case SET_FOLLOWING:
      return _objectSpread(_objectSpread({}, state), {}, {
        isFollowing: action.data
      });
    case SET_FEATURE_INFO:
      return _objectSpread(_objectSpread({}, state), {}, {
        featureInfo: action.data ? [...action.data] : null
      });
    case SET_ACTIVE_TOPIC:
      return _objectSpread(_objectSpread({}, state), {}, {
        activeTopic: action.data,
        vectorTilesUrl: ((_action$data = action.data) === null || _action$data === void 0 ? void 0 : _action$data.vectorTilesUrl) || state.defaultVectorTilesUrl
      });
    case SET_MENU_OPEN:
      return _objectSpread(_objectSpread({}, state), {}, {
        menuOpen: action.data
      });
    case SET_SEARCH_OPEN:
      return _objectSpread(_objectSpread({}, state), {}, {
        searchOpen: action.data
      });
    case SET_SELECTED_FOR_INFOS:
      return _objectSpread(_objectSpread({}, state), {}, {
        dialogVisible: action.data ? "infoDialog" : false,
        selectedForInfos: action.data
      });
    case SET_DIALOG_VISIBLE:
      return _objectSpread(_objectSpread({}, state), {}, {
        dialogVisible: action.data,
        selectedForInfos: null
      });
    case SET_DIALOG_POSITION:
      return _objectSpread(_objectSpread({}, state), {}, {
        dialogPosition: action.data
      });
    case SET_DEPARTURES_FILTER:
      return _objectSpread(_objectSpread({}, state), action.data);
    case SET_PERMISSION_INFOS:
      return _objectSpread(_objectSpread({}, state), {}, {
        permissionInfos: action.data || {
          user: null,
          permissions: []
        }
      });
    case SET_VECTOR_TILES_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid vectorTilesUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        defaultVectorTilesUrl: action.data,
        vectorTilesUrl: ((_state$activeTopic = state.activeTopic) === null || _state$activeTopic === void 0 ? void 0 : _state$activeTopic.vectorTilesUrl) || action.data
      });
    case SET_VECTOR_TILES_KEY:
      return _objectSpread(_objectSpread({}, state), {}, {
        vectorTilesKey: action.data
      });
    case SET_LINE_NAME:
      return _objectSpread(_objectSpread({}, state), {}, {
        lineName: action.data
      });
    case SET_LOGIN_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid loginUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        loginUrl: action.data
      });
    case SET_MAPSET_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid loginUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        mapsetUrl: action.data
      });
    case SET_SHORTENER_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid shortenerUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        shortenerUrl: action.data
      });
    case SET_REALTIME_KEY:
      return _objectSpread(_objectSpread({}, state), {}, {
        realtimeKey: action.data
      });
    case SET_REALTIME_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid realtimeUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        realtimeUrl: action.data
      });
    case SET_DRAW_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid drawUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        drawUrl: action.data
      });
    case SET_CARTARO_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid cartaroUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        cartaroUrl: action.data
      });
    case SET_SEARCH_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid searchUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        searchUrl: action.data
      });
    case SET_SCREEN_DIMENSIONS:
      return _objectSpread(_objectSpread({}, state), {}, {
        screenWidth: action.data.width,
        screenHeight: action.data.height
      });
    case SET_DRAW_IDS:
      return _objectSpread(_objectSpread({}, state), {}, {
        drawIds: action.data
      });
    case SET_DRAW_EDIT_LINK_LOADING:
      return _objectSpread(_objectSpread({}, state), {}, {
        isDrawEditLinkLoading: action.data
      });
    case SET_DRAW_EDIT_LINK:
      return _objectSpread(_objectSpread({}, state), {}, {
        drawEditLink: action.data
      });
    case SET_DESTINATION_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid destinationUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        destinationUrl: action.data
      });
    case SET_DEPARTURES_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid departuresUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        departuresUrl: action.data
      });
    case SET_API_KEY:
      return _objectSpread(_objectSpread({}, state), {}, {
        apiKey: action.data
      });
    case SET_API_KEY_NAME:
      return _objectSpread(_objectSpread({}, state), {}, {
        apiKeyName: action.data
      });
    case SET_SHOW_POPUPS:
      return _objectSpread(_objectSpread({}, state), {}, {
        showPopups: action.data
      });
    case SET_ENABLE_TRACKING:
      return _objectSpread(_objectSpread({}, state), {}, {
        enableTracking: action.data
      });
    case SET_CONSENT_GIVEN:
      return _objectSpread(_objectSpread({}, state), {}, {
        consentGiven: action.data
      });
    case SET_DISABLE_COOKIES:
      return _objectSpread(_objectSpread({}, state), {}, {
        disableCookies: action.data
      });
    case SET_EMBEDDED:
      return _objectSpread(_objectSpread({}, state), {}, {
        embedded: action.data === true
      });
    case SET_SEARCH_INFO_OPEN:
      return _objectSpread(_objectSpread({}, state), {}, {
        searchInfoOpen: action.data
      });
    case SET_APP_BASE_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid appBaseUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        appBaseUrl: action.data
      });
    case SET_STATIC_FILES_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid staticFilesUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        staticFilesUrl: action.data
      });
    case SET_DISPLAY_MENU:
      return _objectSpread(_objectSpread({}, state), {}, {
        displayMenu: action.data
      });
    case SET_STOPS_URL:
      if (!isValidUrl(action.data)) {
        // eslint-disable-next-line no-console
        console.warn("Invalid stopsUrl:", action.data);
        return state;
      }
      return _objectSpread(_objectSpread({}, state), {}, {
        stopsUrl: action.data
      });
    case SET_MAX_CANVAS_SIZE:
      return _objectSpread(_objectSpread({}, state), {}, {
        maxCanvasSize: action.data
      });
    case SET_EXPORT_PRINT_OPTIONS:
      return _objectSpread(_objectSpread({}, state), {}, {
        exportPrintOptions: action.data
      });
    case SET_OVERLAY_ELEMENT:
      return _objectSpread(_objectSpread({}, state), {}, {
        overlayElement: action.data
      });
    default:
      return _objectSpread({}, state);
  }
}
//# sourceMappingURL=reducers.js.map