"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _ahooks = require("ahooks");
var _components = require("@vtx/components");
var _utils = require("@vtx/utils");
var _uniqBy = _interopRequireDefault(require("lodash/uniqBy"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _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(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
var getFields = function getFields(params) {
  return _utils.request.get('/cloud/jcss-reborn/facility/type/view/detail', {
    data: params
  });
};
var getDetail = function getDetail(params) {
  return _utils.request.get('/cloud/jcss-reborn/facility/get', {
    data: params
  });
};
var Detail = function Detail(props) {
  var id = props.id;
  var _useSetState = (0, _ahooks.useSetState)({
      baseFields: [],
      customFields: [],
      detail: {},
      groupList: [] // 明确指定 groupList 的类型
    }),
    _useSetState2 = _slicedToArray(_useSetState, 2),
    state = _useSetState2[0],
    setState = _useSetState2[1];
  (0, _react.useEffect)(function () {
    getFields({
      code: 'wr'
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
        setState({
          baseFields: res.data.baseFields.filter(function (item) {
            return item.key !== 'photoIds' && item.key !== 'panoramaLinkAddress' && item.key !== 'geometryInfo';
          }),
          customFields: res.data.customFields.map(function (item) {
            return Object.assign(Object.assign({}, item), {
              groupCode: item.groupCode || 'detail',
              groupName: item.groupName || '详细信息'
            });
          })
        });
      }
    });
    if (id) {
      getDetail({
        id: id,
        coordType: 'bd09'
      }).then(function (res) {
        if ((res === null || res === void 0 ? void 0 : res.result) === 0) {
          setState({
            detail: Object.assign(Object.assign({}, res.data), res.data.dataJson)
          });
        }
      });
    }
  }, [id]);
  (0, _react.useEffect)(function () {
    var _a;
    if ((_a = state.customFields) === null || _a === void 0 ? void 0 : _a.length) {
      var list = (0, _uniqBy["default"])(state.customFields.map(function (item) {
        return {
          id: item.groupCode,
          name: item.groupName
        };
      }), 'name');
      setState({
        groupList: list.map(function (item) {
          return Object.assign(Object.assign({}, item), {
            list: state.customFields.filter(function (each) {
              return each.groupName === item.name;
            })
          });
        })
      });
    }
  }, [state.customFields]);
  return /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout, {
    mode: "view",
    cols: 3,
    card: true
  }, /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.Card, {
    title: "\u57FA\u672C\u4FE1\u606F"
  }, state.detail.id && state.baseFields.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
      key: item.key,
      label: item.showName
    }, state.detail[item.showKey] || '--');
  })), state.groupList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.Card, {
      key: item.id,
      title: item.name
    }, item.list.map(function (each) {
      var _a, _b, _c, _d;
      return /*#__PURE__*/_react["default"].createElement(_components.VtxFormLayout.FormItem, {
        key: each.key,
        label: each.showName
      }, each.showKey === 'openhour' ? "".concat((_b = (_a = state.detail.openhour) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.startTime, "~").concat((_d = (_c = state.detail.openhour) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.endTime) : state.detail[each.showKey] || '--');
    }));
  }));
};
var _default = exports["default"] = Detail;
//# sourceMappingURL=index.js.map
