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); }
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(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(arr) { if (Array.isArray(arr)) return arr; }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { VtxImage, VtxUpload } from '@vtx/components';
import { isNumber } from 'lodash';
import "./style";
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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,
    _props$style = props.style,
    style = _props$style === void 0 ? {} : _props$style,
    isValueCenter = props.isValueCenter,
    _props$labelStyle = props.labelStyle,
    labelStyle = _props$labelStyle === void 0 ? {} : _props$labelStyle;
  if (!data.length) return /*#__PURE__*/_jsx(_Fragment, {});
  return /*#__PURE__*/_jsx("div", {
    className: horizontal ? 'info-collection-horizontal' : 'info-collection',
    style: _objectSpread(_objectSpread({}, style), {}, {
      padding: padding !== null && padding !== void 0 ? padding : 'unset'
    }),
    children: data.map(function (item) {
      var _item$key, _item$value;
      var style = {};
      if (item !== null && item !== void 0 && item.color) style.color = item.color;
      return /*#__PURE__*/_jsxs("div", {
        className: "info-line",
        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 = item.key) === null || _item$key === void 0 ? void 0 : _item$key.indexOf('hoto')) > -1 || ['MAP', 'GD_ENTRANCE'].includes(item.componentType || '') ? '100%' : item.width || width
        },
        children: [/*#__PURE__*/_jsx("div", {
          className: "info-label-b",
          style: labelStyle,
          children: /*#__PURE__*/_jsxs("div", {
            title: item.label,
            className: "ellipsis info-label-b-text",
            children: [item.label, " \uFF1A"]
          })
        }), item.label === '地址' || item.isAddress ? /*#__PURE__*/_jsx("div", {
          className: "value",
          style: style,
          title: item.value || '',
          children: item.value || '--'
        }) : item.key === 'panoramaLinkAddress' ? /*#__PURE__*/_jsx("div", {
          className: 'value',
          children: (item === null || item === void 0 || (_item$value = item.value) === null || _item$value === void 0 ? void 0 : _item$value.indexOf('http')) > -1 ? /*#__PURE__*/_jsx("a", {
            onClick: function onClick() {
              window.open(item.value);
            },
            children: item.value
          }) : item.value || '--'
        }) : /*#__PURE__*/_jsx("div", {
          className: "value ".concat(ellipsis ? 'ellipsis' : ''),
          style: style,
          title: ValueDom(item.componentType || '', item.value, !!item.componentType),
          children: typeof item.render === 'function' ? item.render() : ValueDom(item.componentType || '', item.value)
        })]
      }, item.key);
    })
  });
}
export 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 _value$join;
  if (isTitle) {
    return '';
  }
  var node;
  switch (componentType) {
    case 'MONTH_PERIOD':
      node = (_value$join = value.join) === null || _value$join === void 0 ? void 0 : _value$join.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__*/_jsx(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)) {
        var _value$map;
        node = value === null || value === void 0 || (_value$map = value.map(function (item) {
          return "".concat(item.startTime, "~").concat(item.endTime);
        })) === null || _value$map === void 0 ? void 0 : _value$map.join('；');
      }
      break;
    case 'IMAGE':
      var photos = value ? JSON.parse(value || '[]') : [];
      if (photos.length) {
        node = /*#__PURE__*/_jsx(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__*/_jsx(VtxImage, {
        aspectFit: true,
        src: value
      });
      break;
    case 'GD_ENTRANCE':
      node = /*#__PURE__*/_jsx("div", {
        children: value === null || value === void 0 ? void 0 : value.map(function (item, index) {
          var _item$location, _item$location2;
          return /*#__PURE__*/_jsxs("div", {
            title: "".concat(item === null || item === void 0 ? void 0 : item.name, "\uFF1A").concat(item === null || item === void 0 || (_item$location = item.location) === null || _item$location === void 0 ? void 0 : _item$location.lngLats),
            children: [item === null || item === void 0 ? void 0 : item.name, "\uFF1A", item === null || item === void 0 || (_item$location2 = item.location) === null || _item$location2 === void 0 ? void 0 : _item$location2.lngLats]
          }, index);
        })
      });
      break;
    default:
      node = value;
      break;
  }
  return node || isNumber(node) ? node : '--';
};