const require_runtime = require("../../../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.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");
let _dnd_kit_core = require("@dnd-kit/core");
let _dnd_kit_sortable = require("@dnd-kit/sortable");
let _dnd_kit_utilities = require("@dnd-kit/utilities");
require("./index.less");
//#region src/plus/saasDevice/devicePlanning/components/WorkAreaList/index.tsx
const SortableWorkAreaItem = ({ item, selected, title, getText, onSelect, onEdit, onDelete }) => {
	const { attributes, isDragging, listeners, setNodeRef, transform, transition } = (0, _dnd_kit_sortable.useSortable)({ id: item.id });
	const menuItems = [{
		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(item);
		}
	}, {
		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(item);
		}
	}];
	return /* @__PURE__ */ react.default.createElement("div", {
		ref: setNodeRef,
		className: (0, classnames.default)("saas-device-planning-workarea-item", {
			"is-selected": selected,
			"is-dragging": isDragging
		}),
		style: {
			transform: _dnd_kit_utilities.CSS.Transform.toString(transform),
			transition
		},
		onClick: () => onSelect(item.id)
	}, /* @__PURE__ */ react.default.createElement("span", require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ className: "saas-device-planning-workarea-item__drag" }, attributes), listeners), /* @__PURE__ */ react.default.createElement(_ant_design_icons.HolderOutlined, null)), /* @__PURE__ */ react.default.createElement("span", { className: "saas-device-planning-workarea-item__name" }, title), /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
		trigger: ["click"],
		menu: { items: menuItems },
		placement: "bottomRight"
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "text",
		className: "saas-device-planning-workarea-item__more",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.MoreOutlined, null),
		onClick: (event) => event.stopPropagation()
	})));
};
const WorkAreaList = ({ loading, workAreas, selectedWorkAreaId, getText, translation, onCreate, onSelect, onEdit, onDelete, onSortEnd }) => {
	const sensors = (0, _dnd_kit_core.useSensors)((0, _dnd_kit_core.useSensor)(_dnd_kit_core.PointerSensor, { activationConstraint: { distance: 8 } }), (0, _dnd_kit_core.useSensor)(_dnd_kit_core.KeyboardSensor, { coordinateGetter: _dnd_kit_sortable.sortableKeyboardCoordinates }));
	return /* @__PURE__ */ react.default.createElement("aside", { className: "saas-device-planning-sider" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-sider__header" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-sider__title" }, getText("pisell2.saas.device-planning.work-areas")), /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		size: "middle",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		onClick: onCreate
	}, getText("pisell2.saas.device-planning.create"))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-sider__list" }, loading && !workAreas.length ? /* @__PURE__ */ react.default.createElement("div", { className: "saas-device-planning-sider__loading" }, /* @__PURE__ */ react.default.createElement(antd.Spin, null)) : workAreas.length ? /* @__PURE__ */ react.default.createElement(_dnd_kit_core.DndContext, {
		sensors,
		collisionDetection: _dnd_kit_core.closestCenter,
		onDragEnd: onSortEnd
	}, /* @__PURE__ */ react.default.createElement(_dnd_kit_sortable.SortableContext, {
		items: workAreas.map((item) => item.id),
		strategy: _dnd_kit_sortable.verticalListSortingStrategy
	}, workAreas.map((item) => /* @__PURE__ */ react.default.createElement(SortableWorkAreaItem, {
		key: item.id,
		item,
		title: translation(item.name),
		selected: item.id === selectedWorkAreaId,
		getText,
		onSelect,
		onEdit,
		onDelete
	})))) : /* @__PURE__ */ react.default.createElement(antd.Empty, { image: antd.Empty.PRESENTED_IMAGE_SIMPLE })));
};
//#endregion
exports.default = WorkAreaList;
