var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/plus/saasDevice/devicePlanning/components/WorkAreaList/index.tsx
var WorkAreaList_exports = {};
__export(WorkAreaList_exports, {
  default: () => WorkAreaList_default
});
module.exports = __toCommonJS(WorkAreaList_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_materials = require("@pisell/materials");
var import_icons = require("@ant-design/icons");
var import_core = require("@dnd-kit/core");
var import_sortable = require("@dnd-kit/sortable");
var import_utilities = require("@dnd-kit/utilities");
var import_classnames = __toESM(require("classnames"));
var import_index = require("./index.less");
var SortableWorkAreaItem = ({
  item,
  selected,
  title,
  getText,
  onSelect,
  onEdit,
  onDelete
}) => {
  const {
    attributes,
    isDragging,
    listeners,
    setNodeRef,
    transform,
    transition
  } = (0, import_sortable.useSortable)({ id: item.id });
  const menuItems = [
    {
      key: "edit",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, null),
      label: getText("pisell2.saas.device-planning.action.edit"),
      onClick: ({ domEvent }) => {
        domEvent.stopPropagation();
        onEdit(item);
      }
    },
    {
      key: "delete",
      danger: true,
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.DeleteOutlined, null),
      label: getText("pisell2.saas.device-planning.action.delete"),
      onClick: ({ domEvent }) => {
        domEvent.stopPropagation();
        onDelete(item);
      }
    }
  ];
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      ref: setNodeRef,
      className: (0, import_classnames.default)("saas-device-planning-workarea-item", {
        "is-selected": selected,
        "is-dragging": isDragging
      }),
      style: {
        transform: import_utilities.CSS.Transform.toString(transform),
        transition
      },
      onClick: () => onSelect(item.id)
    },
    /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: "saas-device-planning-workarea-item__drag",
        ...attributes,
        ...listeners
      },
      /* @__PURE__ */ import_react.default.createElement(import_icons.HolderOutlined, null)
    ),
    /* @__PURE__ */ import_react.default.createElement("span", { className: "saas-device-planning-workarea-item__name" }, title),
    /* @__PURE__ */ import_react.default.createElement(
      import_antd.Dropdown,
      {
        trigger: ["click"],
        menu: { items: menuItems },
        placement: "bottomRight"
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          type: "text",
          className: "saas-device-planning-workarea-item__more",
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.MoreOutlined, null),
          onClick: (event) => event.stopPropagation()
        }
      )
    )
  );
};
var WorkAreaList = ({
  loading,
  workAreas,
  selectedWorkAreaId,
  getText,
  translation,
  onCreate,
  onSelect,
  onEdit,
  onDelete,
  onSortEnd
}) => {
  const sensors = (0, import_core.useSensors)(
    (0, import_core.useSensor)(import_core.PointerSensor, {
      activationConstraint: { distance: 8 }
    }),
    (0, import_core.useSensor)(import_core.KeyboardSensor, {
      coordinateGetter: import_sortable.sortableKeyboardCoordinates
    })
  );
  return /* @__PURE__ */ import_react.default.createElement("aside", { className: "saas-device-planning-sider" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-sider__header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-sider__title" }, getText("pisell2.saas.device-planning.work-areas")), /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "primary", size: "middle", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null), onClick: onCreate }, getText("pisell2.saas.device-planning.create"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-sider__list" }, loading && !workAreas.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-sider__loading" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, null)) : workAreas.length ? /* @__PURE__ */ import_react.default.createElement(
    import_core.DndContext,
    {
      sensors,
      collisionDetection: import_core.closestCenter,
      onDragEnd: onSortEnd
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_sortable.SortableContext,
      {
        items: workAreas.map((item) => item.id),
        strategy: import_sortable.verticalListSortingStrategy
      },
      workAreas.map((item) => /* @__PURE__ */ import_react.default.createElement(
        SortableWorkAreaItem,
        {
          key: item.id,
          item,
          title: translation(item.name),
          selected: item.id === selectedWorkAreaId,
          getText,
          onSelect,
          onEdit,
          onDelete
        }
      ))
    )
  ) : /* @__PURE__ */ import_react.default.createElement(import_antd.Empty, { image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE })));
};
var WorkAreaList_default = WorkAreaList;
