const require_runtime = require("../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_objectWithoutProperties = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectWithoutProperties.js");
const require_const = require("./const.js");
const require_index = require("./SettlementModal/index.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_icon_es_XClose = require("@pisell/icon/es/XClose");
_pisell_icon_es_XClose = require_runtime.__toESM(_pisell_icon_es_XClose);
//#region src/components/eftpos/table.tsx
const _excluded = ["connection", "setting"], _excluded2 = ["connection", "setting"], _excluded3 = ["connection", "setting"];
const { Column } = antd.Table;
const { Title, Text } = antd.Typography;
const App = ({ type, eftposName, tableSize, getList, onEdit, onDel, onRepair, onLog, style, useTyroLog, systemConfigStatus, onClickByTip }, ref) => {
	/**
	* @title: 设置table 列宽
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:26
	*/
	const size = (0, react.useMemo)(() => {
		if (Array.isArray(tableSize)) return [
			tableSize[0] || 200,
			tableSize[1] || 120,
			tableSize[2] || 120,
			tableSize[3] || 260
		];
		return [
			200,
			120,
			120,
			260
		];
	}, [tableSize]);
	(0, react.useMemo)(() => {
		return size.reduce((accumulator, currentValue) => accumulator + currentValue, 0);
	}, [size]);
	const [loading, setLoading] = (0, react.useState)(false);
	const deviceRef = (0, react.useRef)("");
	const [isModalOpen, setModalOpen] = (0, react.useState)(false);
	const [pagination, setPagination] = (0, react.useState)({
		pageSize: 10,
		current: 1,
		total: 0
	});
	const [data, setData] = (0, react.useState)([]);
	const [settlementModalOpen, setSettlementModalOpen] = (0, react.useState)(false);
	const [settlementModalData, setSettlementModalData] = (0, react.useState)(null);
	/**
	* @title: 加载列表数据
	* @param {number} current 加载页数
	* @return {*}
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:25
	*/
	const loadData = function() {
		var _ref = require_asyncToGenerator._asyncToGenerator(function* (current) {
			if (typeof getList !== "function") return Promise.reject(`getList ${getList} is not function`);
			setLoading(true);
			const res = yield getList({
				type,
				num: pagination.pageSize,
				skip: typeof current === "number" ? current : pagination.current
			}).catch((res) => {
				setLoading(false);
			});
			setLoading(false);
			setPagination((p) => require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, p), {}, {
				total: res.data.count,
				current: typeof current === "number" ? current : pagination.current
			}));
			setData(res.data.list);
		});
		return function loadData(_x) {
			return _ref.apply(this, arguments);
		};
	}();
	/**
	* @title:  初始化加载页面
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:25
	*/
	(0, react.useEffect)(() => {
		loadData(1);
	}, []);
	const onAddDevice = () => {
		onEdit();
	};
	/**
	* @title: 编辑设备
	* @param {any} device 设备信息
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:26
	*/
	const onEditDevice = (device) => {
		const { connection, setting } = device;
		onEdit(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_objectWithoutProperties._objectWithoutProperties(device, _excluded)), connection || {}), setting || {}));
	};
	/**
	* @title: 重连设备
	* @param {any} device 设备信息
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:26
	*/
	const onRepairDevice = (device) => {
		const { connection, setting } = device;
		onRepair(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_objectWithoutProperties._objectWithoutProperties(device, _excluded2)), connection || {}), setting || {}));
	};
	/**
	* @title: 重连设备
	* @param {any} device 设备信息
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:26
	*/
	const onLogDevice = (device) => {
		const { connection, setting } = device;
		onLog(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, require_objectWithoutProperties._objectWithoutProperties(device, _excluded3)), connection || {}), setting || {}));
	};
	/**
	* @title: 删除设备信息
	* @param {any} device 设备信息
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:27
	*/
	const onDelDevice = (device) => {
		deviceRef.current = device.id;
		setModalOpen(true);
	};
	/**
	* @title: 分页加载
	* @param {number} num 加载页数
	* @return {*}
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:27
	*/
	const onChangeSize = (num) => {
		loadData(num);
	};
	/**
	* @title: 删除确认按钮
	* @description: 删除完成重新加载数据
	* @Author: hongbing.wang
	* @Date: 2024-08-20 11:28
	*/
	const onOk = () => {
		setModalOpen(false);
		if (deviceRef.current) onDel(deviceRef.current).then(() => {
			return loadData();
		});
	};
	(0, react.useImperativeHandle)(ref, () => ({ loadData }));
	const onSettlement = (device) => {
		console.log("onSettlement", device);
		setSettlementModalOpen(true);
		setSettlementModalData({
			type: "SETTLEMENT",
			card_reader_id: device.id
		});
	};
	const onSettlementEnquiry = (device) => {
		console.log("onSettlementEnquiry", device);
		setSettlementModalOpen(true);
		setSettlementModalData({
			type: "ENQUIRY",
			card_reader_id: device.id
		});
	};
	return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, /* @__PURE__ */ react.default.createElement("div", {
		className: "pisell-lowcode__pos-table",
		style: require_objectSpread2._objectSpread2({}, style || {})
	}, type === "windcave" && !systemConfigStatus ? /* @__PURE__ */ react.default.createElement(antd.Alert, {
		message: _pisell_utils.locales.getText("page.eftpos.text.setting.tip"),
		type: "error",
		style: { margin: "10px 0 0 0" },
		action: /* @__PURE__ */ react.default.createElement(antd.Button, {
			size: "small",
			type: "text",
			onClick: onClickByTip
		}, _pisell_utils.locales.getText("page.eftpos.text.setting.btn"))
	}) : null, /* @__PURE__ */ react.default.createElement(Title, {
		level: 4,
		className: "pisell-lowcode__pos-title"
	}, eftposName, " ", _pisell_utils.locales.getText("page.eftpos.text.device")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__pos-table-act" }, /* @__PURE__ */ react.default.createElement(Text, null, _pisell_utils.locales.getText("page.eftpos.text.device.list")), /* @__PURE__ */ react.default.createElement(antd.Button, {
		type: "primary",
		onClick: onAddDevice,
		style: { height: "48px" }
	}, _pisell_utils.locales.getText("page.eftpos.text.device.add")())), /* @__PURE__ */ react.default.createElement(antd.Table, {
		dataSource: data,
		rowKey: "id",
		pagination: false,
		loading,
		bordered: true,
		scroll: {
			y: "600px",
			x: "100%"
		},
		tableLayout: "fixed"
	}, /* @__PURE__ */ react.default.createElement(Column, {
		title: _pisell_utils.locales.getText("page.eftpos.text.table.name"),
		dataIndex: "name",
		key: "name",
		width: size[0],
		className: "pisell-lowcode__pos-table-col"
	}), /* @__PURE__ */ react.default.createElement(Column, {
		title: _pisell_utils.locales.getText("page.eftpos.text.table.status"),
		width: size[1],
		dataIndex: "status",
		key: "status",
		render: (status) => {
			return _pisell_utils.locales.getText(`page.eftpos.text.${status.toLocaleLowerCase()}`);
		},
		className: "pisell-lowcode__pos-table-col"
	}), /* @__PURE__ */ react.default.createElement(Column, {
		title: _pisell_utils.locales.getText("page.eftpos.text.table.surcharge"),
		dataIndex: "setting",
		key: "setting",
		width: size[2],
		render: (setting) => {
			if (!setting) return /* @__PURE__ */ react.default.createElement(Text, null, "-");
			if (setting.useOriginSurcharge) return /* @__PURE__ */ react.default.createElement(Text, null, "-");
			const array = [setting.constant_rate ? setting.constant_rate + "%" : "", setting.constant_money].filter(Boolean);
			if (array.length === 0) return /* @__PURE__ */ react.default.createElement(Text, null, "-");
			return /* @__PURE__ */ react.default.createElement(Text, null, setting.surcharge ? array.length > 1 ? array.join("+") : array[0] : "-");
		},
		className: "pisell-lowcode__pos-table-col"
	}), /* @__PURE__ */ react.default.createElement(Column, {
		title: _pisell_utils.locales.getText("page.eftpos.text.table.opeartion"),
		width: type === require_const.Eftpos.MX51 ? 600 : size[3],
		key: "opeartion",
		className: "pisell-lowcode__pos-table-col",
		render: (record) => /* @__PURE__ */ react.default.createElement(antd.Space, { size: "middle" }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onRepairDevice(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.repair")), useTyroLog && type === "tyro" ? /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onLogDevice(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.log")) : null, /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onEditDevice(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.edit")), /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onDelDevice(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.delete")), type === require_const.Eftpos.MX51 ? /* @__PURE__ */ react.default.createElement(antd.Space, null, /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onSettlement(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.settlement")), /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "link",
			onClick: () => onSettlementEnquiry(record)
		}, _pisell_utils.locales.getText("page.eftpos.text.settlement_enquiry"))) : null)
	})), /* @__PURE__ */ react.default.createElement(antd.Pagination, {
		style: { textAlign: "right" },
		pageSize: pagination.pageSize,
		current: pagination.current,
		total: pagination.total,
		onChange: onChangeSize,
		onShowSizeChange: onChangeSize
	})), /* @__PURE__ */ react.default.createElement(antd.Modal, {
		open: isModalOpen,
		width: 400,
		centered: true,
		onCancel: () => setModalOpen(false),
		closeIcon: /* @__PURE__ */ react.default.createElement(_pisell_icon_es_XClose.default, {
			size: 20,
			style: { fontSize: "24px" }
		}),
		footer: /* @__PURE__ */ react.default.createElement("div", { style: {
			display: "flex",
			gap: "12px"
		} }, /* @__PURE__ */ react.default.createElement(antd.Button, {
			block: true,
			onClick: () => setModalOpen(false),
			style: {
				flex: 1,
				height: "48px",
				borderRadius: "8px"
			}
		}, _pisell_utils.locales.getText("page.eftpos.text.table.del.cancel")), /* @__PURE__ */ react.default.createElement(antd.Button, {
			type: "primary",
			block: true,
			onClick: onOk,
			style: {
				flex: 1,
				height: "48px",
				borderRadius: "8px"
			}
		}, _pisell_utils.locales.getText("page.eftpos.text.table.del.delete")))
	}, /* @__PURE__ */ react.default.createElement("div", { style: { height: "34px" } }), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__pos-table-del-title" }, _pisell_utils.locales.getText("page.eftpos.text.table.del.title")), /* @__PURE__ */ react.default.createElement("div", { className: "pisell-lowcode__pos-table-del-text" }, _pisell_utils.locales.getText("page.eftpos.text.table.del.text"))), settlementModalOpen && /* @__PURE__ */ react.default.createElement(require_index.default, {
		open: settlementModalOpen,
		onClose: () => setSettlementModalOpen(false),
		data: settlementModalData
	}));
};
var table_default = react.default.forwardRef(App);
//#endregion
exports.default = table_default;
