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/appDevicePlanning/modules/devices/components/DeviceTable/index.tsx
var DeviceTable_exports = {};
__export(DeviceTable_exports, {
  default: () => DeviceTable_default
});
module.exports = __toCommonJS(DeviceTable_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_classnames = __toESM(require("classnames"));
var import_utils = require("../../utils");
var import_index = require("./index.less");
var DeviceTable = ({
  data,
  loading,
  search,
  page,
  pageSize,
  linkingDeviceId,
  getText,
  translation,
  onSearchChange,
  onPageChange,
  onAdd,
  onLink,
  onTakeBack,
  onTakeover,
  onEdit,
  onDelete
}) => {
  const pagedData = (0, import_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__ */ import_react.default.createElement(
        import_materials.Button,
        {
          className: "saas-app-device-planning-device-table__current-button",
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.CheckOutlined, null),
          disabled: true
        },
        getText("pisell2.saas.device-planning.action.current-device")
      );
    }
    if (record.isLastUsed) {
      return /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          type: "primary",
          className: "saas-app-device-planning-device-table__takeover-button",
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.RollbackOutlined, null),
          loading: isLinking,
          disabled: isDisabled,
          onClick: () => onTakeBack(record)
        },
        getText("pisell2.saas.device-planning.action.take-back")
      );
    }
    if (record.link === "linked") {
      return /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          type: "primary",
          className: "saas-app-device-planning-device-table__takeover-button",
          icon: /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "ThunderboltOutlined" }),
          loading: isLinking,
          disabled: isDisabled,
          onClick: () => onTakeover(record)
        },
        getText("pisell2.saas.device-planning.action.takeover")
      );
    }
    return /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: "primary",
        icon: /* @__PURE__ */ import_react.default.createElement(import_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__ */ import_react.default.createElement(import_icons.EditOutlined, null),
      label: getText("pisell2.saas.device-planning.action.edit"),
      onClick: ({ domEvent }) => {
        domEvent.stopPropagation();
        onEdit(record);
      }
    },
    {
      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(record);
      }
    }
  ];
  const emptyContent = /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "SettingOutlined" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty-title" }, getText("pisell2.saas.device-planning.empty.devices-title")), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__empty-desc" }, getText("pisell2.saas.device-planning.empty.devices-desc")), /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { type: "primary", icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null), onClick: onAdd }, getText("pisell2.saas.device-planning.add-device")));
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table" }, /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: "saas-app-device-planning-device-table__toolbar",
      style: { width: "100%" }
    },
    /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: "saas-app-device-planning-device-table__filters",
        style: { width: "100%" }
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.Input,
        {
          allowClear: true,
          prefix: /* @__PURE__ */ import_react.default.createElement(import_icons.SearchOutlined, null),
          value: search,
          placeholder: getText("pisell2.saas.device-planning.search-devices"),
          onChange: (event) => onSearchChange(event.target.value),
          style: { width: "100%" }
        }
      )
    )
  ), /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)("saas-app-device-planning-device-table__cards", {
        "is-loading": loading
      })
    },
    pagedData.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__cards-grid" }, pagedData.map((record) => {
      var _a;
      return /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          key: record.id,
          className: (0, import_classnames.default)(
            "saas-app-device-planning-device-table__card",
            {
              "saas-app-device-planning-device-table__card--last-used": record.isLastUsed
            }
          )
        },
        /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__card-header" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__name" }, /* @__PURE__ */ import_react.default.createElement("span", null, record.name || "-"), record.isCurrent ? /* @__PURE__ */ import_react.default.createElement(
          import_antd.Tag,
          {
            color: "blue",
            className: "saas-app-device-planning-device-table__current-tag"
          },
          getText(
            "pisell2.saas.device-planning.action.current"
          )
        ) : record.isLastUsed ? /* @__PURE__ */ import_react.default.createElement(
          import_antd.Tag,
          {
            color: "warning",
            className: "saas-app-device-planning-device-table__current-tag"
          },
          getText(
            "pisell2.saas.device-planning.action.last-used"
          )
        ) : null), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__workarea" }, translation((_a = record._raw.workarea) == null ? void 0 : _a.description) || (record._raw.workarea ? translation(record._raw.workarea.name) : ""))), /* @__PURE__ */ import_react.default.createElement(
          import_antd.Dropdown,
          {
            trigger: ["click"],
            menu: { items: getMenuItems(record) },
            placement: "bottomRight"
          },
          /* @__PURE__ */ import_react.default.createElement(
            import_materials.Button,
            {
              type: "text",
              className: "saas-app-device-planning-device-table__more",
              icon: /* @__PURE__ */ import_react.default.createElement(import_icons.MoreOutlined, null),
              onClick: (event) => event.stopPropagation()
            }
          )
        )),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__tags" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Tag, { color: record.link === "linked" ? "blue" : "default" }, getText(
          `pisell2.saas.device-planning.status.${record.link}`
        ) || record.link), (record == null ? void 0 : record.link) === "linked" ? /* @__PURE__ */ import_react.default.createElement(import_antd.Tag, { color: record.status === "online" ? "green" : "red" }, getText(
          `pisell2.saas.device-planning.status.${record.status}`
        ) || record.status) : null),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__info" }, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("span", null, getText(
          "pisell2.saas.device-planning.column.device-model"
        )), /* @__PURE__ */ import_react.default.createElement("strong", null, record.modelName || "-")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("span", null, getText("pisell2.saas.device-planning.column.profile")), /* @__PURE__ */ import_react.default.createElement("strong", null, record.profileName || "-")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("span", null, getText("pisell2.saas.device-planning.column.hardware")), /* @__PURE__ */ import_react.default.createElement("strong", null, (0, import_utils.getDeviceHardwareModel)(record) || "-")), /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("span", null, getText(
          "pisell2.saas.device-planning.device-short-number.label"
        )), /* @__PURE__ */ import_react.default.createElement("strong", null, record._raw.short_number || "-"))),
        /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-device-planning-device-table__action" }, renderAction(record))
      );
    })) : emptyContent
  ), data.length > pageSize ? /* @__PURE__ */ import_react.default.createElement(
    import_antd.Pagination,
    {
      className: "saas-app-device-planning-device-table__pagination",
      current: page,
      pageSize,
      total: data.length,
      showSizeChanger: true,
      onChange: onPageChange
    }
  ) : null);
};
var DeviceTable_default = DeviceTable;
