"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.TDBViewGeoCollections = void 0;
var _react = _interopRequireDefault(require("react"));
var _reactLeaflet = require("react-leaflet");
var CONST = _interopRequireWildcard(require("../constants"));
var _map = require("../mapComponents/map.constants");
var _utils = require("../utils");
var _Stack = _interopRequireDefault(require("react-bootstrap/Stack"));
var _LabelComponent = require("../components/LabelComponent");
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
var TDBViewGeoCollections = function TDBViewGeoCollections(_ref) {
  var formData = _ref.formData,
    property = _ref.property,
    label = _ref.label,
    required = _ref.required,
    id = _ref.id;
  //if(!formData.hasOwnProperty(property)) return <div/>
  //if(!Array.isArray(formData[property])) return <div/>

  var mapVectors = [];
  var lineColor = {
    color: 'black'
  };
  var center = _map.MAP_OPTION.center;
  var zoom = _map.MAP_OPTION.zoom;
  var bounds = (0, _utils.setBounds)(formData);
  function getInternals(data) {
    var vectors = [];
    data.map(function (geo) {
      if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.POINT && geo.hasOwnProperty("coordinates")) {
        vectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Marker, {
          position: geo["coordinates"],
          icon: CONST["default"]
        }, /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Popup, null, /*#__PURE__*/_react["default"].createElement("span", null, "lat: ".concat(geo["coordinates"][0], ", lng: ").concat(geo["coordinates"][1])))));
      } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.LINE_STRING_TYPE && geo.hasOwnProperty("coordinates")) {
        vectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polyline, {
          pathOptions: lineColor,
          positions: geo["coordinates"]
        }));
      } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.POLYGON && geo.hasOwnProperty("coordinates")) {
        vectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polygon, {
          pathOptions: lineColor,
          positions: geo["coordinates"]
        }));
      } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.MULTIPOLYGON && geo.hasOwnProperty("coordinates")) {
        vectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polygon, {
          pathOptions: lineColor,
          positions: geo["coordinates"]
        }));
      }
    });
    return vectors;
  }
  formData.map(function (geo) {
    if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.POINT) {
      mapVectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Marker, {
        position: geo["coordinates"],
        icon: CONST["default"]
      }, /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Popup, null, /*#__PURE__*/_react["default"].createElement("span", null, "lat: ".concat(geo["coordinates"][0], ", lng: ").concat(geo["coordinates"][1])))));
    } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.LINE_STRING_TYPE) {
      mapVectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polyline, {
        pathOptions: lineColor,
        positions: geo["coordinates"]
      }));
    } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.POLYGON) {
      mapVectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polygon, {
        pathOptions: lineColor,
        positions: geo["coordinates"]
      }));
    } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.MULTIPOLYGON) {
      mapVectors.push( /*#__PURE__*/_react["default"].createElement(_reactLeaflet.Polygon, {
        pathOptions: lineColor,
        positions: geo["coordinates"]
      }));
    } else if (geo.hasOwnProperty("@type") && geo["@type"] === CONST.GEOMETRY_COLLECTION) {
      var mapItems = getInternals(geo[CONST.GEOMETRIES]);
      mapVectors.push(mapItems);
    }
  });
  return /*#__PURE__*/_react["default"].createElement(_Stack["default"], {
    direction: "horizontal",
    className: "mb-3"
  }, /*#__PURE__*/_react["default"].createElement(_LabelComponent.TDBLabel, {
    name: label,
    required: required,
    id: id
  }), /*#__PURE__*/_react["default"].createElement(_reactLeaflet.MapContainer, {
    center: center,
    zoom: zoom,
    scrollWheelZoom: true,
    bounds: bounds
  }, /*#__PURE__*/_react["default"].createElement(_reactLeaflet.TileLayer, {
    attribution: "\xA9 <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors",
    url: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
  }), mapVectors));
};
exports.TDBViewGeoCollections = TDBViewGeoCollections;