const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let _ant_design_icons = require("@ant-design/icons");
require("./index.less");
//#region src/plus/saasDevice/appDevicePlanning/components/DeviceTable/index.tsx
const DeviceTable = ({ data, loading, search, page, pageSize, linkingDeviceId, getText, translation, onSearchChange, onPageChange, onAdd, onLink, onTakeover, onEdit, onDelete }) => {
	const pagedData = (0, react.useMemo)(() => {
		const start = (page - 1) * pageSize;
		return data.slice(start, start + pageSize);
	}, [
		data,
		page,
		pageSize
	]);
	const renderAction = (record) => {
		const isLinking = linkingDeviceId === record.id;
		const isDisabled = Boolean(linkingDeviceId);
		if (record.isCurrent) return /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			className: "saas-app-device-planning-device-table__current-button",
			icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.CheckOutlined, null),
			disabled: true
		}, getText("pisell2.saas.device-planning.action.current-device"));
		if (record.link === "linked") return /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "primary",
			className: "saas-app-device-planning-device-table__takeover-button",
			icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "ThunderboltOutlined" }),
			loading: isLinking,
			disabled: isDisabled,
			onClick: () => onTakeover(record)
		}, getText("pisell2.saas.device-planning.action.takeover"));
		return /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "primary",
			icon: /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "LinkOutlined" }),
			loading: isLinking,
			disabled: isDisabled,
			onClick: () => onLink(record)
		}, getText("pisell2.saas.device-planning.action.link"));
	};
	const getMenuItems = (record) => [{
		key: "edit",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.EditOutlined, null),
		label: getText("pisell2.saas.device-planning.action.edit"),
		onClick: ({ domEvent }) => {
			domEvent.stopPropagation();
			onEdit(record);
		}
	}, {
		key: "delete",
		danger: true,
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.DeleteOutlined, null),
		label: getText("pisell2.saas.device-planning.action.delete"),
		onClick: ({ domEvent }) => {
			domEvent.stopPropagation();
			onDelete(record);
		}
	}];
	const emptyContent = /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "SettingOutlined" }), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty-title" }, getText("pisell2.saas.device-planning.empty.devices-title")), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty-desc" }, getText("pisell2.saas.device-planning.empty.devices-desc")), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		onClick: onAdd
	}, getText("pisell2.saas.device-planning.add-device")));
	return /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table" }, /* @__PURE__ */ react.default.createElement("div", {
		className: "saas-app-device-planning-device-table__toolbar",
		style: { width: "100%" }
	}, /* @__PURE__ */ react.default.createElement("div", {
		className: "saas-app-device-planning-device-table__filters",
		style: { width: "100%" }
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
		allowClear: true,
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.SearchOutlined, null),
		value: search,
		placeholder: getText("pisell2.saas.device-planning.search-devices"),
		onChange: (event) => onSearchChange(event.target.value),
		style: { width: "100%" }
	}))), /* @__PURE__ */ react.default.createElement("div", { className: (0, classnames.default)("saas-app-device-planning-device-table__cards", { "is-loading": loading }) }, pagedData.length ? /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__cards-grid" }, pagedData.map((record) => {
		var _record$_raw$workarea;
		return /* @__PURE__ */ react.default.createElement("div", {
			key: record.id,
			className: "saas-app-device-planning-device-table__card"
		}, /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__card-header" }, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__name" }, /* @__PURE__ */ react.default.createElement("span", null, record.name || "-"), record.isCurrent ? /* @__PURE__ */ react.default.createElement(antd.Tag, {
			color: "blue",
			className: "saas-app-device-planning-device-table__current-tag"
		}, getText("pisell2.saas.device-planning.action.current")) : record.isLastUsed ? /* @__PURE__ */ react.default.createElement(antd.Tag, {
			color: "blue",
			className: "saas-app-device-planning-device-table__current-tag"
		}, getText("pisell2.saas.device-planning.action.last-used")) : null), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__workarea" }, translation((_record$_raw$workarea = record._raw.workarea) === null || _record$_raw$workarea === void 0 ? void 0 : _record$_raw$workarea.description) || (record._raw.workarea ? translation(record._raw.workarea.name) : ""))), /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
			trigger: ["click"],
			menu: { items: getMenuItems(record) },
			placement: "bottomRight"
		}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
			type: "text",
			className: "saas-app-device-planning-device-table__more",
			icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.MoreOutlined, null),
			onClick: (event) => event.stopPropagation()
		}))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__tags" }, /* @__PURE__ */ react.default.createElement(antd.Tag, { color: record.link === "linked" ? "blue" : "default" }, getText(`pisell2.saas.device-planning.status.${record.link}`) || record.link), (record === null || record === void 0 ? void 0 : record.link) === "linked" ? /* @__PURE__ */ react.default.createElement(antd.Tag, { color: record.status === "online" ? "green" : "red" }, getText(`pisell2.saas.device-planning.status.${record.status}`) || record.status) : null), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__info" }, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.device-planning.column.device-model")), /* @__PURE__ */ react.default.createElement("strong", null, record.modelName || "-")), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.device-planning.column.profile")), /* @__PURE__ */ react.default.createElement("strong", null, record.profileName || "-")), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.device-planning.column.hardware")), /* @__PURE__ */ react.default.createElement("strong", null, record.modelName || "-"))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-device-planning-device-table__action" }, renderAction(record)));
	})) : emptyContent), data.length > pageSize ? /* @__PURE__ */ react.default.createElement(antd.Pagination, {
		className: "saas-app-device-planning-device-table__pagination",
		current: page,
		pageSize,
		total: data.length,
		showSizeChanger: true,
		onChange: onPageChange
	}) : null);
};
//#endregion
exports.default = DeviceTable;
