const _excluded = ["style", "selectedForInfos"];
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
import React from "react";
import PropTypes from "prop-types";
import { useSelector } from "react-redux";
import useTranslation from "../../utils/useTranslation";
import Dialog from "../Dialog";
import layerInfos from "../../layerInfos";
import DataLink from "../DataLink/DataLink";
const propTypes = {
  style: PropTypes.object,
  selectedForInfos: PropTypes.object
};
export const NAME = "infoDialog";
function LayerInfosDialog(_ref) {
  let {
      style,
      selectedForInfos
    } = _ref,
    props = _objectWithoutProperties(_ref, _excluded);
  const language = useSelector(state => state.app.language);
  const staticFilesUrl = useSelector(state => state.app.staticFilesUrl);
  const {
    t
  } = useTranslation();
  if (!selectedForInfos) {
    return null;
  }
  let component = null;
  let description = null;
  let dataLink = null;
  let dataService = null;

  // test if get function exist instead of `instanceof` since the layer may be created
  // outside this bundle.
  if (selectedForInfos.get) {
    component = selectedForInfos.get("layerInfoComponent");
    description = selectedForInfos.get("description");
    dataLink = selectedForInfos.get("dataLink");
    dataService = selectedForInfos.get("dataService");
  } else {
    component = selectedForInfos.layerInfoComponent;
    description = selectedForInfos.description;
  }
  let body;
  const LayerInfoComponent = typeof component === "string" ? layerInfos[component] : component;
  if (component) {
    body = /*#__PURE__*/React.createElement(LayerInfoComponent, {
      language: language,
      properties: selectedForInfos,
      staticFilesUrl: staticFilesUrl,
      t: t
    });
  } else if (description) {
    const translated = t(description);
    body = /*#__PURE__*/React.createElement("div", null, /<.*>/.test(translated) ?
    /*#__PURE__*/
    // eslint-disable-next-line react/no-danger
    React.createElement("p", {
      dangerouslySetInnerHTML: {
        __html: translated
      }
    }) : /*#__PURE__*/React.createElement("p", null, translated), dataLink && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("hr", null), /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(DataLink, {
      layer: selectedForInfos
    }))), dataService && /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement(DataLink, {
      href: "https://geo.sbb.ch/portal/home/group.html?id=4778f8efa0ad41a6829f0094339158e2#overview"
    }, t("Zu den Trafimage-Datensätzen im SBB Geoportal (SBB-intern)"))));
  }
  return /*#__PURE__*/React.createElement(Dialog, _extends({
    cancelDraggable: ".tm-dialog-body",
    name: NAME,
    title: LayerInfoComponent !== null && LayerInfoComponent !== void 0 && LayerInfoComponent.renderTitle ? LayerInfoComponent.renderTitle(selectedForInfos, t) : /*#__PURE__*/React.createElement("span", null, t("".concat(selectedForInfos.name || selectedForInfos.key))),
    body: body,
    style: style
  }, props));
}
LayerInfosDialog.propTypes = propTypes;
export default LayerInfosDialog;
//# sourceMappingURL=LayerInfosDialog.js.map