"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _useProps2 = _interopRequireDefault(require("@vtx/ol-map/lib/use-props"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _ResultTitle = _interopRequireDefault(require("../_component/ResultTitle"));
var _StatisticsList = _interopRequireDefault(require("../_component/StatisticsList"));
var _ahooks = require("ahooks");
var _service = require("./service");
var _lodash = require("lodash");
var _ResultList = _interopRequireDefault(require("../_component/ResultList"));
var _RoadSelect = _interopRequireDefault(require("../_component/RoadSelect"));
var _Filter = _interopRequireDefault(require("../_component/Filter"));
var _form = _interopRequireDefault(require("antd/lib/form"));
var _FilterForm = _interopRequireDefault(require("./FilterForm"));
var _MapLayer = _interopRequireDefault(require("./MapLayer"));
var _Status = _interopRequireDefault(require("./Status"));
var _DetailModal = _interopRequireDefault(require("./DetailModal"));
var _DetailItems = _interopRequireDefault(require("../_component/DetailItems"));
var _useModal2 = _interopRequireDefault(require("../_mapUtil/useModal"));
var _config = require("./config");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
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 && Object.prototype.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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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); }
var ResultStatistics = function ResultStatistics(_ref) {
  var activeKey = _ref.activeKey,
    setActiveKey = _ref.setActiveKey;
  var _useRequest = (0, _ahooks.useRequest)(_service.fetchTypeStatistics),
    _useRequest$data = _useRequest.data,
    data = _useRequest$data === void 0 ? [] : _useRequest$data;
  var objData = (0, _lodash.keyBy)(data, 'type');
  var list = [{
    key: _config.SedimentationType.CQYJ,
    icon: require('./assets/cqyj.svg')
  }, {
    key: _config.SedimentationType.TFDS,
    icon: require('./assets/tfds.svg')
  }, {
    key: _config.SedimentationType.GTGD,
    icon: require('./assets/gtgd.svg')
  }, {
    key: _config.SedimentationType.ZC,
    icon: require('../assets/zcgd.svg')
  }].map(function (item) {
    var _objData$item$key;
    return _objectSpread(_objectSpread({}, item), {}, {
      name: _config.SedimentationTypeName[item.key],
      unit: '条',
      color: _config.SedimentationTypeColor[item.key],
      count: (_objData$item$key = objData[item.key]) === null || _objData$item$key === void 0 ? void 0 : _objData$item$key.count
    });
  });
  return /*#__PURE__*/_react["default"].createElement(_StatisticsList["default"], {
    list: list,
    activeKey: activeKey,
    onClick: function onClick(item) {
      return setActiveKey(item.key);
    }
  });
};
var Result = function Result() {
  var _useProps = (0, _useProps2["default"])(),
    map = _useProps.map,
    visible = _useProps.visible,
    setVisible = _useProps.setVisible;
  var _useState = (0, _react.useState)(''),
    _useState2 = _slicedToArray(_useState, 2),
    activeKey = _useState2[0],
    setActiveKey = _useState2[1];
  var _useState3 = (0, _react.useState)(null),
    _useState4 = _slicedToArray(_useState3, 2),
    roadId = _useState4[0],
    setRoadId = _useState4[1];
  var _Form$useForm = _form["default"].useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    form = _Form$useForm2[0];
  var _useModal = (0, _useModal2["default"])(),
    modalInfo = _useModal.modalInfo,
    onOpenModal = _useModal.onOpenModal,
    onCancel = _useModal.onCancel;
  var _useRequest2 = (0, _ahooks.useRequest)(function () {
      return (0, _service.fetchQueryData)(_objectSpread(_objectSpread({
        size: 10000,
        roadId: roadId
      }, form.getFieldsValue()), {}, {
        sedimentationTypes: activeKey
      }));
    }, {
      refreshDeps: [activeKey, roadId]
    }),
    _useRequest2$data = _useRequest2.data,
    data = _useRequest2$data === void 0 ? [] : _useRequest2$data,
    run = _useRequest2.run;
  (0, _react.useEffect)(function () {
    form.setFieldsValue({
      sedimentationTypes: activeKey
    });
  }, [activeKey]);
  (0, _react.useEffect)(function () {
    map && map.hideTemplate && map.hideTemplate();
  }, [data]);
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_CustomModal["default"], {
    map: map,
    onCancel: function onCancel() {
      setVisible(false);
    },
    visible: visible,
    isShowHidden: true
  }, /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '分析结果统计',
    question: "\u901A\u8FC7\u6D41\u91CF\u3001\u6DB2\u4F4D\u6570\u636E\u5206\u6790\u6C61\u6C34\u7BA1\u7F51\u4E2D\u53EF\u80FD\u5B58\u5728\u6DE4\u79EF\u7684\u7BA1\u6BB5"
  }), /*#__PURE__*/_react["default"].createElement(ResultStatistics, {
    activeKey: activeKey,
    setActiveKey: setActiveKey
  }), /*#__PURE__*/_react["default"].createElement(_ResultTitle["default"], {
    title: '淤积堵塞明细',
    rightContent: /*#__PURE__*/_react["default"].createElement("div", {
      className: "ol-map-analysis-sedimentation-filter"
    }, /*#__PURE__*/_react["default"].createElement(_RoadSelect["default"], {
      value: roadId,
      onChange: function onChange(v) {
        return setRoadId(v);
      }
    }), /*#__PURE__*/_react["default"].createElement(_Filter["default"], {
      onOk: function onOk() {
        run();
        setActiveKey(form.getFieldValue('sedimentationTypes'));
      },
      onReset: function onReset() {
        form.resetFields();
        setActiveKey('');
      }
    }, /*#__PURE__*/_react["default"].createElement(_FilterForm["default"], {
      form: form
    })))
  }), /*#__PURE__*/_react["default"].createElement(_ResultList["default"], {
    list: data,
    idKey: 'lineNo',
    onTitleClick: function onTitleClick(info) {
      map.showTemplateByFilter("SEDIMENTATION_GW_".concat(info.sedimentationType), 'lineNo', info.lineNo);
    },
    onItemClick: function onItemClick(info) {
      var _info$facility;
      onOpenModal({
        facilityId: info === null || info === void 0 || (_info$facility = info.facility) === null || _info$facility === void 0 ? void 0 : _info$facility.id
      });
    },
    titleKey: "lineNo",
    getDetailContent: function getDetailContent(info) {
      var roadName = info.roadName,
        avgWaterLevel = info.avgWaterLevel,
        avgFlowSpeed = info.avgFlowSpeed;
      var ywLabel = '淤积时段平均液位';
      var lsLabel = '淤积时段平均流速';
      if ([_config.SedimentationType.ZC, _config.SedimentationType.GTGD].includes(info.sedimentationType)) {
        ywLabel = '平均液位';
        lsLabel = '平均流速';
      }
      var items = [{
        label: '所在道路',
        value: roadName
      }, {
        label: ywLabel,
        value: avgWaterLevel ? "".concat(avgWaterLevel, "m") : null
      }, {
        label: lsLabel,
        value: avgFlowSpeed ? "".concat(avgFlowSpeed, "m/s") : null
      }];
      return /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
        items: items
      });
    },
    getOtherContent: function getOtherContent(info) {
      return /*#__PURE__*/_react["default"].createElement(_Status["default"], {
        info: info
      });
    }
  })), visible && /*#__PURE__*/_react["default"].createElement(_MapLayer["default"], {
    data: data,
    openModal: onOpenModal
  }), modalInfo.visible && /*#__PURE__*/_react["default"].createElement(_DetailModal["default"], _extends({}, modalInfo.info, {
    onCancel: onCancel,
    visible: modalInfo.visible
  })));
};
ResultStatistics.propTypes = {
  activeKey: _propTypes["default"].string,
  setActiveKey: _propTypes["default"].func
};
var _default = exports["default"] = Result;
//# sourceMappingURL=Result.js.map
