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/ConnectionConfigFields.tsx
var ConnectionConfigFields_exports = {};
__export(ConnectionConfigFields_exports, {
  default: () => ConnectionConfigFields_default
});
module.exports = __toCommonJS(ConnectionConfigFields_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_utils = require("../../../../utils");
var BluetoothIcon = () => /* @__PURE__ */ import_react.default.createElement(
  "svg",
  {
    viewBox: "0 0 1024 1024",
    width: "1em",
    height: "1em",
    fill: "currentColor",
    "aria-hidden": "true",
    focusable: "false"
  },
  /* @__PURE__ */ import_react.default.createElement("path", { d: "M844.799642 674.803923 538.533306 521.15859l307.696917-177.029926c10.583033-5.006014 17.398252-15.59621 17.569144-27.302833s-6.332219-22.491247-16.764825-27.804253L475.584626 65.954131c-9.517771-4.846378-20.869307-4.39817-29.974685 1.181919-9.105379 5.581112-14.656815 15.493879-14.656815 26.174126l0 288.760636L210.662931 196.715267c-12.974499-10.915607-32.339546-9.248641-43.255153 3.724835-10.915607 12.973476-9.248641 32.339546 3.724835 43.255153L430.953126 462.312344l0 102.83511L171.558307 775.571954c-13.166881 10.68127-15.181771 30.013571-4.500501 43.180452 6.068206 7.480368 14.924921 11.360745 23.859407 11.360745 6.794753 0 13.634532-2.245134 19.322068-6.859221l220.714867-179.046862 0 283.065937c0 10.689457 5.561669 20.61041 14.680351 26.188452 4.903683 2.99931 10.455119 4.510734 16.019859 4.510734 4.78498 0 9.580193-1.118474 13.980409-3.368724l371.449917-224.085638c10.664897-5.456269 17.182334-16.618493 16.691147-28.589129C863.284645 689.959088 855.875908 679.368892 844.799642 674.803923zM763.458055 315.360458 492.351498 475.082182l0-21.60711c0.563842-3.368724 0.558725-6.801916 0-10.153244L492.351498 143.395898 763.458055 315.360458zM492.351498 877.084952 492.351498 584.489988c0.558725-3.347235 0.562818-6.777357 0-10.146081l0-5.809309 267.472797 137.65822L492.351498 877.084952z" })
);
var CONNECT_CONNECTION_TYPE_OPTIONS = import_utils.CONNECTION_TYPE_OPTIONS.filter(
  (option) => option.value !== "serial"
).map((option) => ({
  ...option,
  icon: option.value === "usb" ? /* @__PURE__ */ import_react.default.createElement(import_icons.UsbOutlined, null) : option.value === "ethernet" ? /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "ApiOutlined" }) : option.value === "wifi" ? /* @__PURE__ */ import_react.default.createElement(import_icons.WifiOutlined, null) : option.value === "bluetooth" ? /* @__PURE__ */ import_react.default.createElement(BluetoothIcon, null) : null
}));
var IPV4_PATTERN = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/;
var needsNetworkConfig = (connectionType) => connectionType === "ethernet" || connectionType === "wifi";
var validateRequired = (message) => [
  {
    required: true,
    message
  }
];
var ConnectionConfigFields = ({
  connectionType,
  networkMethod,
  profileRequired,
  profileOptions,
  getText
}) => {
  const validateIpAddress = (_rule, value) => {
    const ipValue = String(value || "").trim();
    if (!ipValue || IPV4_PATTERN.test(ipValue)) {
      return Promise.resolve();
    }
    return Promise.reject(
      new Error(getText("pisell2.saas.device-planning.connect.ip-address"))
    );
  };
  return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-section-title" }, /* @__PURE__ */ import_react.default.createElement(import_icons.SettingOutlined, null), getText("pisell2.saas.device-planning.connect.configuration")), /* @__PURE__ */ import_react.default.createElement("div", { style: { height: "8px" } }), /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "connection_type",
      label: getText("pisell2.saas.device-planning.connect.connection-type"),
      required: true,
      rules: validateRequired(
        getText("pisell2.saas.device-planning.connect.connection-type")
      )
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Group, { className: "device-detail-drawer__connect-option-grid" }, CONNECT_CONNECTION_TYPE_OPTIONS.map((option) => /* @__PURE__ */ import_react.default.createElement(
      import_antd.Radio,
      {
        key: option.value,
        value: option.value,
        className: "device-detail-drawer__connect-option"
      },
      option.icon,
      option.label
    )))
  ), needsNetworkConfig(connectionType) ? /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "connection_method",
      label: getText(
        "pisell2.saas.device-planning.connect.network-config"
      ),
      required: true,
      rules: validateRequired(
        getText("pisell2.saas.device-planning.connect.network-config")
      )
    },
    /* @__PURE__ */ import_react.default.createElement(import_antd.Radio.Group, { className: "device-detail-drawer__connect-option-grid" }, ["auto", "manual"].map((method) => /* @__PURE__ */ import_react.default.createElement(
      import_antd.Radio,
      {
        key: method,
        value: method,
        className: "device-detail-drawer__connect-option"
      },
      getText(
        method === "auto" ? "pisell2.saas.device-planning.connect.auto-discovery" : "pisell2.saas.device-planning.connect.manual-ip"
      )
    )))
  ), networkMethod === "manual" ? /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "connection_ip",
      label: getText("pisell2.saas.device-planning.connect.ip-address"),
      required: true,
      rules: [
        ...validateRequired(
          getText("pisell2.saas.device-planning.connect.ip-address")
        ),
        { validator: validateIpAddress }
      ]
    },
    /* @__PURE__ */ import_react.default.createElement(import_materials.Input, { placeholder: "192.168.1.100" })
  ) : null) : null, /* @__PURE__ */ import_react.default.createElement(
    import_antd.Form.Item,
    {
      name: "profile_ids",
      label: getText(
        "pisell2.saas.device-planning.connect.peripheral-profiles"
      ),
      required: profileRequired,
      rules: profileRequired ? [
        {
          type: "array",
          required: true,
          min: 1,
          message: getText(
            "pisell2.saas.device-planning.add.device-profile-required"
          )
        }
      ] : [],
      extra: /* @__PURE__ */ import_react.default.createElement("div", { className: "device-detail-drawer__connect-help" }, getText("pisell2.saas.device-planning.connect.profiles-help"))
    },
    /* @__PURE__ */ import_react.default.createElement(
      import_materials.Select,
      {
        mode: "multiple",
        options: profileOptions,
        placeholder: getText(
          "pisell2.saas.device-planning.connect.select-profiles"
        )
      }
    )
  ));
};
var ConnectionConfigFields_default = ConnectionConfigFields;
