var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/feedback/AddFeedbackModal.tsx
var AddFeedbackModal_exports = {};
__export(AddFeedbackModal_exports, {
  default: () => AddFeedbackModal
});
module.exports = __toCommonJS(AddFeedbackModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_interface = require("./interface");
var import_context = require("../config-provider/context");
var import_index = require("./index.less");
var { TextArea } = import_antd.Input;
var { Dragger } = import_antd.Upload;
var layout = {
  labelCol: { span: 4 },
  wrapperCol: { span: 18 }
};
var BASE_URL = "https://overmind-project.netease.com";
var ADVICE_OPTION = {
  Tips: "对系统有任何建议和需求欢迎直接提报！\n提需求的正确姿势：描述需求背后遇到的具体问题和场景即可～",
  Title: {
    Label: "一句话描述",
    Placeholder: "请简要描述你的需求"
  },
  Description: {
    Label: "需求场景描述",
    Placeholder: "提需求的正确姿势：描述需求背后遇到的具体业务问题和场景即可～当然如果你有建议和想法也可以一并记录在这里。"
  },
  Attachments: {
    Label: "补充图片说明"
  },
  TypeLabel: {
    FormLabel: "场景类型",
    AdviceLabel: "提需求",
    AdviceDesc: "产品的功能与体验改进建议",
    TicketLabel: "报BUG",
    TicketDesc: "产品使用过程中遇到的问题"
  }
};
var BUG_OPTION = {
  Tips: "如在系统使用过程中发现任何问题或BUG，欢迎直接反馈哦，我们每天会有值班同学跟进处理。 \n <b>提BUG的正确姿势：操作时间、操作人、操作步骤与对象、报错信息（截图最佳）等。</b>",
  Title: {
    Label: "一句话描述",
    Placeholder: "请简要描述你遇到的问题"
  },
  Description: {
    Label: "问题描述",
    Placeholder: "请描述问题的细节：操作时间、操作人、操作步骤与对象、报错信息等"
  },
  Attachments: {
    Label: "问题截图"
  },
  TypeLabel: {
    FormLabel: "场景类型",
    AdviceLabel: "提需求",
    AdviceDesc: "产品的功能与体验改进建议",
    TicketLabel: "报BUG",
    TicketDesc: "产品使用过程中遇到的问题"
  }
};
var TYPE_INFO = {
  [import_interface.FeedbackType.Advice]: ADVICE_OPTION,
  [import_interface.FeedbackType.Bug]: BUG_OPTION
};
var AddFeedbackModal = class extends import_react.Component {
  constructor(props) {
    super(props);
    this.hideModal = () => {
      var _a, _b;
      this.setState({ visible: false });
      (_b = (_a = this.props).onCancel) == null ? void 0 : _b.call(_a);
    };
    this.onChangeBug = () => {
      this.setState({ type: import_interface.FeedbackType.Bug }, () => {
        this.formRef.current.resetFields();
      });
    };
    this.onChangeAdvice = () => {
      this.setState({ type: import_interface.FeedbackType.Advice }, () => {
        this.formRef.current.resetFields();
      });
    };
    this.onOk = async () => {
      try {
        const {
          config: { appkey, email, level = 2 },
          config,
          onOk
        } = this.props;
        const { type } = this.state;
        const values = await this.formRef.current.validateFields();
        const { attachments } = values;
        if (attachments) {
          const jsonArr = attachments == null ? void 0 : attachments.filter((file) => file.percent === 100).map((file) => file.response.result);
          Object.assign(values, { attachments: JSON.stringify(jsonArr) });
        }
        this.setState({
          btnLoading: true
        });
        const url = type === import_interface.FeedbackType.Advice ? "/api/advise/add4Everyone" : "/api/ticket/add4Everyone";
        const res = await fetch(`${BASE_URL}${url}`, {
          method: "post",
          headers: {
            "Content-Type": "application/json;charset=utf-8",
            appkey,
            email
          },
          body: JSON.stringify({
            ...config,
            level,
            env: "online-project",
            submitEmail: email,
            ...values
          })
        });
        const { code, msg } = await res.json();
        if (code === 200) {
          this.hideModal();
          this.formRef.current.resetFields();
          import_antd.message.success("提交成功");
          onOk && onOk(type);
        } else {
          import_antd.message.error(msg);
        }
      } catch (e) {
        console.log(e);
      } finally {
        this.setState({
          btnLoading: false
        });
      }
    };
    this.beforeUpload = (file, fileList) => {
      for (const item of fileList) {
        const { size, name } = item;
        if (size >= 40 * 1024 * 1024) {
          import_antd.message.error(`上传失败！${name}超过40M`);
          return import_antd.Upload.LIST_IGNORE;
        }
      }
      return true;
    };
    this.onUpload = (info) => {
      try {
        const { response, status } = info.file;
        if (status === "error") {
          throw response.msg;
        }
        if (status === "done") {
          const { code } = response;
          if (code !== 200 && code !== "200") {
            throw response.msg;
          }
        }
      } catch (error) {
        import_antd.message.error("上传失败");
      }
    };
    this.normFile = (e) => {
      if (Array.isArray(e)) {
        return e;
      }
      return e && e.fileList;
    };
    this.getInitialValues = (type) => {
      const { defaultValues } = this.props;
      const defaultKeyValueMap = {
        [import_interface.FeedbackType.Bug]: {
          name: defaultValues == null ? void 0 : defaultValues.bugName,
          description: defaultValues == null ? void 0 : defaultValues.bugDescription
        },
        [import_interface.FeedbackType.Advice]: {
          name: defaultValues == null ? void 0 : defaultValues.adviceName,
          description: defaultValues == null ? void 0 : defaultValues.adviceDescription
        }
      };
      return defaultKeyValueMap[type];
    };
    this.state = {
      type: props.type || import_interface.FeedbackType.Advice,
      visible: !!props.visible,
      btnLoading: false,
      props
    };
    this.formRef = import_react.default.createRef();
  }
  static getDerivedStateFromProps(nextProps, prevState) {
    const { visible, type } = nextProps;
    if (visible !== prevState.visible && visible !== prevState.props.visible) {
      return {
        visible,
        props: nextProps
      };
    }
    if (type !== prevState.type && type !== prevState.props.type) {
      return {
        type,
        props: nextProps
      };
    }
    return {
      props: nextProps
    };
  }
  render() {
    const { visible, btnLoading, type } = this.state;
    const {
      prefixCls,
      typeInfo,
      btnText,
      config: { appkey, email },
      bugFirst
    } = this.props;
    const {
      Tips,
      Title: { Label: TitleLabel, Placeholder: TitlePlaceholder },
      Description: { Label: DescLabel, Placeholder: DescPlaceholder },
      Attachments: { Label: AttachLabel },
      TypeLabel: { FormLabel, AdviceLabel, AdviceDesc, TicketLabel, TicketDesc }
    } = (typeInfo == null ? void 0 : typeInfo[type]) ?? TYPE_INFO[type];
    const { name, description } = this.getInitialValues(type);
    return /* @__PURE__ */ import_react.default.createElement(import_context.ConfigContext.Consumer, null, (value) => /* @__PURE__ */ import_react.default.createElement(import_antd.ConfigProvider, { ...value, prefixCls: prefixCls ? prefixCls : value.prefixCls }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Modal,
      {
        className: "ehr-addFeedback-modal",
        title: btnText,
        open: visible,
        destroyOnClose: true,
        width: 800,
        maskClosable: false,
        onCancel: this.hideModal,
        onOk: this.onOk,
        okButtonProps: {
          loading: btnLoading
        }
      },
      /* @__PURE__ */ import_react.default.createElement(import_antd.Form, { ref: this.formRef, ...layout }, /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: FormLabel, required: true }, /* @__PURE__ */ import_react.default.createElement("div", { className: `ehr-feedback-type-container ${bugFirst ? "ehr-feedback-type-container-reverse" : ""}` }, /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `ehr-feedback-type ${type === import_interface.FeedbackType.Advice ? "ehr-feedback-type-selected" : null}`,
          onClick: this.onChangeAdvice
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.BulbFilled, { className: "ehr-type-icon" }),
        /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "feedback-type-title" }, AdviceLabel), /* @__PURE__ */ import_react.default.createElement("div", { className: "feedback-type-subTitle" }, AdviceDesc))
      ), /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: `ehr-feedback-type ${type === import_interface.FeedbackType.Bug ? "ehr-feedback-type-selected" : null}`,
          onClick: this.onChangeBug
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.BugFilled, { className: "ehr-type-icon" }),
        /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "feedback-type-title" }, TicketLabel), /* @__PURE__ */ import_react.default.createElement("div", { className: "feedback-type-subTitle" }, TicketDesc))
      ))), /* @__PURE__ */ import_react.default.createElement("div", { className: "ehr-feedback-tips" }, /* @__PURE__ */ import_react.default.createElement(import_icons.ExclamationCircleOutlined, { className: "tip-icon" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "ehr-feedback-tips-content", dangerouslySetInnerHTML: { __html: Tips } })), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: TitleLabel, name: "name", initialValue: name, required: true, rules: [{ required: true }] }, /* @__PURE__ */ import_react.default.createElement(import_antd.Input, { placeholder: TitlePlaceholder, maxLength: 100 })), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: DescLabel, name: "description", initialValue: description }, /* @__PURE__ */ import_react.default.createElement(TextArea, { rows: 4, placeholder: DescPlaceholder, maxLength: 500 })), /* @__PURE__ */ import_react.default.createElement(import_antd.Form.Item, { label: AttachLabel, name: "attachments", valuePropName: "fileList", getValueFromEvent: this.normFile }, /* @__PURE__ */ import_react.default.createElement(
        Dragger,
        {
          multiple: true,
          beforeUpload: this.beforeUpload,
          onChange: this.onUpload,
          action: `${BASE_URL}/api/upload`,
          accept: "image/jpeg,image/png",
          headers: {
            appkey,
            email
          }
        },
        /* @__PURE__ */ import_react.default.createElement("p", null, /* @__PURE__ */ import_react.default.createElement(import_icons.InboxOutlined, { className: "ehr-feedback-upload" })),
        /* @__PURE__ */ import_react.default.createElement("p", null, "点击/拖拽/粘贴文件到这里，单个文件不超过40M。 ")
      )))
    )));
  }
};
AddFeedbackModal.defaultProps = {
  btnText: "提需求 / 报BUG",
  typeInfo: TYPE_INFO,
  defaultValues: {}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
