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 { getImportLog } from "../../../../../serve.js";
import { formatDate } from "../../utils/date.js";
import Detail_default from "./Detail.js";
import React, { useEffect, useRef, useState } from "react";
import { Spin, Table } from "antd";
import { useRequest } from "ahooks";
import "./index.less";
//#region src/components/table/Actions/component/ExportImport/components/ImportLog/index.tsx
const defaultData = {
	skip: 1,
	num: 10
};
const ImportLog = (props) => {
	const { exportImport } = props;
	const { apiUrl, otherParams } = exportImport;
	const detailRef = useRef(null);
	const [list, setList] = useState([]);
	const context = useEngineContext();
	request.setRequest(context.appHelper.utils.request);
	/**
	* @title: 导入日志
	* @description:
	* @return {*}
	* @Author: WangHan
	* @Date: 2024-06-29 15:14
	*/
	const _historyList = useRequest(getImportLog, {
		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.import_log });
		_historyList.run(_defaultParams);
	};
	useEffect(() => {
		init();
	}, [exportImport]);
	const columns = [
		{
			title: getText("table-action-export-import-log-name"),
			dataIndex: "file_name"
		},
		{
			title: getText("table-action-export-import-log-result"),
			dataIndex: "result",
			render: (text, record) => {
				var _record$result;
				return /* @__PURE__ */ React.createElement("div", null, getText("table-action-export-import-log-ok")((text === null || text === void 0 ? void 0 : text.success) || 0), (record === null || record === void 0 || (_record$result = record.result) === null || _record$result === void 0 ? void 0 : _record$result.fail) ? getText("table-action-export-import-log-err")((text === null || text === void 0 ? void 0 : text.fail) || 0) : null, (text === null || text === void 0 ? void 0 : text.fail) ? /* @__PURE__ */ React.createElement("a", {
					style: { marginLeft: "10px" },
					onClick: () => {
						var _detailRef$current, _detailRef$current$op;
						detailRef === null || detailRef === void 0 || (_detailRef$current = detailRef.current) === null || _detailRef$current === void 0 || (_detailRef$current$op = _detailRef$current.open) === null || _detailRef$current$op === void 0 || _detailRef$current$op.call(_detailRef$current, { list: [record] });
					}
				}, getText("table-action-export-import-log-check")) : null);
			}
		},
		{
			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-log-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 }
	}))), /* @__PURE__ */ React.createElement(Detail_default, { ref: detailRef }));
};
//#endregion
export { ImportLog as default };
