const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_constants = require("../../constants.js");
let react = require("react");
react = require_runtime.__toESM(react);
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/devicePlanning/components/DeviceTable/index.tsx
const DeviceTable = ({ activeKind, data, loading, search, typeFilter, typeOptions, page, pageSize, getText, onSearchChange, onTypeFilterChange, onPageChange, onAdd, onSortChange, onRowClick }) => {
	const columns = (0, react.useMemo)(() => [
		{
			title: getText("pisell2.saas.device-planning.column.name"),
			dataIndex: "name",
			key: "name",
			render: (name, record) => {
				var _record$_raw$type;
				return /* @__PURE__ */ react.default.createElement("span", { className: "saas-device-planning-device-table__device-name" }, ((_record$_raw$type = record._raw.type) === null || _record$_raw$type === void 0 ? void 0 : _record$_raw$type.icon) ? /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: record._raw.type.icon }) : null, name);
			}
		},
		{
			title: getText("pisell2.saas.device-planning.column.device-type"),
			dataIndex: "typeName",
			key: "typeName"
		},
		{
			title: getText("pisell2.saas.device-planning.column.device-model"),
			dataIndex: "modelName",
			key: "modelName"
		},
		{
			title: getText("pisell2.saas.device-planning.column.profile"),
			dataIndex: "profileName",
			key: "profileName"
		},
		{
			title: getText("pisell2.saas.device-planning.column.link-status"),
			dataIndex: "link",
			key: "link",
			width: 140,
			render: (value) => /* @__PURE__ */ react.default.createElement(_pisell_materials.Tag, { color: value === "linked" ? "green" : "gold" }, getText(`pisell2.saas.device-planning.status.${value}`) || value)
		},
		{
			title: getText("pisell2.saas.device-planning.column.online-status"),
			dataIndex: "status",
			key: "status",
			width: 140,
			render: (value) => /* @__PURE__ */ react.default.createElement("span", { className: "saas-device-planning-device-table__online-status" }, /* @__PURE__ */ react.default.createElement("span", { className: (0, classnames.default)("saas-device-planning-device-table__status-dot", { "is-online": value === "online" }) }), getText(`pisell2.saas.device-planning.status.${value}`) || value)
		}
	], [getText]);
	const pagedData = (0, react.useMemo)(() => {
		const start = (page - 1) * pageSize;
		return data.slice(start, start + pageSize);
	}, [
		data,
		page,
		pageSize
	]);
	const handleSortChange = (detail) => {
		const sortedPageData = (detail === null || detail === void 0 ? void 0 : detail.dataSource) || [];
		const start = (page - 1) * pageSize;
		const nextData = [...data];
		nextData.splice(start, sortedPageData.length, ...sortedPageData);
		onSortChange(nextData);
		return false;
	};
	const emptyContent = /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__empty" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "SettingOutlined" }), /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__empty-title" }, getText(`pisell2.saas.device-planning.empty.${activeKind}.title`)), /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__empty-desc" }, getText(`pisell2.saas.device-planning.empty.${activeKind}.desc`)), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		className: "saas-device-planning-device-table__empty-button",
		onClick: onAdd
	}, getText(require_constants.ADD_BUTTON_KEY[activeKind])));
	return /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__toolbar" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__filters" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Input, {
		allowClear: true,
		prefix: /* @__PURE__ */ react.default.createElement(_ant_design_icons.SearchOutlined, null),
		value: search,
		placeholder: getText(require_constants.SEARCH_PLACEHOLDER_KEY[activeKind]),
		onChange: (event) => onSearchChange(event.target.value),
		style: { width: 260 }
	}), /* @__PURE__ */ react.default.createElement(_pisell_materials.Select, {
		allowClear: true,
		value: typeFilter,
		placeholder: getText("pisell2.saas.device-planning.all-types"),
		options: typeOptions,
		onChange: (value) => onTypeFilterChange(value),
		style: { width: 200 }
	})), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		className: "saas-device-planning-device-table__add-button",
		onClick: onAdd
	}, getText(require_constants.ADD_BUTTON_KEY[activeKind]))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-device-table__table" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Table, {
		rowKey: "id",
		dataSource: pagedData,
		columns,
		rowClassName: "saas-device-planning-device-table__row",
		loading,
		dragSort: data.length > 1,
		virtual: false,
		onSortChange: handleSortChange,
		onRow: (record) => ({ onClick: () => onRowClick(record) }),
		scroll: {
			autoCalc: true,
			scrollToFirstRowOnChange: true
		},
		pagination: {
			localPagination: false,
			current: page,
			pageSize,
			total: data.length,
			showSizeChanger: true,
			onChange: (value) => {
				onPageChange(value.page || 1, value.size || pageSize);
			}
		},
		showTitle: false,
		showSubTitle: false,
		locale: { emptyText: emptyContent },
		bordered: false
	})));
};
//#endregion
exports.default = DeviceTable;
