import 'antd/es/message/style';
import _message from 'antd/es/message';
import 'antd/es/form/style';
import _Form from 'antd/es/form';
import { b as __awaiter, c as __generator, d as __assign } from './index.js';
import { BaseEditPanelFormFC } from '@lm_fe/components_m';
import { getSearchParamsValue, getSearchParamsAll, safeExec } from '@lm_fe/utils';
import React__default, { useState, useEffect } from 'react';
import { u as useConfigHook, g as getConfigFullUrl } from './utils.js';
import { mchcModal__ } from '@lm_fe/pages';
import '@lm_fe/env';
import 'antd/es/tabs/style';
import 'antd/es/tabs';
import 'lodash/size';
import 'lodash/get';
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 'antd/es/button/style';
import 'antd/es/button';
import 'lodash/assign';
import '@ant-design/icons';
import '@lm_fe/service';
function MyConfigPanel(props) {
  var _this = this;
  var _a;
  var id = (_a = getSearchParamsValue('id')) !== null && _a !== void 0 ? _a : props.id;
  var form = _Form.useForm()[0];
  var _b = useConfigHook(props),
    config = _b[0],
    model = _b[1];
  var _c = useState(),
    data = _c[0],
    setData = _c[1];
  function sync() {
    var _a;
    (_a = model.current) === null || _a === void 0 ? void 0 : _a.sync(getSearchParamsAll()).then(processData);
  }
  function processData() {
    return __awaiter(this, arguments, void 0, function (data) {
      var _data;
      if (data === void 0) {
        data = {};
      }
      return __generator(this, function (_a) {
        switch (_a.label) {
          case 0:
            _data = data;
            if (!(config === null || config === void 0 ? void 0 : config.handleBeforePopup)) return [3, 2];
            return [4, config.handleBeforePopup(data)];
          case 1:
            _data = _a.sent();
            _a.label = 2;
          case 2:
            setData(_data);
            form.setFieldsValue(_data);
            return [2];
        }
      });
    });
  }
  useEffect(function () {
    var _a;
    if (id) {
      (_a = model.current) === null || _a === void 0 ? void 0 : _a.getOne(id, {
        params: getSearchParamsAll()
      }).then(processData);
    } else {
      if (config === null || config === void 0 ? void 0 : config.needSync) {
        sync();
      } else {
        processData();
      }
    }
    return function () {};
  }, [config]);
  return /*#__PURE__*/React__default.createElement("div", {
    style: {
      height: '100%',
      overflowY: 'scroll',
      padding: 12,
      paddingBottom: 64,
      background: '#fff'
    }
  }, /*#__PURE__*/React__default.createElement(BaseEditPanelFormFC, {
    form: form,
    data: data,
    formDescriptions: config === null || config === void 0 ? void 0 : config.tableColumns,
    onPrint: function onPrint() {
      mchcModal__.open('print_modal', {
        modal_data: {
          requestData: {
            url: "".concat(getConfigFullUrl(config), "print")
          }
        }
      });
    },
    onSync: (config === null || config === void 0 ? void 0 : config.needSync) ? sync : undefined,
    onFinish: function onFinish(v) {
      return __awaiter(_this, void 0, void 0, function () {
        var _data, value;
        var _a, _b, _c;
        return __generator(this, function (_d) {
          _data = __assign(__assign({}, data), v);
          value = (_a = safeExec(config === null || config === void 0 ? void 0 : config.beforeSubmit, _data)) !== null && _a !== void 0 ? _a : _data;
          (_c = (_b = model.current) === null || _b === void 0 ? void 0 : _b.postOrPut(value)) === null || _c === void 0 ? void 0 : _c.then(function () {
            return _message.success('操作成功');
          });
          return [2];
        });
      });
    }
  }));
}
export { MyConfigPanel as default };
//# sourceMappingURL=pages.config-table.panel.js.map
