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/appPeripheral/components/PeripheralActionModal.tsx
var PeripheralActionModal_exports = {};
__export(PeripheralActionModal_exports, {
  default: () => PeripheralActionModal_default
});
module.exports = __toCommonJS(PeripheralActionModal_exports);
var import_react = __toESM(require("react"));
var import_antd = require("antd");
var import_icons = require("@ant-design/icons");
var import_materials = require("@pisell/materials");
var import_classnames = __toESM(require("classnames"));
var usageOptions = ["label", "wristband"];
var isLabelPrinter = (model) => {
  var _a;
  return ((_a = model.peripheral) == null ? void 0 : _a.type_code) === "label_printer";
};
var PeripheralActionModal = ({
  open,
  model,
  variant,
  submitting,
  testLoading,
  getText,
  onClose,
  onEdit,
  onConnect,
  onTest,
  onIgnore,
  onSelectUsage
}) => {
  const isPhone = variant === "phone";
  const showUsage = isLabelPrinter(model);
  const missingUsage = showUsage && !model.usage;
  const connectionType = model.connectionTypeLabel || "-";
  const isComponentConnection = model.connection.type === "component";
  const isConnecting = model.status === "connecting";
  const getHardwareInfo = () => {
    const device = model.physicalDevice;
    if (device == null ? void 0 : device.ip) {
      return {
        label: getText("pisell2.saas.app-peripheral.hardware.ip"),
        value: device.ip
      };
    }
    if (device == null ? void 0 : device.mac) {
      return {
        label: getText("pisell2.saas.app-peripheral.hardware.mac"),
        value: device.mac
      };
    }
    if (device == null ? void 0 : device.port) {
      return {
        label: getText("pisell2.saas.app-peripheral.hardware.port"),
        value: device.port
      };
    }
    return void 0;
  };
  const hardware = getHardwareInfo();
  return /* @__PURE__ */ import_react.default.createElement(
    import_materials.PisellModal,
    {
      open,
      title: getText(
        isComponentConnection ? "pisell2.saas.app-peripheral.component-actions-title" : "pisell2.saas.app-peripheral.peripheral-actions-title"
      ),
      headerDivider: false,
      footerDivider: false,
      footer: null,
      width: isPhone ? "100%" : 560,
      destroyOnClose: true,
      maskClosable: true,
      onCancel: onClose,
      platform: isPhone ? "h5" : void 0,
      mobileModalHeight: isPhone ? "auto" : void 0,
      className: (0, import_classnames.default)("saas-app-peripheral-action-modal", {
        "saas-app-peripheral-action-modal--phone": isPhone
      }),
      bodyStyle: { paddingBottom: "24px" }
    },
    /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__summary" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__icon" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: model.icon })), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__summary-main" }, /* @__PURE__ */ import_react.default.createElement("strong", null, model.title), /* @__PURE__ */ import_react.default.createElement("span", null, model.subtitle)), /* @__PURE__ */ import_react.default.createElement(
      "span",
      {
        className: (0, import_classnames.default)("saas-app-peripheral-action-modal__status", {
          [`is-${model.status}`]: true
        })
      },
      getText(`pisell2.saas.app-peripheral.status.${model.status}`)
    )),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions, { column: 1, size: "small", bordered: true }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Descriptions.Item,
      {
        label: getText("pisell2.saas.app-peripheral.connection-type")
      },
      connectionType
    ), hardware ? /* @__PURE__ */ import_react.default.createElement(import_antd.Descriptions.Item, { label: hardware.label }, hardware.value) : null),
    showUsage ? /* @__PURE__ */ import_react.default.createElement(
      "div",
      {
        className: (0, import_classnames.default)("saas-app-peripheral-action-modal__usage", {
          "is-error": missingUsage
        })
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__usage-main" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__section-title" }, getText("pisell2.saas.app-peripheral.print-usage-title")), /* @__PURE__ */ import_react.default.createElement(
        "div",
        {
          className: (0, import_classnames.default)("saas-app-peripheral-action-modal__usage-tabs", {
            "is-empty": !model.usage,
            "is-disabled": submitting
          })
        },
        usageOptions.map((usage) => /* @__PURE__ */ import_react.default.createElement(
          "button",
          {
            key: usage,
            type: "button",
            className: (0, import_classnames.default)("saas-app-peripheral-action-modal__usage-tab", {
              "is-active": model.usage === usage
            }),
            disabled: submitting,
            onClick: () => onSelectUsage(usage)
          },
          getText(`pisell2.saas.app-peripheral.print-usage.${usage}`)
        ))
      )),
      missingUsage ? /* @__PURE__ */ import_react.default.createElement(
        import_antd.Alert,
        {
          type: "error",
          showIcon: true,
          message: getText("pisell2.saas.app-peripheral.usage-required")
        }
      ) : null
    ) : null,
    /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-action-modal__actions" }, model.canTest ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: "primary",
        className: "saas-app-peripheral-action-modal__primary-action",
        loading: testLoading,
        disabled: submitting,
        onClick: onTest
      },
      getText("pisell2.saas.app-peripheral.test")
    ) : null, model.status !== "connected" ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: "primary",
        className: "saas-app-peripheral-action-modal__primary-action",
        loading: submitting,
        disabled: isConnecting,
        onClick: onConnect
      },
      getText(
        isConnecting ? "pisell2.saas.app-peripheral.status.connecting" : "pisell2.saas.app-peripheral.connect"
      )
    ) : null, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { icon: /* @__PURE__ */ import_react.default.createElement(import_icons.EditOutlined, null), disabled: submitting, onClick: onEdit }, getText("pisell2.saas.app-peripheral.edit")), /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        danger: true,
        icon: isComponentConnection ? /* @__PURE__ */ import_react.default.createElement(import_icons.DeleteOutlined, null) : /* @__PURE__ */ import_react.default.createElement(import_icons.StopOutlined, null),
        disabled: submitting,
        onClick: onIgnore
      },
      getText(
        isComponentConnection ? "pisell2.saas.app-peripheral.delete" : "pisell2.saas.app-peripheral.ignore-connection"
      )
    ))
  );
};
var PeripheralActionModal_default = PeripheralActionModal;
