import 'antd/es/modal/style';
import _Modal from 'antd/es/modal';
import 'antd/es/tabs/style';
import _Tabs from 'antd/es/tabs';
import 'antd/es/button/style';
import _Button from 'antd/es/button';
import 'antd/es/message/style';
import _message from 'antd/es/message';
import _set from 'lodash/set';
import _isEmpty from 'lodash/isEmpty';
import _get from 'lodash/get';
import { s as styleInject, b as __awaiter, c as __generator, e as api, d as __assign } from './index.js';
import { useFormTabs, MyForm, GestationalWeekProjectTree, getFormData } from '@lm_fe/components_m';
import { mchcUtils } from '@lm_fe/env';
import React__default, { useState, useEffect } from 'react';
import { a as getsurveyList, b as updateSurveyList } from './request.js';
import { DoctorEnd_检验检查_History } from '@lm_fe/pages';
import 'lodash/size';
import '@lm_fe/utils';
import 'lodash/orderBy';
import 'lodash/map';
import '@lm_fe/components';
import 'antd/es/collapse/style';
import 'antd/es/collapse';
import 'antd/es/badge/style';
import 'antd/es/badge';
import 'lodash/assign';
import '@ant-design/icons';
import '@lm_fe/service';
var css_248z = ".survey-list .check-items-wrapper {\n  padding: 24px;\n}\n.survey-list .check-items-wrapper .ant-timeline.ant-timeline-label .ant-timeline-item-label {\n  width: 120px;\n}\n.survey-list .check-items-wrapper .ant-timeline.ant-timeline-label .ant-timeline-item-tail {\n  left: 132px;\n}\n.survey-list .check-items-wrapper .ant-timeline.ant-timeline-label .ant-timeline-item-head {\n  left: 132px;\n}\n.survey-list .check-items-wrapper .ant-timeline.ant-timeline-label .ant-timeline-item-left .ant-timeline-item-content {\n  left: 124px;\n  width: calc(100% - 120px - 20px);\n}\n.survey-list .check-items-wrapper .check-items {\n  font-weight: 600;\n}\n.survey-list .check-items-wrapper .arrived-current .ant-timeline-item-head {\n  width: 18px;\n  height: 18px;\n  border-width: 4px;\n}\n.survey-list .check-items-wrapper .arrived-current .ant-timeline-item-head {\n  margin-left: -8px;\n}\n.survey-list .check-items-wrapper .detail-item-date {\n  color: #383f4a;\n}\n.survey-list .check-items-wrapper .detail-item-reports-normal {\n  color: #007aff;\n}\n.survey-list .check-items-wrapper .detail-item-reports-abnormal {\n  color: #ff4974;\n}\n.survey-list .check-items-wrapper .color-red {\n  color: #ff4974;\n}\n.survey-list .check-items-wrapper .color-grey {\n  color: #828c99;\n}\n.survey-list .check-items-wrapper .color-orange {\n  color: #ff7a00;\n}\n.survey-list .check-items-wrapper .make-bold {\n  font-weight: bold;\n}\n";
styleInject(css_248z);
function SurverList(props) {
  var _this = this;
  var isShowListModal = props.isShowListModal,
    isAllPregnancies = props.isAllPregnancies,
    headerInfo = props.headerInfo,
    closeModal = props.closeModal,
    furtherRefresh = props.furtherRefresh;
  var forms = useFormTabs(3)[0];
  var _a = useState({});
  _a[0];
  _a[1];
  var _b = useState([]);
  _b[0];
  var set_surveyFormConfig = _b[1];
  var _c = useState([]),
    ultrasoundConfig = _c[0],
    set_ultrasoundConfig = _c[1];
  var _d = useState({}),
    formHandler = _d[0],
    set_formHandler = _d[1];
  var _e = useState([]);
  _e[0];
  _e[1];
  var _f = useState('1'),
    activeKey = _f[0],
    set_activeKey = _f[1];
  var _g = useState({
      '1': {},
      '2': {}
    }),
    formData = _g[0],
    set_formData = _g[1];
  useEffect(function () {
    (function () {
      return __awaiter(_this, void 0, void 0, function () {
        var surveyConfig, ultrasoundConfig, b;
        return __generator(this, function (_a) {
          switch (_a.label) {
            case 0:
              return [4, api.further.getSurveyFormConfig()];
            case 1:
              surveyConfig = _a.sent();
              return [4, api.further.getUltrasoundFormConfig()];
            case 2:
              ultrasoundConfig = _a.sent();
              b = _get(ultrasoundConfig, 'fields');
              set_surveyFormConfig(_get(surveyConfig, 'fields'));
              set_ultrasoundConfig(b);
              get_FormData();
              return [2];
          }
        });
      });
    })();
    return function () {};
  }, []);
  function get_FormData() {
    return __awaiter(this, arguments, void 0, function (tab, needRequest) {
      var id, res;
      var _a;
      var _b;
      if (tab === void 0) {
        tab = '1';
      }
      if (needRequest === void 0) {
        needRequest = false;
      }
      return __generator(this, function (_c) {
        switch (_c.label) {
          case 0:
            if (!_isEmpty(formData[tab]) && !needRequest) return [2, false];
            id = _get(props, "headerInfo.id");
            return [4, getsurveyList[tab](id)];
          case 1:
            res = _c.sent();
            if (tab == '1') {
              _set(res, "hbvdna", (_b = _get(res, "hbvdna")) === null || _b === void 0 ? void 0 : _b.replace(/&amp;lt;/, '<'));
            }
            set_formData(__assign(__assign({}, formData), (_a = {}, _a[tab] = res, _a)));
            return [2];
        }
      });
    });
  }
  function handleBtnClick() {
    return __awaiter(this, void 0, void 0, function () {
      var _a, res, validCode, resData;
      return __generator(this, function (_b) {
        switch (_b.label) {
          case 0:
            forms[0].submit();
            if (activeKey == '1') {
              furtherRefresh && furtherRefresh();
            }
            if (!(activeKey === '2')) return [3, 5];
            return [4, formHandler.submit()];
          case 1:
            _a = _b.sent(), res = _a.res, validCode = _a.validCode;
            if (!validCode) return [3, 3];
            resData = getFormData(res);
            return [4, updateSurveyList[activeKey](__assign(__assign({}, resData), {
              id: _get(props, "headerInfo.id")
            }))];
          case 2:
            _b.sent();
            closeModal();
            return [3, 4];
          case 3:
            _message.destroy();
            _message.error('请完善表单项！');
            _b.label = 4;
          case 4:
            return [3, 6];
          case 5:
            closeModal();
            _b.label = 6;
          case 6:
            return [2];
        }
      });
    });
  }
  function setFormHandler(data) {
    set_formHandler(data);
  }
  function handleTabChange(key) {
    if (key == 1 || key == 2) {
      get_FormData(key);
    }
    set_activeKey(key);
  }
  var buttons = [/*#__PURE__*/React__default.createElement("div", null, /*#__PURE__*/React__default.createElement(_Button, {
    onClick: function onClick() {
      return closeModal();
    }
  }, "\u53D6\u6D88"), /*#__PURE__*/React__default.createElement(_Button, {
    type: "primary",
    onClick: function onClick() {
      return handleBtnClick();
    }
  }, "\u786E\u5B9A"))];
  return /*#__PURE__*/React__default.createElement(_Modal, {
    className: "survey-list",
    width: "96vw",
    centered: true,
    footer: isAllPregnancies ? null : buttons,
    title: null,
    bodyStyle: {
      height: '90vh'
    },
    visible: isShowListModal,
    onCancel: function onCancel() {
      return closeModal();
    }
  }, /*#__PURE__*/React__default.createElement(_Tabs, {
    size: "small",
    activeKey: activeKey,
    onChange: handleTabChange.bind(this)
  }, /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    className: "survey-form label-width6",
    tab: "\u68C0\u9A8C\u68C0\u67E5",
    key: "1"
  }, /*#__PURE__*/React__default.createElement(DoctorEnd_检验检查_History, {
    form: forms[0],
    pregnancyId: headerInfo === null || headerInfo === void 0 ? void 0 : headerInfo.id
  })), /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    className: "survey-form label-width6",
    tab: "\u8D85\u58F0\u68C0\u67E5",
    key: "2"
  }, /*#__PURE__*/React__default.createElement(MyForm, {
    config: ultrasoundConfig,
    value: formData['2'],
    getFormHandler: function getFormHandler(formHandler) {
      return setFormHandler(formHandler);
    },
    submitChange: false
  })), /*#__PURE__*/React__default.createElement(_Tabs.TabPane, {
    className: "check-items-wrapper",
    tab: "\u5B55\u671F\u5FC5\u67E5\u9879\u76EE",
    key: "3"
  }, /*#__PURE__*/React__default.createElement(GestationalWeekProjectTree, {
    pregnancyId: mchcUtils.getDoctorEndId()
  }))));
}
export { SurverList as default };
//# sourceMappingURL=prenatal-visit.pregnancy.doctor-end17.js.map
