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