"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 _ahooks = require("ahooks");
var _button = _interopRequireDefault(require("antd/lib/button"));
var _checkbox = _interopRequireDefault(require("antd/lib/checkbox"));
var _message = _interopRequireDefault(require("antd/lib/message"));
var _col = _interopRequireDefault(require("antd/lib/col"));
var _row = _interopRequireDefault(require("antd/lib/row"));
var _getUrlParam = _interopRequireDefault(require("@vtx/utils/lib/getUrlParam"));
var _request = _interopRequireDefault(require("../_mapUtil/request"));
var _configuration = _interopRequireDefault(require("./components/configuration"));
var _config = _interopRequireDefault(require("../_mapUtil/config"));
var _GeneralConfig = _interopRequireDefault(require("./components/GeneralConfig"));
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 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); }
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 Intelligentanalysisconfiguration = function Intelligentanalysisconfiguration(props) {
  var onClose = props.onClose;
  var _useState = (0, _react.useState)([]),
    _useState2 = _slicedToArray(_useState, 2),
    allSupportPipeNetworks = _useState2[0],
    setAllSupportPipeNetworks = _useState2[1];
  var _useState3 = (0, _react.useState)([]),
    _useState4 = _slicedToArray(_useState3, 2),
    jcfxList = _useState4[0],
    setJcfxList = _useState4[1];
  var _useState5 = (0, _react.useState)([]),
    _useState6 = _slicedToArray(_useState5, 2),
    jgzdfxList = _useState6[0],
    setJgzdfxList = _useState6[1];
  var _useState7 = (0, _react.useState)([]),
    _useState8 = _slicedToArray(_useState7, 2),
    znfxList = _useState8[0],
    setZnfxList = _useState8[1];
  var _useState9 = (0, _react.useState)([]),
    _useState10 = _slicedToArray(_useState9, 2),
    predictionList = _useState10[0],
    setPredictionList = _useState10[1];
  // 选中的key
  var _useState11 = (0, _react.useState)([]),
    _useState12 = _slicedToArray(_useState11, 2),
    checkedList = _useState12[0],
    setCheckedList = _useState12[1];

  // 配置弹窗
  var _useState13 = (0, _react.useState)(false),
    _useState14 = _slicedToArray(_useState13, 2),
    configurationVisible = _useState14[0],
    setConfigurationVisible = _useState14[1];
  var _useState15 = (0, _react.useState)({}),
    _useState16 = _slicedToArray(_useState15, 2),
    configurationContent = _useState16[0],
    setConfigurationContent = _useState16[1];
  var _useState17 = (0, _react.useState)([]),
    _useState18 = _slicedToArray(_useState17, 2),
    gwlxType = _useState18[0],
    setGwlxType = _useState18[1];
  var pipeNetworks = [{
    types: 1,
    code: [1]
  }, {
    types: 2,
    code: [2]
  }, {
    types: 4,
    code: [4]
  }, {
    types: 8,
    code: [8]
  }, {
    types: 3,
    code: [1, 2]
  }, {
    types: 5,
    code: [1, 4]
  }, {
    types: 9,
    code: [1, 8]
  }, {
    types: 6,
    code: [2, 4]
  }, {
    types: 10,
    code: [2, 8]
  }, {
    types: 12,
    code: [4, 8]
  }, {
    types: 7,
    code: [1, 2, 4]
  }, {
    types: 11,
    code: [1, 2, 8]
  }, {
    types: 13,
    code: [1, 4, 8]
  }, {
    types: 14,
    code: [2, 4, 8]
  }, {
    types: 15,
    code: [1, 2, 4, 8]
  }];
  var onSave = function onSave() {
    var url = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/saveConfig");
    _request["default"].post(url, {
      body: {
        pipeNetworks: eval(gwlxType.join('+'))
      }
    }).then(function (res) {
      if ((res === null || res === void 0 ? void 0 : res.result) == 0) {
        onClose && onClose();
        _message["default"].success(res.msg || '操作成功');
      }
      getConfig();
    })["catch"](function () {
      _message["default"].error(res.msg || '服务器异常');
    });
  };
  var getAllSupportAnalyse = function getAllSupportAnalyse() {
    var url = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/getAllSupportAnalyse");
    _request["default"].get(url, {
      body: {}
    }).then(function (res) {
      var _res$data;
      var List = res === null || res === void 0 || (_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.map(function (item) {
        var _pipeNetworks$filter;
        return _objectSpread(_objectSpread({}, item), {}, {
          code: pipeNetworks === null || pipeNetworks === void 0 || (_pipeNetworks$filter = pipeNetworks.filter(function (it) {
            return (it === null || it === void 0 ? void 0 : it.types) == (item === null || item === void 0 ? void 0 : item.supportPipeNetworks);
          })) === null || _pipeNetworks$filter === void 0 || (_pipeNetworks$filter = _pipeNetworks$filter[0]) === null || _pipeNetworks$filter === void 0 ? void 0 : _pipeNetworks$filter.code
        });
      });
      setJcfxList(List === null || List === void 0 ? void 0 : List.filter(function (item) {
        return (item === null || item === void 0 ? void 0 : item.type) == 1;
      }));
      setJgzdfxList(List === null || List === void 0 ? void 0 : List.filter(function (item) {
        return (item === null || item === void 0 ? void 0 : item.type) == 2;
      }));
      setZnfxList(List === null || List === void 0 ? void 0 : List.filter(function (item) {
        return (item === null || item === void 0 ? void 0 : item.type) == 3;
      }));
      setPredictionList(List === null || List === void 0 ? void 0 : List.filter(function (item) {
        return (item === null || item === void 0 ? void 0 : item.type) == 4;
      }));
    })["catch"](function () {
      _message["default"].error(res.msg || '服务器异常');
    });
  };
  var getAllSupportPipeNetworks = function getAllSupportPipeNetworks() {
    var url3 = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/getAllSupportPipeNetworks");
    _request["default"].get(url3, {
      body: {}
    }).then(function (res) {
      setAllSupportPipeNetworks(res === null || res === void 0 ? void 0 : res.data);
    })["catch"](function () {
      _message["default"].error(res.msg || '服务器异常');
    });
  };
  var getConfig = function getConfig() {
    var url1 = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/getConfig");
    _request["default"].get(url1, {
      body: {
        tenantId: (0, _getUrlParam["default"])('tenantId')
      }
    }).then(function (res) {
      var _res$data2, _res$data4;
      var newGwlxType = [];
      if (res !== null && res !== void 0 && (_res$data2 = res.data) !== null && _res$data2 !== void 0 && _res$data2.pipeNetworks) {
        var _pipeNetworks$filter$;
        newGwlxType = pipeNetworks === null || pipeNetworks === void 0 || (_pipeNetworks$filter$ = pipeNetworks.filter(function (item) {
          var _res$data3;
          return item.types == (res === null || res === void 0 || (_res$data3 = res.data) === null || _res$data3 === void 0 ? void 0 : _res$data3.pipeNetworks);
        })[0]) === null || _pipeNetworks$filter$ === void 0 ? void 0 : _pipeNetworks$filter$.code;
      }
      setGwlxType(newGwlxType);
      setCheckedList((res === null || res === void 0 || (_res$data4 = res.data) === null || _res$data4 === void 0 || (_res$data4 = _res$data4.types) === null || _res$data4 === void 0 ? void 0 : _res$data4.map(function (item) {
        return item === null || item === void 0 ? void 0 : item.typeCode;
      })) || []);
    });
  };
  (0, _ahooks.useMount)(function () {
    getAllSupportPipeNetworks();
    getAllSupportAnalyse();
    getConfig();
  });
  (0, _ahooks.useUpdateEffect)(function () {
    getConfig();
  }, [configurationVisible]);
  var onConfiguration = function onConfiguration(item) {
    setConfigurationVisible(true);
    setConfigurationContent(item);
  };
  var configurationProps = {
    configurationVisible: configurationVisible,
    configurationContent: configurationContent,
    onConfigurationClose: function onConfigurationClose() {
      setConfigurationVisible(false);
      setConfigurationContent({});
    }
  };
  var _onChange = function onChange(e) {
    var _e$target;
    if (!(e !== null && e !== void 0 && (_e$target = e.target) !== null && _e$target !== void 0 && _e$target.checked)) {
      var _e$target2;
      var url = "".concat(_config["default"].publicUrlZNFX, "/api/gisAnalyze/deleteTypeConfig?analyseType=").concat(e === null || e === void 0 || (_e$target2 = e.target) === null || _e$target2 === void 0 ? void 0 : _e$target2.value);
      _request["default"].post(url, {
        body: {}
      }).then(function (res) {
        getConfig();
      })["catch"](function () {
        _message["default"].error(res.msg || '服务器异常');
      });
    }
  };
  var onChangeGwlx = function onChangeGwlx(val) {
    setGwlxType(val);
  };
  var classnames = function classnames(name) {
    if (name) {
      return "ol-map-analysis-configuration-".concat(name);
    }
    return "ol-map-analysis-configuration";
  };
  return /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('')
  }, /*#__PURE__*/_react["default"].createElement("div", null, "\u7BA1\u7F51\u7C7B\u578B\uFF1A", /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
    onChange: onChangeGwlx,
    value: gwlxType
  }, allSupportPipeNetworks === null || allSupportPipeNetworks === void 0 ? void 0 : allSupportPipeNetworks.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
      value: item === null || item === void 0 ? void 0 : item.type,
      key: item === null || item === void 0 ? void 0 : item.type
    }, item === null || item === void 0 ? void 0 : item.name);
  }))), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('normal')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worp')
  }, "\u57FA\u7840\u5206\u6790"), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worpChild')
  }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
    style: {
      width: '100%'
    },
    value: checkedList
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], null, jcfxList === null || jcfxList === void 0 ? void 0 : jcfxList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_col["default"], {
      key: item === null || item === void 0 ? void 0 : item.name,
      xxl: 4,
      xl: 6,
      lg: 8
    }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
      disabled: !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
        var _item$code;
        return item === null || item === void 0 || (_item$code = item.code) === null || _item$code === void 0 ? void 0 : _item$code.includes(it);
      })) || !checkedList.includes(item === null || item === void 0 ? void 0 : item.name),
      value: item === null || item === void 0 ? void 0 : item.name,
      onChange: function onChange(val) {
        return _onChange(val, item === null || item === void 0 ? void 0 : item.name);
      }
    }, item === null || item === void 0 ? void 0 : item.alias), /*#__PURE__*/_react["default"].createElement("span", {
      className: classnames('btn'),
      onClick: function onClick() {
        gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
          var _item$code2;
          return item === null || item === void 0 || (_item$code2 = item.code) === null || _item$code2 === void 0 ? void 0 : _item$code2.includes(it);
        }) ? onConfiguration(item) : null;
      }
    }, !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
      var _item$code3;
      return item === null || item === void 0 || (_item$code3 = item.code) === null || _item$code3 === void 0 ? void 0 : _item$code3.includes(it);
    })) ? '不可配置' : '配置'));
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('normal')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worp')
  }, "\u7ED3\u6784\u8BCA\u65AD\u5206\u6790"), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worpChild')
  }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
    style: {
      width: '100%'
    },
    value: checkedList
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], {
    wrap: ""
  }, jgzdfxList === null || jgzdfxList === void 0 ? void 0 : jgzdfxList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_col["default"], {
      key: item === null || item === void 0 ? void 0 : item.name,
      xxl: 4,
      xl: 6,
      lg: 8
    }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
      disabled: !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
        var _item$code4;
        return item === null || item === void 0 || (_item$code4 = item.code) === null || _item$code4 === void 0 ? void 0 : _item$code4.includes(it);
      })) || !checkedList.includes(item === null || item === void 0 ? void 0 : item.name),
      value: item === null || item === void 0 ? void 0 : item.name,
      onChange: function onChange(val) {
        return _onChange(val, item === null || item === void 0 ? void 0 : item.name);
      }
    }, item === null || item === void 0 ? void 0 : item.alias), /*#__PURE__*/_react["default"].createElement("span", {
      className: classnames('btn'),
      onClick: function onClick() {
        gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
          var _item$code5;
          return item === null || item === void 0 || (_item$code5 = item.code) === null || _item$code5 === void 0 ? void 0 : _item$code5.includes(it);
        }) ? onConfiguration(item) : null;
      }
    }, !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
      var _item$code6;
      return item === null || item === void 0 || (_item$code6 = item.code) === null || _item$code6 === void 0 ? void 0 : _item$code6.includes(it);
    })) ? '不可配置' : '配置'));
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('normal')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worp')
  }, "\u667A\u80FD\u5206\u6790"), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worpChild')
  }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
    style: {
      width: '100%'
    },
    value: checkedList
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], null, znfxList === null || znfxList === void 0 ? void 0 : znfxList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_col["default"], {
      xxl: 4,
      xl: 7,
      lg: 8,
      key: item === null || item === void 0 ? void 0 : item.name
    }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
      disabled: !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
        var _item$code7;
        return item === null || item === void 0 || (_item$code7 = item.code) === null || _item$code7 === void 0 ? void 0 : _item$code7.includes(it);
      })) || !checkedList.includes(item === null || item === void 0 ? void 0 : item.name),
      value: item === null || item === void 0 ? void 0 : item.name,
      onChange: function onChange(val) {
        return _onChange(val, item === null || item === void 0 ? void 0 : item.name);
      }
    }, item === null || item === void 0 ? void 0 : item.alias), /*#__PURE__*/_react["default"].createElement("span", {
      className: classnames('btn'),
      onClick: function onClick() {
        gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
          var _item$code8;
          return item === null || item === void 0 || (_item$code8 = item.code) === null || _item$code8 === void 0 ? void 0 : _item$code8.includes(it);
        }) ? onConfiguration(item) : null;
      }
    }, !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
      var _item$code9;
      return item === null || item === void 0 || (_item$code9 = item.code) === null || _item$code9 === void 0 ? void 0 : _item$code9.includes(it);
    })) ? '不可配置' : '配置'));
  }))))), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('normal')
  }, /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worp')
  }, "\u667A\u80FD\u9884\u6D4B"), /*#__PURE__*/_react["default"].createElement("div", {
    className: classnames('worpChild')
  }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"].Group, {
    style: {
      width: '100%'
    },
    value: checkedList
  }, /*#__PURE__*/_react["default"].createElement(_row["default"], null, predictionList === null || predictionList === void 0 ? void 0 : predictionList.map(function (item) {
    return /*#__PURE__*/_react["default"].createElement(_col["default"], {
      xxl: 4,
      xl: 7,
      lg: 8,
      key: item === null || item === void 0 ? void 0 : item.name
    }, /*#__PURE__*/_react["default"].createElement(_checkbox["default"], {
      disabled: !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
        var _item$code10;
        return item === null || item === void 0 || (_item$code10 = item.code) === null || _item$code10 === void 0 ? void 0 : _item$code10.includes(it);
      })) || !checkedList.includes(item === null || item === void 0 ? void 0 : item.name),
      value: item === null || item === void 0 ? void 0 : item.name,
      onChange: function onChange(val) {
        return _onChange(val, item === null || item === void 0 ? void 0 : item.name);
      }
    }, item === null || item === void 0 ? void 0 : item.alias), /*#__PURE__*/_react["default"].createElement("span", {
      className: classnames('btn'),
      onClick: function onClick() {
        gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
          var _item$code11;
          return item === null || item === void 0 || (_item$code11 = item.code) === null || _item$code11 === void 0 ? void 0 : _item$code11.includes(it);
        }) ? onConfiguration(item) : null;
      }
    }, !(gwlxType !== null && gwlxType !== void 0 && gwlxType.some(function (it) {
      var _item$code12;
      return item === null || item === void 0 || (_item$code12 = item.code) === null || _item$code12 === void 0 ? void 0 : _item$code12.includes(it);
    })) ? '不可配置' : '配置'));
  }))))), /*#__PURE__*/_react["default"].createElement(_GeneralConfig["default"], {
    classnames: classnames
  }), /*#__PURE__*/_react["default"].createElement(_button["default"], {
    className: classnames('savebtn'),
    type: "primary",
    onClick: onSave
  }, "\u4FDD\u5B58"), configurationVisible ? /*#__PURE__*/_react["default"].createElement(_configuration["default"], configurationProps) : null);
};
var _default = exports["default"] = Intelligentanalysisconfiguration;
//# sourceMappingURL=index.js.map
