const require_runtime = require("../../../../../../../_virtual/_rolldown/runtime.js");
const require_index = require("../../../../../../../locales/index.js");
const require_objectSpread2 = require("../../../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_useEngineContext = require("../../../../../../../hooks/useEngineContext.js");
const require_utils = require("../../../../../utils.js");
const require_serve = require("../../../../../serve.js");
const require_date = require("../../utils/date.js");
const require_download = require("../../utils/download.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let ahooks = require("ahooks");
require("./index.less");
//#region src/components/table/Actions/component/ExportImport/components/ExportFile/index.tsx
const defaultData = {
	skip: 1,
	num: 10
};
const exportStatusOptions = {
	pending: require_index.getText("table-action-export-import-file-pending"),
	processing: require_index.getText("table-action-export-import-file-processing"),
	completed: require_index.getText("table-action-export-import-file-completed"),
	complete: require_index.getText("table-action-export-import-file-completed")
};
const ExportFile = (props) => {
	const { exportImport } = props;
	const { apiUrl, otherParams } = exportImport;
	const [list, setList] = (0, react.useState)([]);
	const context = require_useEngineContext.default();
	require_utils.request.setRequest(context.appHelper.utils.request);
	/**
	* @title: 导出文件
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-06-29 15:17
	*/
	const _historyList = (0, ahooks.useRequest)(require_serve.getExportFile, {
		manual: true,
		onSuccess: (res) => {
			if (res.code == 200) {
				var _res$data;
				setList(((_res$data = res.data) === null || _res$data === void 0 ? void 0 : _res$data.list) || []);
			}
		}
	});
	const init = () => {
		const _defaultParams = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, defaultData), otherParams), {}, { url: apiUrl === null || apiUrl === void 0 ? void 0 : apiUrl.export_file });
		_historyList.run(_defaultParams);
	};
	(0, react.useEffect)(() => {
		init();
	}, [exportImport]);
	const columns = [
		{
			title: require_index.getText("table-action-export-import-file-name"),
			dataIndex: "file_name",
			render: (text, record) => {
				return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, record.status == "completed" || record.status == "complete" ? /* @__PURE__ */ react.default.createElement("a", { onClick: () => {
					require_download.default(record.url, text);
				} }, text) : /* @__PURE__ */ react.default.createElement("span", null, text));
			}
		},
		{
			title: require_index.getText("table-action-export-import-file-content"),
			dataIndex: "setting",
			render: (text, record) => {
				var _text$params, _record$result;
				return /* @__PURE__ */ react.default.createElement("div", null, (text === null || text === void 0 || (_text$params = text.params) === null || _text$params === void 0 || (_text$params = _text$params.ids) === null || _text$params === void 0 ? void 0 : _text$params.length) ? require_index.getText("table-action-export-import-file-content-part") : require_index.getText("table-action-export-import-file-content-all"), " ", require_index.getText("table-action-export-import-file-record")(`${(record === null || record === void 0 || (_record$result = record.result) === null || _record$result === void 0 ? void 0 : _record$result.total) || 0}`));
			}
		},
		{
			title: require_index.getText("table-action-export-import-file-status"),
			dataIndex: "status",
			render: (text) => exportStatusOptions[text]
		},
		{
			title: require_index.getText("table-action-export-import-file-account"),
			dataIndex: "account",
			render: (text) => {
				return text ? /* @__PURE__ */ react.default.createElement("div", null, `${(text === null || text === void 0 ? void 0 : text.first_name) || ""} ${(text === null || text === void 0 ? void 0 : text.last_name) || ""}`) : null;
			}
		},
		{
			title: require_index.getText("table-action-export-import-file-created"),
			dataIndex: "created_at",
			render: (text) => require_date.formatDate(text)
		}
	];
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", { className: "export-history-content" }, /* @__PURE__ */ react.default.createElement(antd.Spin, { spinning: _historyList === null || _historyList === void 0 ? void 0 : _historyList.loading }, /* @__PURE__ */ react.default.createElement("div", { className: "content-hint" }, require_index.getText("table-action-export-import-file-hint"), /* @__PURE__ */ react.default.createElement("a", { onClick: () => init() }, require_index.getText("table-action-export-import-file-refresh"))), /* @__PURE__ */ react.default.createElement(antd.Table, {
		rowClassName: "antd-table-row",
		columns,
		dataSource: list,
		pagination: false,
		rowKey: (record) => record.id,
		scroll: { x: true }
	}))));
};
//#endregion
exports.default = ExportFile;
