"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TDBFeatureCollectionDocuments = void 0;
var _react = _interopRequireWildcard(require("react"));
var _Stack = _interopRequireDefault(require("react-bootstrap/Stack"));
var _reactLeafletFullscreen = require("react-leaflet-fullscreen");
require("react-leaflet-fullscreen/dist/styles.css");
var _LabelComponent = require("../components/LabelComponent");
var _reactUuid = _interopRequireDefault(require("react-uuid"));
require("leaflet-arrowheads");
var _leaflet = _interopRequireDefault(require("leaflet"));
var CONST = _interopRequireWildcard(require("../constants"));
var _map = require("./map.constants");
var _markers = require("./markers");
var util = _interopRequireWildcard(require("../utils"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var TDBFeatureCollectionDocuments = function TDBFeatureCollectionDocuments(_ref) {
  var config = _ref.config;
  var mapRef = (0, _react.useRef)(null);
  var mapID = (0, _reactUuid["default"])();
  var map = function map() {
    var zoom = _map.MAP_OPTION.zoom;
    //let bounds=util.setBounds(config.documents.hasOwnProperty(CONST.B_BOX) ? config.documents[CONST.B_BOX] : [])

    var mapOptions = (0, _markers.customMapOptions)(zoom, null);
    var markerOptions = (0, _markers.customMarkerOptions)(CONST["default"]);
    var map = _leaflet["default"].map("tdb__map__geojson__leaflet_".concat(mapID), mapOptions); //mapOptions
    var tileLayer = new _leaflet["default"].tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
      attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
    });
    tileLayer.addTo(map);
    var geoJSON = _leaflet["default"].geoJSON(config.formData, {
      pointToLayer: function pointToLayer(feature, latlng) {
        return _leaflet["default"].marker(latlng, markerOptions);
      }
    }).bindPopup(function (layer) {
      return layer.feature.properties.description;
    }).addTo(map);
    window.map = map;
    map.fitBounds(geoJSON.getBounds());
    setTimeout(function () {
      return map.invalidateSize(true);
    }, 2000);
  };
  (0, _react.useEffect)(function () {
    if (mapRef) {
      map();
    }
  }, [mapRef]);
  return /*#__PURE__*/_react["default"].createElement(_Stack["default"], {
    direction: "horizontal",
    className: "mb-3"
  }, /*#__PURE__*/_react["default"].createElement(_LabelComponent.TDBLabel, {
    name: config.label ? config.label : config.name,
    required: config.required,
    id: config.id
  }), /*#__PURE__*/_react["default"].createElement("div", {
    ref: mapRef,
    id: "tdb__map__geojson__leaflet_".concat(mapID),
    className: "rounded",
    "data-testid": "map-leaflet-id"
  }));
};
exports.TDBFeatureCollectionDocuments = TDBFeatureCollectionDocuments;