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/file-export/task/export-item.tsx
var export_item_exports = {};
__export(export_item_exports, {
  Item: () => Item,
  ItemUI: () => ItemUI
});
module.exports = __toCommonJS(export_item_exports);
var import_react = __toESM(require("react"));
var import_icons = require("@ant-design/icons");
var import_antd = require("antd");
var import_ahooks = require("ahooks");
var import_context = require("../context");
var import_context2 = require("../../config-provider/context");
var ItemUI = (props) => {
  const componentContext = (0, import_react.useContext)(import_context2.ConfigContext);
  const { uiLocale } = componentContext;
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "item" }, /* @__PURE__ */ import_react.default.createElement("span", { className: "filename" }, props.fileName), props.status == 1 ? uiLocale.FileExport.popoDownload : /* @__PURE__ */ import_react.default.createElement(import_icons.Loading3QuartersOutlined, { spin: true }));
};
var DELAY = 5 * 1e3;
var Item = (props) => {
  const componentContext = (0, import_react.useContext)(import_context2.ConfigContext);
  const { uiLocale } = componentContext;
  const { delay = DELAY, progressFn } = (0, import_react.useContext)(import_context.GlobalTaskContext);
  const [status, setStatus] = (0, import_react.useState)(0);
  const timer = (0, import_react.useRef)(null);
  const { runAsync } = (0, import_ahooks.useRequest)(progressFn, { manual: true });
  const errorDownload = (0, import_react.useCallback)(() => {
    import_antd.notification.error({
      duration: 6,
      message: props.fileName + uiLocale.FileExport.failed,
      description: uiLocale.FileExport.repeat
    });
  }, [props.fileName]);
  const successDownload = (0, import_react.useCallback)(() => {
    import_antd.notification.success({
      duration: 6,
      message: props.fileName + uiLocale.FileExport.success,
      description: uiLocale.FileExport.popoDownload
    });
  }, [props.fileName]);
  const clearTimer = () => {
    props.callback && props.callback(props.taskId);
    clearInterval(timer.current);
    timer.current = null;
  };
  const queryTaskProcess = (0, import_react.useCallback)(() => {
    runAsync({ processKey: props.taskId }).then(({ code, data }) => {
      if (+code !== 200) {
        errorDownload();
        clearTimer();
        return;
      }
      if (+code === 200 && +data.status === 1) {
        setStatus(1);
        successDownload();
        clearTimer();
      }
    }).catch(() => {
      errorDownload();
      clearTimer();
    });
  }, [runAsync, props, timer]);
  (0, import_react.useEffect)(() => {
    if (!timer.current) {
      timer.current = setInterval(() => {
        queryTaskProcess();
      }, delay);
    }
  }, [delay, queryTaskProcess, timer]);
  return /* @__PURE__ */ import_react.default.createElement(ItemUI, { ...props, status });
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Item,
  ItemUI
});
