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/DeviceDetailDrawer/components/connectDeviceModal/PickExistingDeviceStep.tsx
var PickExistingDeviceStep_exports = {};
__export(PickExistingDeviceStep_exports, {
  default: () => PickExistingDeviceStep_default
});
module.exports = __toCommonJS(PickExistingDeviceStep_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 PickExistingDeviceStep = ({
  workAreas,
  selectedWorkAreaId,
  currentWorkAreaId,
  filteredDevices,
  connectedDeviceIds,
  loading,
  pickingDeviceId,
  keyword,
  targetKind,
  getText,
  translation,
  getWorkAreaDeviceCount,
  getDeviceCountText,
  onWorkAreaChange,
  onKeywordChange,
  onPickDevice
}) => {
  var _a;
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-areas" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-section-title" }, getText("pisell2.saas.device-planning.connect.work-areas")), /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-section-desc" }, getText("pisell2.saas.device-planning.connect.select-area")), /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-area-list" }, workAreas.map((area) => /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      key: area.id,
      role: "button",
      tabIndex: 0,
      className: `device-detail-drawer__connect-area${selectedWorkAreaId === area.id ? " is-active" : ""}`,
      onClick: () => onWorkAreaChange(area.id)
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-area-header" }, /* @__PURE__ */ import_react.default.createElement("strong", null, translation(area.name) || area.id), area.id === currentWorkAreaId ? /* @__PURE__ */ import_react.default.createElement("span", { className: "device-detail-drawer__connect-current" }, getText("pisell2.saas.device-planning.connect.current")) : null),
    /* @__PURE__ */ import_react.default.createElement("span", null, getDeviceCountText(getWorkAreaDeviceCount(area)))
  )))), /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-targets" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-workarea-name" }, translation(
    (_a = workAreas.find((area) => area.id === selectedWorkAreaId)) == null ? void 0 : _a.name
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-filters" }, /* @__PURE__ */ import_react.default.createElement(
    import_materials.Input,
    {
      allowClear: true,
      prefix: /* @__PURE__ */ import_react.default.createElement(import_icons.SearchOutlined, null),
      value: keyword,
      placeholder: getText("pisell2.saas.device-planning.connect.search"),
      onChange: (event) => onKeywordChange(event.target.value)
    }
  )), /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-device-list" }, /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { spinning: loading || Boolean(pickingDeviceId) }, /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-device-grid" }, filteredDevices.map((device) => {
    var _a2, _b;
    const disabled = connectedDeviceIds.includes(device.id);
    return /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        key: device.id,
        role: "button",
        tabIndex: disabled || pickingDeviceId ? -1 : 0,
        "aria-disabled": disabled || Boolean(pickingDeviceId),
        className: (0, import_classnames.default)(
          "device-detail-drawer__connect-device-card",
          {
            "is-disabled": disabled || Boolean(pickingDeviceId)
          }
        ),
        onClick: () => {
          if (!disabled && !pickingDeviceId) {
            onPickDevice(device);
          }
        }
      },
      /* @__PURE__ */ import_react.default.createElement(
        "span",
        {
          className: `device-detail-drawer__connect-device-icon is-${device.type_kind}`
        },
        /* @__PURE__ */ import_react.default.createElement(
          import_materials.Icon,
          {
            type: ((_a2 = device.type) == null ? void 0 : _a2.icon) || "DesktopOutlined",
            color: import_utils.DEVICE_ICON_COLOR[device.type_kind]
          }
        )
      ),
      /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("strong", null, translation(device.name) || device.id), /* @__PURE__ */ import_react.default.createElement("span", null, translation((_b = device.type) == null ? void 0 : _b.name) || device.type_code))
    );
  })), !filteredDevices.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-empty" }, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Empty,
    {
      image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE,
      description: getText(
        targetKind === "smart" ? "pisell2.saas.device-planning.connect.no-smart" : "pisell2.saas.device-planning.connect.no-peripherals"
      )
    }
  )) : null))));
};
var PickExistingDeviceStep_default = PickExistingDeviceStep;
