"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 _olMap = require("@vtx/ol-map");
var _antd = require("antd");
var _react = _interopRequireWildcard(require("react"));
var _useModal2 = _interopRequireDefault(require("../_mapUtil/useModal"));
var _ahooks = require("ahooks");
var _CustomModal = _interopRequireDefault(require("../_component/CustomModal"));
var _ResultTitle = _interopRequireDefault(require("../_component/ResultTitle"));
var _StatisticsList = _interopRequireDefault(require("../_component/StatisticsList"));
var _lodash = require("lodash");
var _service = require("./service");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _RoadSelect = _interopRequireDefault(require("../_component/RoadSelect"));
var _Filter = _interopRequireDefault(require("../_component/Filter"));
var _FilterForm = _interopRequireDefault(require("./FilterForm"));
var _ResultList = _interopRequireDefault(require("../_component/ResultList"));
var _DetailItems = _interopRequireDefault(require("../_component/DetailItems"));
var _moment = _interopRequireDefault(require("moment"));
var _MyTag = _interopRequireDefault(require("../_component/MyTag"));
var _Duration = _interopRequireDefault(require("../_component/Duration"));
var _MapLayer = _interopRequireDefault(require("./MapLayer"));
var _config = require("./config");
var _DetailModal = _interopRequireDefault(require("./DetailModal"));
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 _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 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); }
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; }
var ResultStatistics = function ResultStatistics(_ref) {
  var _objData$RainSewageTy, _objData$RainSewageTy2;
  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 = [{
    name: _config.RainSewageTypeName[_config.RainSewageType.YWHJ] + '管段',
    count: (_objData$RainSewageTy = objData[_config.RainSewageType.YWHJ]) === null || _objData$RainSewageTy === void 0 ? void 0 : _objData$RainSewageTy.count,
    key: _config.RainSewageType.YWHJ,
    unit: '条',
    color: _config.RainSewageTypeColor[_config.RainSewageType.YWHJ],
    icon: require('./assets/ywhj.svg')
  }, {
    name: _config.RainSewageTypeName[_config.RainSewageType.ZC],
    count: (_objData$RainSewageTy2 = objData[_config.RainSewageType.ZC]) === null || _objData$RainSewageTy2 === void 0 ? void 0 : _objData$RainSewageTy2.count,
    key: _config.RainSewageType.ZC,
    unit: '条',
    color: _config.RainSewageTypeColor[_config.RainSewageType.ZC],
    icon: require('../assets/zcgd.svg')
  }];
  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, _olMap.useProps)(),
    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 = _antd.Form.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({
        size: 10000,
        rainSewageMixedTypes: activeKey,
        roadId: roadId
      }, form.getFieldsValue()));
    }, {
      refreshDeps: [activeKey, roadId]
    }),
    _useRequest2$data = _useRequest2.data,
    data = _useRequest2$data === void 0 ? [] : _useRequest2$data,
    run = _useRequest2.run;
  (0, _react.useEffect)(function () {
    form.setFieldsValue({
      date: [(0, _moment["default"])().subtract(30, 'day'), (0, _moment["default"])()]
    });
  }, [form]);
  (0, _react.useEffect)(function () {
    try {
      map.hideTemplate();
    } catch (err) {}
  }, [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\u96E8\u6C34\u7BA1\u7F51\u7535\u5BFC\u7387\u6570\u636E\u5206\u6790\u53EF\u80FD\u5B58\u5728\u96E8\u6C61\u6DF7\u63A5\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();
      },
      onReset: function onReset() {
        form.resetFields();
      }
    }, /*#__PURE__*/_react["default"].createElement(_FilterForm["default"], {
      form: form
    })))
  }), /*#__PURE__*/_react["default"].createElement(_ResultList["default"], {
    list: data,
    idKey: 'lineNo',
    onTitleClick: function onTitleClick(info) {
      map.showTemplateByFilter("RAIN_SEWAGE_GW_".concat(info.sewageMixedType), '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,
        totalOccTimes = info.totalOccTimes;
      var items = [{
        label: '所在道路',
        value: roadName
      }, {
        label: '雨污混接报警次数',
        value: totalOccTimes
      }];
      return /*#__PURE__*/_react["default"].createElement(_DetailItems["default"], {
        items: items
      });
    },
    getOtherContent: function getOtherContent(_ref2) {
      var totalDurationHours = _ref2.totalDurationHours,
        sewageMixedType = _ref2.sewageMixedType;
      return /*#__PURE__*/_react["default"].createElement(_antd.Space, null, /*#__PURE__*/_react["default"].createElement(_MyTag["default"], {
        text: _config.RainSewageTypeName[sewageMixedType],
        color: _config.RainSewageTypeColor[sewageMixedType]
      }), /*#__PURE__*/_react["default"].createElement(_Duration["default"], {
        label: '雨污混接时长',
        durationHour: totalDurationHours
      }));
    }
  })), 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
