"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["default"] = void 0;

var _components = require("@vtx/components");

var _antd = require("antd");

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _vtxGasEnterpriseModal = _interopRequireDefault(require("../vtx-gas-enterprise-modal"));

var _vtxGasFillingStationModal = _interopRequireDefault(require("../vtx-gas-filling-station-modal"));

var _api = require("./api");

var _map = require("@vtx/map");

var _useMapInfo2 = _interopRequireDefault(require("../vm-hooks/useMapInfo"));

var _useSettings2 = _interopRequireDefault(require("../vm-hooks/useSettings"));

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; }

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }

function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }

function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

var BaseContent = function BaseContent(props) {
  var id = props.id;

  var _useState = (0, _react.useState)({}),
      _useState2 = _slicedToArray(_useState, 2),
      info = _useState2[0],
      setInfo = _useState2[1];

  var _useState3 = (0, _react.useState)([]),
      _useState4 = _slicedToArray(_useState3, 2),
      fieIds = _useState4[0],
      setFieIds = _useState4[1];

  var _useMapInfo = (0, _useMapInfo2["default"])(),
      mapInfo = _useMapInfo.mapInfo;

  (0, _react.useEffect)(function () {
    (0, _api.getFieIds)().then(function (data) {
      setFieIds(data);
    });

    if (id) {
      (0, _api.getInfo)(id).then(function (data) {
        setInfo(data);
      });
    }
  }, [id]);
  var name = info.name,
      address = info.address,
      divisionName = info.divisionName,
      buildDate = info.buildDate,
      description = info.description,
      dataJson = info.dataJson;

  var _useSettings = (0, _useSettings2["default"])(),
      theme = _useSettings.theme;

  return /*#__PURE__*/_react["default"].createElement(_antd.Form, {
    layout: "inline"
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout, {
    mode: "view",
    cols: 3
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.Pane, {
    title: "\u57FA\u672C\u4FE1\u606F"
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
    label: "\u4F9B\u5E94\u7AD9\u540D\u79F0"
  }, name || '--'), /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
    label: "\u884C\u653F\u533A\u5212"
  }, divisionName || '--'), /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
    label: "\u5EFA\u7AD9\u65F6\u95F4"
  }, buildDate || '--'), /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
    label: "\u5730\u5740"
  }, address || '--'), fieIds.map(function (fieId) {
    var showName = fieId.showName,
        showKey = fieId.showKey,
        key = fieId.key,
        type = fieId.component.type;
    var element = dataJson && dataJson[showKey];

    if (type === 'IMAGE') {
      var _id = '';

      if (dataJson && dataJson[showKey]) {
        var _JSON$parse$;

        _id = (_JSON$parse$ = JSON.parse(dataJson[showKey])[0]) === null || _JSON$parse$ === void 0 ? void 0 : _JSON$parse$.id;
      }

      element = _id ? /*#__PURE__*/_react["default"].createElement(_components.VtxImage, {
        src: "/cloudFile/common/downloadFile?id=".concat(_id),
        style: {
          width: '200px',
          height: '200px'
        }
      }) : '--';
    }

    if (type === 'MAP') {
      var _dataJson$showKey;

      var _ref = [],
          lng = _ref[0],
          lat = _ref[1];

      if (dataJson && (_dataJson$showKey = dataJson[showKey]) !== null && _dataJson$showKey !== void 0 && _dataJson$showKey.lngLats) {
        var _dataJson$showKey2;

        var _dataJson$showKey$lng = (_dataJson$showKey2 = dataJson[showKey]) === null || _dataJson$showKey2 === void 0 ? void 0 : _dataJson$showKey2.lngLats.split(',');

        var _dataJson$showKey$lng2 = _slicedToArray(_dataJson$showKey$lng, 2);

        lng = _dataJson$showKey$lng2[0];
        lat = _dataJson$showKey$lng2[1];
      }

      element = lng && lat && /*#__PURE__*/_react["default"].createElement("div", {
        style: {
          width: '100%',
          height: 200
        }
      }, /*#__PURE__*/_react["default"].createElement(_map.VtxMap, {
        mapId: "supplyStation",
        mapType: mapInfo.mapType,
        mapCenter: [lng, lat],
        mapZoomLevel: 15,
        mapPoints: [{
          id: '1',
          longitude: lng,
          latitude: lat
        }],
        mapStyle: theme === 'dark' ? theme : ''
      }));
    }

    if (showName.includes('企业')) {
      element = /*#__PURE__*/_react["default"].createElement(_vtxGasEnterpriseModal["default"], {
        label: element,
        id: dataJson && dataJson[key]
      });
    } else if (showName.includes('储配站')) {
      element = /*#__PURE__*/_react["default"].createElement(_vtxGasFillingStationModal["default"], {
        label: element,
        id: dataJson && dataJson[key]
      });
    }

    return /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
      label: showName,
      key: showKey,
      weights: type === 'MAP' ? 3 : 1
    }, element || '--');
  }), /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
    label: "\u5907\u6CE8",
    weights: 3
  }, description))));
};

BaseContent.propTypes = {
  id: _propTypes["default"].string.isRequired,
  name: _propTypes["default"].string.isRequired
};
var _default = BaseContent;
exports["default"] = _default;
//# sourceMappingURL=base.js.map
