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/DisplayFeedbackModal.tsx
var DisplayFeedbackModal_exports = {};
__export(DisplayFeedbackModal_exports, {
  default: () => DisplayFeedbackModal_default
});
module.exports = __toCommonJS(DisplayFeedbackModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_moment = __toESM(require("moment"));
var import_icons = require("@ant-design/icons");
var import_constants = require("../_util/constants");
var import_AddFeedbackModal = __toESM(require("./AddFeedbackModal"));
var import_Vote = __toESM(require("./Vote"));
var import_interface = require("./interface");
var import_context = require("../config-provider/context");
var import_utils = require("../locale/utils");
var import_index = require("./index.less");
var { Search } = import_antd.Input;
var PAGE_SIZE = 10;
var useFetch = (visible, currentPage, searchTerm, type, config, refreshFlag) => {
  const [loading, setLoading] = (0, import_react.useState)(true);
  const [total, setTotal] = (0, import_react.useState)(0);
  const [dataList, setDataList] = (0, import_react.useState)([]);
  const fetchData = (0, import_react.useCallback)(async () => {
    try {
      const { appkey, email, channel, subProductId } = config;
      setLoading(true);
      const payload = {
        appkey,
        channel: [channel],
        email,
        env: "online-project",
        limit: PAGE_SIZE,
        offset: (currentPage - 1) * PAGE_SIZE,
        order: "desc",
        orderBy: "agree_count",
        subProductId: [subProductId],
        name: searchTerm
      };
      const url = type === import_interface.FeedbackType.Advice ? "/api/advise/listByPage" : "/api/ticket/listByPage";
      const res = await fetch(`${import_constants.FEEDBACK_BASE_URL}${url}`, {
        method: "post",
        headers: {
          "Content-Type": "application/json;charset=utf-8",
          appkey,
          email
        },
        body: JSON.stringify(payload)
      });
      const {
        result: { list, totalCount }
      } = await res.json();
      setTotal(totalCount);
      setDataList(
        list.map((item) => ({
          ...item[type === import_interface.FeedbackType.Advice ? "advise" : "ticket"],
          agreeFlag: item.agreeFlag,
          attachmentCount: item.attachmentCount
        }))
      );
    } catch (e) {
      console.log(e);
    } finally {
      setLoading(false);
    }
  }, [config, currentPage, type, searchTerm]);
  (0, import_react.useEffect)(() => {
    visible && fetchData();
  }, [fetchData, visible]);
  (0, import_react.useEffect)(() => {
    refreshFlag && fetchData();
  }, [fetchData, refreshFlag]);
  return { loading, dataList, total, dispatch: fetchData };
};
var DisplayFeedbackModal = (props) => {
  const { btnText, config, visible, onCancel, defaultValues } = props;
  const [currentPage, setCurrentPage] = (0, import_react.useState)(1);
  const [show, setShow] = (0, import_react.useState)(false);
  const [type, setType] = (0, import_react.useState)(import_interface.FeedbackType.Advice);
  const [refreshFlag, setRefreshFlag] = (0, import_react.useState)(false);
  const [searchTerm, setSearchTerm] = (0, import_react.useState)("");
  const { loading, dataList, total, dispatch } = useFetch(!!visible, currentPage, searchTerm, type, config, refreshFlag);
  const onChangeType = (e) => {
    setType(e.target.value);
    setCurrentPage(1);
  };
  const { appkey, email } = config;
  const handleClick = (0, import_react.useCallback)(() => {
    setRefreshFlag(!refreshFlag);
  }, [refreshFlag]);
  (0, import_react.useEffect)(() => {
    !loading && refreshFlag && setRefreshFlag(false);
  }, [loading, refreshFlag]);
  const columns = (uiLocale) => {
    const STATE_MAP = {
      1: {
        color: "#52c41a",
        text: uiLocale.Feedback.Display.new
      },
      2: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.processing
      },
      3: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.processed
      },
      4: {
        color: "#d9d9d9",
        text: uiLocale.Feedback.Display.closed
      },
      5: {
        color: "#d9d9d9",
        text: uiLocale.Feedback.Display.cancel
      },
      6: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.accept
      },
      7: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.accept
      },
      8: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.reject
      },
      14: {
        color: "#1890ff",
        text: uiLocale.Feedback.Display.evaluate
      }
    };
    return [
      {
        key: "agreeCount",
        dataIndex: "agreeCount",
        width: 80,
        render: (value, record) => {
          const { agreeFlag } = record;
          return /* @__PURE__ */ import_react.default.createElement(
            import_Vote.default,
            {
              agreeFlag,
              count: value,
              appkey,
              email,
              id: record.id,
              type,
              handleClick
            }
          );
        }
      },
      {
        dataIndex: "addtime",
        key: "addtime",
        width: 200,
        render: (value, record) => {
          const time = type === import_interface.FeedbackType.Advice ? value : record.createTime;
          return (0, import_moment.default)(time).format("YYYY-MM-DD HH:mm:ss");
        }
      },
      {
        key: "feedbackName",
        dataIndex: "name",
        align: "left",
        ellipsis: true
      },
      {
        key: "attachmentCount",
        dataIndex: "attachmentCount",
        width: 80,
        render: (value) => /* @__PURE__ */ import_react.default.createElement("span", { className: "display-attachmentCount" }, /* @__PURE__ */ import_react.default.createElement(import_icons.PictureOutlined, { className: "display-attachmentCount-icon" }), value)
      },
      {
        key: "feedbackState",
        dataIndex: "state",
        width: 140,
        render: (value) => {
          const typeInfo = STATE_MAP[value] || {};
          return /* @__PURE__ */ import_react.default.createElement("span", { className: "display-status" }, /* @__PURE__ */ import_react.default.createElement("b", { style: { backgroundColor: typeInfo.color } }), typeInfo.text || uiLocale.Feedback.Display.new);
        }
      }
    ];
  };
  const onTableChange = (pagination) => {
    setCurrentPage(pagination.current || 1);
  };
  const onSearch = (value) => {
    setSearchTerm(value);
    setCurrentPage(1);
  };
  return /* @__PURE__ */ import_react.default.createElement(import_context.ConfigContext.Consumer, null, (value) => {
    var _a;
    const { uiLocale, theme = { token: { colorPrimary: "#1677ff" } } } = value;
    return /* @__PURE__ */ import_react.default.createElement(import_antd.ConfigProvider, { ...value }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Modal,
      {
        className: "ehr-feedback-table-modal",
        title: btnText || uiLocale.Feedback.Display.btnText,
        open: visible,
        destroyOnClose: true,
        width: 960,
        maskClosable: false,
        onCancel: onCancel || (() => {
        }),
        footer: null,
        style: { "--primary-color": (_a = theme == null ? void 0 : theme.token) == null ? void 0 : _a.colorPrimary }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "ehr-feedback-table-container" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "feedback-table-header" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Group, { onChange: onChangeType, value: type }, /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Button, { value: import_interface.FeedbackType.Advice }, uiLocale.Feedback.Display.advice), /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Button, { value: import_interface.FeedbackType.Bug }, uiLocale.Feedback.Display.bug)), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement(Search, { allowClear: true, placeholder: uiLocale.Feedback.Display.searchPlaceholder, style: { width: 300, marginRight: 15 }, onSearch }), /* @__PURE__ */ import_react.default.createElement(import_antd.Button, { type: "primary", onClick: () => setShow(true), style: { minWidth: 80 } }, type === import_interface.FeedbackType.Advice ? uiLocale.Feedback.Display.adviceBtnText : uiLocale.Feedback.Display.bugBtnText))), (dataList == null ? void 0 : dataList.length) || loading ? /* @__PURE__ */ import_react.default.createElement(
        import_antd.Table,
        {
          rowKey: "id",
          locale: { emptyText: uiLocale.Empty.description },
          columns: columns(uiLocale),
          dataSource: dataList,
          loading,
          onChange: onTableChange,
          showHeader: false,
          size: "small",
          pagination: {
            current: currentPage,
            total,
            size: "default",
            showTotal: (total2) => (0, import_utils.replaceMessage)(uiLocale.Feedback.Display.tableTotal, { total: `${total2}` })
          }
        }
      ) : /* @__PURE__ */ import_react.default.createElement(import_antd.Empty, null))
    ), /* @__PURE__ */ import_react.default.createElement(
      import_AddFeedbackModal.default,
      {
        visible: show,
        config,
        type,
        defaultValues,
        onOk: () => dispatch(),
        onCancel: () => setShow(false)
      }
    ));
  });
};
var DisplayFeedbackModal_default = DisplayFeedbackModal;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {});
