"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _echartsForReact = _interopRequireDefault(require("echarts-for-react"));
var _Table = _interopRequireDefault(require("../../_component/Table"));
var _MyEmpty = _interopRequireDefault(require("../../_component/MyEmpty"));
var _ahooks = require("ahooks");
var _propTypes = _interopRequireDefault(require("prop-types"));
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 _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 _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
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 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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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); } /**
 * @returns 纵截面分析结果弹窗
 */
// 材质
var texture = [{
  value: '1',
  label: '混凝土管'
}, {
  value: '2',
  label: '钢筋混凝土管'
}, {
  value: '3',
  label: '陶土管'
}, {
  value: '4',
  label: 'PE(聚乙烯)管 '
}, {
  value: '5',
  label: 'HDPE(高密度聚乙烯)管'
}, {
  value: '6',
  label: 'UPVC管'
}, {
  value: '7',
  label: '铸铁管'
}, {
  value: '8',
  label: '玻璃钢夹砂管'
}, {
  value: '9',
  label: '钢管'
}, {
  value: '10',
  label: '石棉水泥管'
}, {
  value: '11',
  label: '其他'
}];

// 获取材质名称
var getTextureName = function getTextureName(value) {
  var list = texture.find(function (val) {
    return val.value == value;
  }) || {};
  return list === null || list === void 0 ? void 0 : list.label;
};
function ProfileModal(props) {
  var ref = (0, _react.useRef)(null);
  var size = (0, _ahooks.useSize)(ref);
  var _props$modalData = props.modalData,
    modalData = _props$modalData === void 0 ? [] : _props$modalData;
  var getOption = function getOption() {
    var series = [];
    var totalDistance = 2;
    var yMin = 0;
    var chartData = [],
      xAxisData = [0];
    modalData.map(function (val, index) {
      var _val$line = val.line,
        line = _val$line === void 0 ? {} : _val$line,
        _val$startPoint = val.startPoint,
        startPoint = _val$startPoint === void 0 ? {} : _val$startPoint,
        _val$endPoint = val.endPoint,
        endPoint = _val$endPoint === void 0 ? {} : _val$endPoint;
      var datas = [];
      if (index === modalData.length - 1) {
        datas = [_objectSpread({
          groundElevation: startPoint.groundElevation,
          bottomElevation: startPoint.bottomElevation,
          deep: startPoint.deep
        }, line), _objectSpread({
          groundElevation: endPoint.groundElevation,
          bottomElevation: endPoint.bottomElevation,
          deep: endPoint.deep
        }, line)];
      } else {
        datas = [_objectSpread({
          groundElevation: startPoint.groundElevation,
          bottomElevation: startPoint.bottomElevation,
          deep: startPoint.deep
        }, line)];
      }
      chartData.push.apply(chartData, _toConsumableArray(datas));
    });
    chartData && chartData.length && chartData.map(function (item, idx) {
      series.push(item.groundElevation);
      var _space = item.space === 'NaN' ? 0 : item.space || 0;
      if (idx < chartData.length - 1) {
        xAxisData.push(Number(parseFloat((xAxisData[idx] || 0) + _space).toFixed(2)));
      }
      if (idx === 0) {
        yMin = item.groundElevation;
      } else {
        if (item.groundElevation < yMin) {
          yMin = item.groundElevation;
        }
      }
      totalDistance += _space;
    });
    return {
      grid: {
        left: 30,
        right: 30,
        top: 30,
        bottom: 20
      },
      tooltip: {
        trigger: 'item',
        axisPointer: {
          type: 'cross'
        },
        confine: true,
        // backgroundColor: 'transparent',
        padding: 0,
        formatter: function formatter(_ref) {
          var dataIndex = _ref.dataIndex;
          return "<div class=\"corssTooltip\">\n                <div>\u7BA1\u5E95\u6807\u9AD8(m)\uFF1A".concat(chartData[dataIndex].bottomElevation || '', "</div>\n                <div>\u57CB\u6DF1(m)\uFF1A").concat(chartData[dataIndex].deep || '', "</div>\n                <div>\u5730\u9762\u9AD8\u7A0B(m)\uFF1A").concat(chartData[dataIndex].groundElevation || '', "</div>\n                <div>\u7BA1\u9053\u6807\u8BC6\u7801\uFF1A").concat(chartData[dataIndex].code || '', "</div>\n                <div>\u7BA1\u9053\u7C7B\u522B\uFF1A").concat(chartData[dataIndex].netType || '', "</div>\n                <div>\u7BA1\u9053\u957F\u5EA6(m)\uFF1A").concat(chartData[dataIndex].lineLength || '', "</div>\n                <div>\u89C4\u683C(mm)\uFF1A").concat(chartData[dataIndex].ds || '', "</div>\n                <div>\u6750\u8D28\uFF1A").concat(chartData[dataIndex].lineTexture && getTextureName(chartData[dataIndex].lineTexture) || '', "</div>\n                </div>");
        }
      },
      xAxis: {
        name: '米',
        // min: 0,
        // max: parseInt(totalDistance),
        axisTick: {
          show: false
        },
        splitLine: {
          show: false
        },
        scale: true,
        axisLine: {
          onZero: true
        },
        data: xAxisData
      },
      yAxis: {
        name: '米',
        axisTick: {
          show: false
        },
        splitLine: {
          show: false
        },
        axisLine: {
          show: true,
          onZero: false
        }
      },
      series: [{
        type: 'line',
        data: series,
        itemStyle: {
          color: '#009BFF'
        },
        emphasis: {
          itemStyle: {
            color: 'red'
          }
        }
      }]
    };
  };
  var columns = [{
    title: '管线编码',
    dataIndex: 'name',
    key: 'name',
    width: 100,
    fixed: 'left'
  }];
  var dataSource = [];
  var lineLength = {
    name: '管长(m)'
  };
  var ds = {
    name: '管径(mm)'
  };
  var groundElevation = {
    name: '起点地面高程(m)'
  };
  var endZ = {
    name: '终点地面高程(m)'
  };
  var bottomElevation = {
    name: '起点管顶高程(m)'
  };
  var pointTopElevation = {
    name: '终点管顶高程(m)'
  };
  var msfs = {
    name: '埋设方式'
  };
  var roadName = {
    name: '所在道路'
  };
  var zData = {
    name: '地面高程(m)'
  };
  var startZData = {
    name: '管底标高(m)'
  };
  var spacingData = {
    name: '间距(m)'
  };
  var dsData = {
    name: '规格(mm)'
  };
  var lineTextureData = {
    name: '材质'
  };
  var startDeepData = {
    name: '埋深(m)'
  };
  if (modalData !== null && modalData !== void 0 && modalData.length) {
    modalData.map(function (item) {
      var _texture$find$label, _texture$find;
      var _item$line = item.line,
        line = _item$line === void 0 ? {} : _item$line,
        _item$startPoint = item.startPoint,
        startPoint = _item$startPoint === void 0 ? {} : _item$startPoint,
        _item$endPoint = item.endPoint,
        endPoint = _item$endPoint === void 0 ? {} : _item$endPoint;
      columns.push({
        title: line.code,
        key: line.code,
        dataIndex: line.code,
        align: 'right'
        // render: renderContent,
      });
      lineLength[line.code] = line.lineLength;
      ds[line.code] = line.ds;
      groundElevation[line.code] = startPoint.groundElevation || '-';
      endZ[line.code] = endPoint.groundElevation || '-';
      zData[line.code] = "".concat(startPoint.groundElevation || '-', ",  ").concat(endPoint.groundElevation || '-');
      bottomElevation[line.code] = startPoint.bottomElevation || '-';
      pointTopElevation[line.code] = endPoint.bottomElevation || '-';
      startZData[line.code] = "".concat(startPoint.bottomElevation || '-', ",   ").concat(endPoint.bottomElevation || '-');
      spacingData[line.code] = line.space === 'NaN' ? 0 : line.space || 0;
      dsData[line.code] = line.ds;
      lineTextureData[line.code] = (_texture$find$label = (_texture$find = texture.find(function (tItem) {
        return tItem.value === String(line.lineTexture);
      })) === null || _texture$find === void 0 ? void 0 : _texture$find.label) !== null && _texture$find$label !== void 0 ? _texture$find$label : line.lineTexture;
      startDeepData[line.code] = "".concat(startPoint.deep || '-', ",   ").concat(endPoint.deep || '-');
      msfs[line.code] = line === null || line === void 0 ? void 0 : line.layWayStr;
      roadName[line.code] = line === null || line === void 0 ? void 0 : line.roadName;
    });
    dataSource = [lineLength, ds, groundElevation, endZ, bottomElevation, pointTopElevation, msfs, roadName];
  }
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-analysis-inverse-slope-diagnosis-".concat(name);
    }
    return "ol-map-analysis-inverse-slope-diagnosis";
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('ProfileModal'),
    ref: ref
  }, modalData !== null && modalData !== void 0 && modalData.length && size !== null && size !== void 0 && size.height ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_echartsForReact["default"], {
    option: getOption(),
    style: {
      height: (size === null || size === void 0 ? void 0 : size.height) / 2
    },
    lazyUpdate: true
  }), /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      flex: 1,
      padding: '10px 0 0',
      display: 'flex',
      overflow: 'hidden'
    }
  }, /*#__PURE__*/_react["default"].createElement(_Table["default"], {
    dataSource: dataSource,
    columns: columns,
    pagination: false,
    indexColumn: false,
    scroll: {
      y: (size === null || size === void 0 ? void 0 : size.height) / 2 - 60,
      x: 300
    },
    isList: true
  }))) : /*#__PURE__*/_react["default"].createElement(_MyEmpty["default"], null));
}
ProfileModal.propTypes = {
  modalData: _propTypes["default"].array
};
var _default = exports["default"] = ProfileModal;
//# sourceMappingURL=index.js.map
