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/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_materials = require("@pisell/materials");
var import_antd = require("antd");
var import_antd2 = require("antd");
var import_icons = require("@ant-design/icons");
var import_model = require("../../../../model");
var import_DeviceIcon = __toESM(require("../../../../components/shared/DeviceIcon"));
var import_LinkStatusTag = __toESM(require("../../../../components/shared/LinkStatusTag"));
var import_OnlineStatus = __toESM(require("../../../../components/shared/OnlineStatus"));
var import_index = require("./index.less");
var STRUCTURE_TAG_COLOR = {
  composite: "blue",
  component: "purple"
};
var DeviceTable = ({
  activeKind,
  data,
  loading,
  search,
  typeFilter,
  structureFilter,
  typeOptions,
  structureOptions,
  page,
  pageSize,
  getText,
  onSearchChange,
  onTypeFilterChange,
  onStructureFilterChange,
  onPageChange,
  onAdd,
  onSortChange,
  onRowClick
}) => {
  const columns = (0, import_react.useMemo)(
    () => {
      const nameColumn = {
        title: getText("pisell2.saas.device-planning.column.name"),
        dataIndex: "name",
        key: "name",
        render: (name, record) => {
          var _a;
          return /* @__PURE__ */ import_react.default.createElement("span", { className: "saas-device-planning-device-table__device-name" }, ((_a = record._raw.type) == null ? void 0 : _a.icon) ? /* @__PURE__ */ import_react.default.createElement(
            import_DeviceIcon.default,
            {
              className: "saas-device-planning-device-table__device-icon",
              icon: record._raw.type.icon,
              kind: record._raw.type_kind
            }
          ) : null, name);
        }
      };
      const typeColumn = {
        title: getText("pisell2.saas.device-planning.column.device-type"),
        dataIndex: "typeName",
        key: "typeName"
      };
      const shortNumberColumn = {
        title: getText(
          "pisell2.saas.device-planning.device-short-number.label"
        ),
        key: "shortNumber",
        width: 170,
        render: (_value, record) => {
          var _a;
          return ((_a = record._raw.short_number) == null ? void 0 : _a.trim()) || "-";
        }
      };
      const modelColumn = {
        title: getText("pisell2.saas.device-planning.column.device-model"),
        dataIndex: "modelName",
        key: "modelName"
      };
      const structureColumn = {
        title: getText("pisell2.saas.device-planning.column.structure"),
        dataIndex: "structure",
        key: "structure",
        width: 120,
        render: (value) => value ? /* @__PURE__ */ import_react.default.createElement(import_antd2.Tag, { color: STRUCTURE_TAG_COLOR[value] }, getText(`pisell2.saas.device-planning.structure.${value}`)) : "-"
      };
      if (activeKind === "dumb" || activeKind === "integrated") {
        return [nameColumn, typeColumn, modelColumn];
      }
      return [
        nameColumn,
        shortNumberColumn,
        typeColumn,
        modelColumn,
        structureColumn,
        {
          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__ */ import_react.default.createElement(import_LinkStatusTag.default, { value, getText })
        },
        {
          title: getText("pisell2.saas.device-planning.column.online-status"),
          dataIndex: "status",
          key: "status",
          width: 140,
          render: (value) => /* @__PURE__ */ import_react.default.createElement(
            import_OnlineStatus.default,
            {
              value,
              getText,
              className: "saas-device-planning-device-table__online-status",
              dotClassName: "saas-device-planning-device-table__status-dot"
            }
          )
        }
      ];
    },
    [activeKind, getText]
  );
  const pagedData = (0, import_react.useMemo)(() => {
    const start = (page - 1) * pageSize;
    return data.slice(start, start + pageSize);
  }, [data, page, pageSize]);
  const handleSortChange = (detail) => {
    const sortedPageData = (detail == null ? 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__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__empty" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "SettingOutlined" }), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__empty-title" }, getText(`pisell2.saas.device-planning.empty.${activeKind}.title`)), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__empty-desc" }, getText(`pisell2.saas.device-planning.empty.${activeKind}.desc`)), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      type: "primary",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null),
      className: "saas-device-planning-device-table__empty-button",
      onClick: onAdd
    },
    getText(import_model.ADD_BUTTON_KEY[activeKind])
  ));
  return /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__toolbar" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__filters" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Input,
    {
      allowClear: true,
      prefix: /* @__PURE__ */ import_react.default.createElement(import_icons.SearchOutlined, null),
      value: search,
      placeholder: getText(import_model.SEARCH_PLACEHOLDER_KEY[activeKind]),
      onChange: (event) => onSearchChange(event.target.value),
      style: { width: 260 }
    }
  ), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      allowClear: true,
      value: typeFilter,
      placeholder: getText("pisell2.saas.device-planning.all-types"),
      options: typeOptions,
      onChange: (value) => onTypeFilterChange(value),
      style: { width: 200 }
    }
  ), activeKind === "smart" ? /* @__PURE__ */ import_react.default.createElement(
    import_antd.Select,
    {
      allowClear: true,
      value: structureFilter,
      placeholder: getText("pisell2.saas.device-planning.all-structures"),
      options: structureOptions.map((option) => ({
        label: getText(option.labelKey),
        value: option.value
      })),
      onChange: (value) => onStructureFilterChange(value),
      style: { width: 160 }
    }
  ) : null), /* @__PURE__ */ import_react.default.createElement(
    import_materials.Button,
    {
      type: "primary",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null),
      className: "saas-device-planning-device-table__add-button",
      onClick: onAdd
    },
    getText(import_model.ADD_BUTTON_KEY[activeKind])
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-device-planning-device-table__table" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Table,
    {
      key: activeKind,
      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,
        showPagination: true,
        onChange: (value) => {
          const nextPageSize = value.size || pageSize;
          onPageChange(
            nextPageSize !== pageSize ? 1 : value.page || 1,
            nextPageSize
          );
        }
      },
      showTitle: false,
      showSubTitle: false,
      locale: { emptyText: emptyContent },
      bordered: false
    }
  )));
};
var DeviceTable_default = DeviceTable;
