"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _components = require("@vtx/components");
require("./style");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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; }
function InfoCollection(props) {
  var _props$data = props.data,
    data = _props$data === void 0 ? [] : _props$data,
    _props$width = props.width,
    width = _props$width === void 0 ? '100%' : _props$width,
    _props$gap = props.gap,
    gap = _props$gap === void 0 ? 8 : _props$gap,
    _props$horizontal = props.horizontal,
    horizontal = _props$horizontal === void 0 ? false : _props$horizontal,
    _props$ellipsis = props.ellipsis,
    ellipsis = _props$ellipsis === void 0 ? false : _props$ellipsis,
    padding = props.padding,
    style = props.style,
    isValueCenter = props.isValueCenter,
    _props$labelStyle = props.labelStyle,
    labelStyle = _props$labelStyle === void 0 ? {} : _props$labelStyle;
  if (!data.length) return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null);
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: horizontal ? 'info-collection-horizontal' : 'info-collection',
    style: Object.assign(Object.assign({}, style), {
      padding: padding !== null && padding !== void 0 ? padding : 'unset'
    })
  }, data.map(function (item) {
    var _a;
    var style = {};
    if (item === null || item === void 0 ? void 0 : item.color) style.color = item.color;
    return /*#__PURE__*/_react["default"].createElement("div", {
      className: "info-line",
      key: item.key,
      style: {
        marginRight: horizontal ? 0 : 12,
        marginBottom: gap,
        alignItems: isValueCenter ? 'center' : 'unset',
        width: item.isAddress || ['address', 'divisionName', 'accUnitName', 'manageUnitName', 'description', 'panoramaLinkAddress'].includes(item.key) || item.key.indexOf('hoto') > -1 || ['MAP', 'GD_ENTRANCE'].includes(item.componentType || '') ? '100%' : width
      }
    }, /*#__PURE__*/_react["default"].createElement("div", {
      className: "info-label-b",
      style: labelStyle
    }, /*#__PURE__*/_react["default"].createElement("div", {
      title: item.label,
      className: "ellipsis info-label-b-text"
    }, item.label, " \uFF1A")), item.label === '地址' || item.isAddress ? (/*#__PURE__*/_react["default"].createElement("div", {
      className: "value",
      style: style,
      title: item.value || ''
    }, item.value || '-')) : item.key === 'panoramaLinkAddress' ? (/*#__PURE__*/_react["default"].createElement("div", {
      className: 'value'
    }, ((_a = item === null || item === void 0 ? void 0 : item.value) === null || _a === void 0 ? void 0 : _a.indexOf('http')) > -1 ? (/*#__PURE__*/_react["default"].createElement("a", {
      onClick: function onClick() {
        window.open(item.value);
      }
    }, item.value)) : item.value || '-')) : (/*#__PURE__*/_react["default"].createElement("div", {
      className: "value ".concat(ellipsis ? 'ellipsis' : ''),
      style: style,
      title: ValueDom(item.componentType || '', item.value, true)
    }, typeof item.render === 'function' ? item.render() : ValueDom(item.componentType || '', item.value))));
  }));
}
var _default = exports["default"] = InfoCollection;
var QUARTER_MAP = {
  '01': 'Q1',
  '04': 'Q2',
  '07': 'Q3',
  '10': 'Q4'
};
/* eslint-disable no-case-declarations */
var ValueDom = function ValueDom(componentType, value, isTitle) {
  var _a, _b;
  if (isTitle) {
    return '';
  }
  var node;
  switch (componentType) {
    case 'MONTH_PERIOD':
      node = (_a = value.join) === null || _a === void 0 ? void 0 : _a.call(value, '~');
      break;
    case 'QUARTER':
      var _value$split = value.split('-'),
        _value$split2 = _slicedToArray(_value$split, 2),
        year = _value$split2[0],
        quarter = _value$split2[1];
      node = "".concat(year, "-").concat(QUARTER_MAP[quarter]);
      break;
    case 'ATTACHS':
      var files = JSON.parse(value || '[]');
      if (files.length) {
        node = /*#__PURE__*/_react["default"].createElement(_components.VtxUpload, {
          name: "file",
          viewMode: true,
          fileList: files,
          downloadUrl: "".concat(process.env.PREFIX || '', "/cloudFile/common/downloadFile?id=")
        });
      } else {
        node = '-';
      }
      break;
    case 'MAP':
      var lngLats = (value === null || value === void 0 ? void 0 : value.lngLats) || '';
      node = lngLats;
      break;
    case 'SWITCH':
      node = value || (value ? '是' : '否');
      break;
    case 'GARBAGE_CAN':
      var arr = [];
      Array.isArray(value) && (value === null || value === void 0 ? void 0 : value.forEach(function (item) {
        arr.push("".concat(item.garbageTypeName, "x").concat(item.throwDoorCount));
      }));
      node = arr;
      break;
    case 'TIME_PERIOD':
      if (Array.isArray(value)) {
        node = (_b = value === null || value === void 0 ? void 0 : value.map(function (item) {
          return "".concat(item.startTime, "~").concat(item.endTime);
        })) === null || _b === void 0 ? void 0 : _b.join('；');
      }
      break;
    case 'IMAGE':
      var photos = value ? JSON.parse(value || '[]') : [];
      if (photos.length) {
        node = /*#__PURE__*/_react["default"].createElement(_components.VtxUpload, {
          name: "file",
          viewMode: true,
          useThumbnail: true,
          listType: 'picture-card',
          fileList: photos,
          flag: Math.random() * 100,
          headers: {
            authorization: 'authorization-text'
          },
          downloadUrl: "".concat(process.env.PREFIX || '', "/cloudFile/common/downloadFile?id="),
          previewUrl: "".concat(process.env.PREFIX || '', "/cloudFile/common/downloadFile?id=")
        });
      } else {
        node = '-';
      }
      break;
    case 'qrCode':
      node = /*#__PURE__*/_react["default"].createElement(_components.VtxImage, {
        aspectFit: true,
        src: value
      });
      break;
    case 'GD_ENTRANCE':
      node = /*#__PURE__*/_react["default"].createElement("div", null, value === null || value === void 0 ? void 0 : value.map(function (item, index) {
        var _a, _b;
        return /*#__PURE__*/_react["default"].createElement("div", {
          key: index,
          title: "".concat(item === null || item === void 0 ? void 0 : item.name, "\uFF1A").concat((_a = item === null || item === void 0 ? void 0 : item.location) === null || _a === void 0 ? void 0 : _a.lngLats)
        }, item === null || item === void 0 ? void 0 : item.name, "\uFF1A", (_b = item === null || item === void 0 ? void 0 : item.location) === null || _b === void 0 ? void 0 : _b.lngLats);
      }));
      break;
    default:
      node = value;
      break;
  }
  return node || '-';
};
//# sourceMappingURL=index.js.map
