"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 _react = _interopRequireWildcard(require("react"));
var _vmRowCol = require("../vm-row-col");
var _index = require("../vm-charts/index");
var _moment = _interopRequireDefault(require("moment"));
var _vmEmpty = _interopRequireDefault(require("../vm-empty"));
var _api = require("./api");
require("./style");
var _antd = require("antd");
var _vmFilter = require("../vm-filter");
var _vmContainer = _interopRequireDefault(require("../vm-container"));
var _vmSelectDevice = _interopRequireDefault(require("../vm-select-device"));
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 _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; }
var defaultDate = [(0, _moment["default"])().subtract(1, 'day'), (0, _moment["default"])()];
var format = 'YYYY-MM-DD HH:mm:ss';
function VmCorrelationComparison(props) {
  var _useState = (0, _react.useState)(defaultDate),
    _useState2 = _slicedToArray(_useState, 2),
    date = _useState2[0],
    setDate = _useState2[1]; // 时间
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    lineData = _useState4[0],
    setLineData = _useState4[1]; // 参照图表数据
  var _useState5 = (0, _react.useState)([]),
    _useState6 = _slicedToArray(_useState5, 2),
    xdate = _useState6[0],
    setXdate = _useState6[1]; // 参照图表X轴数据
  var _useState7 = (0, _react.useState)([]),
    _useState8 = _slicedToArray(_useState7, 2),
    compareXdate = _useState8[0],
    setCompareXdate = _useState8[1]; // 对比图表X轴数据
  var _useState9 = (0, _react.useState)([]),
    _useState10 = _slicedToArray(_useState9, 2),
    compareObjectData = _useState10[0],
    setCompareObjectData = _useState10[1]; // 对比图表数据
  var _useState11 = (0, _react.useState)([]),
    _useState12 = _slicedToArray(_useState11, 2),
    compareFactorList = _useState12[0],
    setCompareFactorList = _useState12[1]; // 对比因子列表
  var _useState13 = (0, _react.useState)(''),
    _useState14 = _slicedToArray(_useState13, 2),
    compareFacilityId = _useState14[0],
    setCompareFacilityId = _useState14[1]; // 对比对象设施id
  var _useState15 = (0, _react.useState)(''),
    _useState16 = _slicedToArray(_useState15, 2),
    compareFacilityName = _useState16[0],
    setCompareFacilityName = _useState16[1]; // 对比对象设施名称
  var _useState17 = (0, _react.useState)(''),
    _useState18 = _slicedToArray(_useState17, 2),
    factorCode = _useState18[0],
    setFactorCode = _useState18[1]; // 参照监测因子code
  var _useState19 = (0, _react.useState)(''),
    _useState20 = _slicedToArray(_useState19, 2),
    compareFactorCode = _useState20[0],
    setCompareFactorCode = _useState20[1]; // 对比选中监测因子code
  var _useState21 = (0, _react.useState)([]),
    _useState22 = _slicedToArray(_useState21, 2),
    referFactorList = _useState22[0],
    setReferFactorList = _useState22[1]; // 对比监测因子列表
  var _useState23 = (0, _react.useState)(''),
    _useState24 = _slicedToArray(_useState23, 2),
    deviceId = _useState24[0],
    setDeviceId = _useState24[1]; // 获取设施关联设备id
  var id = props.id,
    publicUrlJCSS = props.publicUrlJCSS,
    _props$title = props.title,
    title = _props$title === void 0 ? '' : _props$title,
    filterParams = props.filterParams,
    isRelateDevice = props.isRelateDevice,
    isDevice = props.isDevice;
  (0, _react.useEffect)(function () {
    getCompareFactor(id, 'refer');
  }, [id]);
  var _Service$UseMonitorTy = _api.Service.UseMonitorType(),
    monitorTypeData = _Service$UseMonitorTy.monitorTypeData;
  // 获取图表数据
  var getMonitorData = function getMonitorData(time, first) {
    setLineData([]);
    var newTime = time || date;
    _api.Service.getMonitorData({
      id: id,
      publicUrlJCSS: publicUrlJCSS,
      startTime: newTime[0].format(format),
      endTime: newTime[1].format(format),
      compareFacilityId: compareFacilityId,
      factorCode: factorCode,
      compareFactorCode: compareFactorCode,
      filterParams: filterParams,
      isRelateDevice: isRelateDevice,
      deviceId: deviceId,
      isDevice: isDevice
    }).then(function (res) {
      var _ref = res || {},
        _ref$xdate = _ref.xdate,
        xdate = _ref$xdate === void 0 ? [] : _ref$xdate,
        _ref$data = _ref.data,
        data = _ref$data === void 0 ? [] : _ref$data,
        _ref$compareData = _ref.compareData,
        compareData = _ref$compareData === void 0 ? [] : _ref$compareData,
        _ref$compareXdate = _ref.compareXdate,
        compareXdate = _ref$compareXdate === void 0 ? [] : _ref$compareXdate;
      setXdate(xdate);
      setCompareXdate(compareXdate);
      if (first) {
        if (data && data.length) {
          // @ts-ignore
          setLineData([data[0], compareData[0] || []]);
        }
      } else {
        handleData(data, compareData);
      }
    });
  };
  // data:参照 compareData：对比
  var handleData = function handleData(data, compareData) {
    var newData = [];
    data.map(function (v) {
      if (v.opcCode === factorCode) {
        newData.push(Object.assign(Object.assign({}, v), {
          name: "".concat(title || '参照站点').concat(v.name)
        }));
      }
    });
    compareData.map(function (v) {
      if (v.opcCode === compareFactorCode) {
        newData.push(Object.assign(Object.assign({}, v), {
          name: "".concat(compareFacilityName || '对比站点').concat(v.name)
        }));
      }
    });
    setLineData(newData);
  };
  // 获取对比对象
  var getCompareObject = function getCompareObject(e) {
    setCompareObjectData([]);
    _api.Service.getCompareObject({
      id: id,
      publicUrlJCSS: publicUrlJCSS,
      monitorTypeIds: e,
      filterParams: filterParams,
      isRelateDevice: isRelateDevice,
      deviceId: deviceId,
      isDevice: isDevice
    }).then(function (res) {
      setCompareObjectData(res);
    });
  };
  // 获取对比监测因子
  var getCompareFactor = function getCompareFactor(e, type) {
    _api.Service.getCompareFactor({
      publicUrlJCSS: publicUrlJCSS,
      id: e,
      filterParams: filterParams,
      isRelateDevice: isRelateDevice,
      deviceId: deviceId,
      isDevice: isDevice
    }).then(function (res) {
      if (type === 'refer') {
        setReferFactorList(res || []);
      } else {
        setCompareFactorList(res || []);
      }
    });
  };
  // 设备id
  var getSelectValue = function getSelectValue(value) {
    setDeviceId(value);
  };
  // 分析
  var analysisFun = function analysisFun() {
    getMonitorData(null, false);
  };
  var items = [{
    type: 'radio',
    label: '参照监测因子',
    itemProps: {
      options: referFactorList,
      onChange: function onChange(e) {
        setFactorCode(e.target.value);
      }
    }
  }, {
    type: 'radio',
    label: '对比监测类型',
    style: {
      maxWidth: 'calc(100% - 84px)'
    },
    height: 26,
    itemProps: {
      options: monitorTypeData || [],
      onChange: function onChange(e) {
        getCompareObject(e.target.value);
      }
    }
  }, {
    type: 'select',
    style: {
      width: '200px'
    },
    label: '对比对象',
    itemProps: {
      options: compareObjectData,
      onChange: function onChange(e, option) {
        getCompareFactor(e, 'compare');
        setCompareFacilityId(e);
        setCompareFacilityName(option.objectName);
      }
    }
  }, {
    type: 'radio',
    label: '对比监测因子',
    itemProps: {
      options: compareFactorList,
      onChange: function onChange(e) {
        setCompareFactorCode(e.target.value);
      }
    }
  }, {
    type: 'rangePicker',
    label: '对比时间',
    defaultValue: defaultDate,
    itemProps: {
      format: format,
      onChange: function onChange(e) {
        setDate(e);
      }
    },
    customContent: (/*#__PURE__*/_react["default"].createElement(_antd.Button, {
      onClick: function onClick() {
        analysisFun();
      },
      type: "primary",
      style: {
        marginLeft: '30px'
      }
    }, "\u5206\u6790"))
  }];
  return /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: '100%'
    }
  }, /*#__PURE__*/_react["default"].createElement(_vmRowCol.VmRow, null, /*#__PURE__*/_react["default"].createElement(_vmRowCol.VmCol, null, /*#__PURE__*/_react["default"].createElement(_vmContainer["default"], {
    contentStyle: {
      height: 'auto'
    }
  }, isRelateDevice ? (/*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement(_vmSelectDevice["default"], {
    selectStyle: {
      width: 200
    },
    id: id,
    getSelectValue: getSelectValue,
    className: true,
    selectConfig: {
      label: '参照设备'
    }
  }))) : null, /*#__PURE__*/_react["default"].createElement(_vmFilter.VmFilterItem, {
    items: items
  }))), /*#__PURE__*/_react["default"].createElement(_vmRowCol.VmCol, null, /*#__PURE__*/_react["default"].createElement(_vmContainer["default"], {
    contentStyle: {
      overflowY: 'hidden'
    }
  }, /*#__PURE__*/_react["default"].createElement("div", {
    style: {
      height: '260px'
    }
  }, lineData && lineData.length ? (/*#__PURE__*/_react["default"].createElement(_index.Line, {
    data: lineData,
    xAxisConfig: [{
      type: 'category',
      boundaryGap: false,
      data: xdate,
      axisLabel: {
        show: false
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false
      },
      axisPointer: {},
      onZero: false,
      z: 10
    }],
    xAxis: compareXdate,
    exportShow: true,
    dataZoomShow: true
  })) : (/*#__PURE__*/_react["default"].createElement(_vmEmpty["default"], {
    type: "chart"
  })))))));
}
var _default = exports["default"] = VmCorrelationComparison;
//# sourceMappingURL=index.js.map
