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/index.tsx
var appPeripheral_exports = {};
__export(appPeripheral_exports, {
  default: () => appPeripheral_default
});
module.exports = __toCommonJS(appPeripheral_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_ahooks = require("ahooks");
var import_classnames = __toESM(require("classnames"));
var import_utils = require("@pisell/utils");
var import_useEngineContext = __toESM(require("../../../hooks/useEngineContext"));
var import_useLocale = __toESM(require("../../../hooks/useLocale"));
var import_responsive = require("../../../responsive");
var import_utils2 = require("../../../utils");
var import_serve = require("./serve");
var import_hooks = require("./hooks");
var import_peripheralConnectionService = require("./services/peripheralConnectionService");
var import_locales = __toESM(require("./locales"));
var import_constants = require("./constants");
var import_utils3 = require("./utils");
var import_peripheralRuntime = require("./utils/peripheralRuntime");
var import_ConnectExistingDeviceModal = __toESM(require("./components/ConnectExistingDeviceModal"));
var import_EditDeviceModal = __toESM(require("./components/EditDeviceModal"));
var import_PeripheralConnectionCardContainer = __toESM(require("./components/PeripheralConnectionCardContainer"));
var import_index = require("./index.less");
var PERIPHERAL_STATUS_CHANGE_CHANNEL = "peripheral.statusChange";
var localBindingHydrationCache = /* @__PURE__ */ new Map();
var getStoredIotDevice = (app) => {
  var _a;
  try {
    const iotDevice = JSON.parse(((_a = app == null ? void 0 : app.storage) == null ? void 0 : _a.getStorage("iotDevice")) || "{}");
    return {
      id: (iotDevice == null ? void 0 : iotDevice.id) !== void 0 && (iotDevice == null ? void 0 : iotDevice.id) !== null ? Number(iotDevice.id) : void 0
    };
  } catch (e) {
    return {};
  }
};
var getConnectionListParams = (sourceDeviceId) => ({
  type: "dumb",
  source_device_id: sourceDeviceId,
  with: [
    "targetDevice.type",
    "targetDevice.model.brand",
    "targetDevice.workarea",
    "profiles"
  ]
});
var createLocalBindingMap = (bindings) => bindings.reduce((result, binding) => {
  result[Number(binding.connection_id)] = binding;
  return result;
}, {});
var hydrateLocalBindingMapOnce = async (sourceDeviceId, loadBindings) => {
  const cached = localBindingHydrationCache.get(sourceDeviceId);
  if (cached == null ? void 0 : cached.hydrated) return cached.bindingMap;
  if (cached == null ? void 0 : cached.promise) return cached.promise;
  const promise = loadBindings().then((bindingMap) => {
    localBindingHydrationCache.set(sourceDeviceId, {
      hydrated: true,
      bindingMap
    });
    return bindingMap;
  }).catch((error) => {
    localBindingHydrationCache.delete(sourceDeviceId);
    throw error;
  });
  localBindingHydrationCache.set(sourceDeviceId, {
    hydrated: false,
    bindingMap: (cached == null ? void 0 : cached.bindingMap) || {},
    promise
  });
  return promise;
};
var updateLocalBindingMapCache = (sourceDeviceId, bindingMap) => {
  localBindingHydrationCache.set(sourceDeviceId, {
    hydrated: true,
    bindingMap
  });
};
var unsubscribePubsub = (pubsub, subscription, handler) => {
  var _a;
  if (typeof subscription === "function") {
    subscription();
    return;
  }
  if (typeof (subscription == null ? void 0 : subscription.unsubscribe) === "function") {
    subscription.unsubscribe();
    return;
  }
  (_a = pubsub == null ? void 0 : pubsub.unsubscribe) == null ? void 0 : _a.call(pubsub, PERIPHERAL_STATUS_CHANGE_CHANNEL, handler);
};
var findStatusChangeRow = (rows, payload, physicalDevice) => {
  var _a, _b, _c, _d;
  const connectionId = (_a = payload.binding) == null ? void 0 : _a.connection_id;
  if (connectionId) {
    return rows.find((row) => row.id === Number(connectionId));
  }
  const uuid = (physicalDevice == null ? void 0 : physicalDevice.uuid) || ((_b = payload.binding) == null ? void 0 : _b.physical_uuid) || ((_d = (_c = payload.binding) == null ? void 0 : _c.physical_device) == null ? void 0 : _d.uuid);
  if (!uuid) return void 0;
  return rows.find(
    (row) => {
      var _a2;
      return ((_a2 = row.physical) == null ? void 0 : _a2.uuid) === uuid || (0, import_peripheralRuntime.getPeripheralUuid)(row.connection) === uuid;
    }
  );
};
var SaasAppPeripheral = ({
  className,
  style,
  showBack = false,
  onBack,
  onManageProfiles,
  onTest,
  variant
}) => {
  var _a;
  const context = (0, import_useEngineContext.default)();
  const locale = (0, import_useLocale.default)();
  const currentVariant = variant || "desktop";
  import_utils.locales.init(import_locales.default, locale || "en");
  const getText = import_utils.locales.getText;
  const translation = (0, import_hooks.useTranslation)();
  const utils = ((_a = context == null ? void 0 : context.appHelper) == null ? void 0 : _a.utils) || {};
  const [storedIotDevice, setStoredIotDevice] = (0, import_react.useState)(
    () => {
      var _a2;
      return getStoredIotDevice((_a2 = utils == null ? void 0 : utils.getApp) == null ? void 0 : _a2.call(utils));
    }
  );
  const [connectModal, setConnectModal] = (0, import_react.useState)();
  const [editingDevice, setEditingDevice] = (0, import_react.useState)();
  const [removingConnection, setRemovingConnection] = (0, import_react.useState)();
  const [confirmAction, setConfirmAction] = (0, import_react.useState)();
  const [initializing, setInitializing] = (0, import_react.useState)(false);
  const [rows, setRows] = (0, import_react.useState)([]);
  const localBindingMapRef = (0, import_react.useRef)({});
  const rowsRef = (0, import_react.useRef)([]);
  (0, import_react.useEffect)(() => {
    if (utils == null ? void 0 : utils.request) {
      import_utils2.request.setRequest(utils.request);
    }
  }, [utils == null ? void 0 : utils.request]);
  (0, import_react.useEffect)(() => {
    var _a2;
    const nextDevice = getStoredIotDevice((_a2 = utils == null ? void 0 : utils.getApp) == null ? void 0 : _a2.call(utils));
    setStoredIotDevice(
      (prev) => prev.id === nextDevice.id ? prev : nextDevice
    );
  }, [utils == null ? void 0 : utils.getApp]);
  const getAppInstance = (0, import_ahooks.useMemoizedFn)(() => {
    var _a2;
    return (_a2 = utils == null ? void 0 : utils.getApp) == null ? void 0 : _a2.call(utils);
  });
  (0, import_react.useEffect)(() => {
    rowsRef.current = rows;
  }, [rows]);
  const currentDeviceRequest = (0, import_ahooks.useRequest)(import_serve.getDeviceDetail, { manual: true });
  const connectionRequest = (0, import_ahooks.useRequest)(import_serve.getDeviceConnections, { manual: true });
  const workAreaRequest = (0, import_ahooks.useRequest)(import_serve.getWorkAreas, { manual: true });
  const typeRequest = (0, import_ahooks.useRequest)(
    () => (0, import_serve.getDeviceTypes)({
      kind: "dumb",
      with: [
        "activeModels",
        "activeModels.activeProfiles",
        "activeModels.brand"
      ]
    }),
    { manual: true }
  );
  const createConnectionRequest = (0, import_ahooks.useRequest)(import_serve.createDeviceConnection, {
    manual: true
  });
  const updateConnectionRequest = (0, import_ahooks.useRequest)(
    (params) => (0, import_serve.updateDeviceConnection)(params.id, params.payload),
    { manual: true }
  );
  const updateDeviceRequest = (0, import_ahooks.useRequest)(
    (params) => (0, import_serve.updateDevice)(params.id, params.payload),
    { manual: true }
  );
  const deleteConnectionRequest = (0, import_ahooks.useRequest)(import_serve.deleteDeviceConnection, {
    manual: true
  });
  const deleteDeviceRequest = (0, import_ahooks.useRequest)(import_serve.deleteDevice, { manual: true });
  const currentDevice = currentDeviceRequest.data || void 0;
  const workAreas = (0, import_react.useMemo)(
    () => workAreaRequest.data || [],
    [workAreaRequest.data]
  );
  const models = (0, import_react.useMemo)(
    () => (0, import_utils3.flattenDeviceModels)(typeRequest.data || []),
    [typeRequest.data]
  );
  const loading = initializing || currentDeviceRequest.loading || connectionRequest.loading || workAreaRequest.loading;
  const hydrateLocalBindings = (0, import_ahooks.useMemoizedFn)(
    async (nextConnections) => {
      const sourceDeviceId = storedIotDevice.id;
      if (!sourceDeviceId) return localBindingMapRef.current;
      localBindingMapRef.current = await hydrateLocalBindingMapOnce(
        sourceDeviceId,
        async () => {
          const bindings = await (0, import_peripheralConnectionService.syncLocalPeripheralBindings)({
            app: getAppInstance(),
            connections: nextConnections
          });
          return createLocalBindingMap(bindings);
        }
      );
      return localBindingMapRef.current;
    }
  );
  const patchLocalBindingMap = (0, import_ahooks.useMemoizedFn)(
    (row, physical, usage) => {
      const binding = (0, import_peripheralRuntime.createLocalPeripheralBinding)(row.connection, physical, usage);
      localBindingMapRef.current = {
        ...localBindingMapRef.current,
        [row.id]: binding
      };
      updateLocalBindingMapCache(
        row.connection.source_device_id,
        localBindingMapRef.current
      );
    }
  );
  const loadConnections = (0, import_ahooks.useMemoizedFn)(async (options = {}) => {
    if (!storedIotDevice.id) return;
    const nextConnections = await connectionRequest.runAsync(
      getConnectionListParams(storedIotDevice.id)
    );
    const localBindingMap = options.hydrateLocal ? await hydrateLocalBindings(nextConnections || []) : localBindingMapRef.current;
    setRows(
      (prevRows) => (0, import_peripheralRuntime.mergeConnectionRows)(prevRows, nextConnections || [], localBindingMap)
    );
    return nextConnections;
  });
  const reloadConnectionsImmediately = (0, import_ahooks.useMemoizedFn)(() => {
    loadConnections();
  });
  const patchRowPhysical = (0, import_ahooks.useMemoizedFn)(
    (rowId, physical) => {
      setRows(
        (prevRows) => prevRows.map((row) => {
          if (row.id !== rowId) return row;
          patchLocalBindingMap(row, physical, row.usage);
          return {
            ...row,
            physical
          };
        })
      );
    }
  );
  const patchRowUsage = (0, import_ahooks.useMemoizedFn)(
    (rowId, usage) => {
      setRows(
        (prevRows) => prevRows.map((row) => {
          if (row.id !== rowId) return row;
          patchLocalBindingMap(row, row.physical, usage);
          return {
            ...row,
            usage
          };
        })
      );
    }
  );
  const applySyncedBinding = (0, import_ahooks.useMemoizedFn)(
    (row, physical, binding) => {
      localBindingMapRef.current = {
        ...localBindingMapRef.current,
        [row.id]: binding
      };
      updateLocalBindingMapCache(
        row.connection.source_device_id,
        localBindingMapRef.current
      );
      setRows((prevRows) => {
        const nextRows = prevRows.map(
          (prevRow) => prevRow.id === row.id ? {
            ...prevRow,
            physical,
            usage: binding.peripheral_usage
          } : prevRow
        );
        rowsRef.current = nextRows;
        return nextRows;
      });
    }
  );
  const handlePeripheralStatusChange = (0, import_ahooks.useMemoizedFn)(
    async (payload) => {
      var _a2, _b;
      const physicalDevice = (payload == null ? void 0 : payload.data) || ((_a2 = payload == null ? void 0 : payload.event) == null ? void 0 : _a2.data);
      if (!(physicalDevice == null ? void 0 : physicalDevice.uuid)) return;
      const row = findStatusChangeRow(rowsRef.current, payload, physicalDevice);
      if (!row) return;
      try {
        const result = await (0, import_peripheralConnectionService.syncPeripheralConnectionStatus)({
          app: getAppInstance(),
          connection: row.connection,
          physicalDevice,
          peripheralUsage: ((_b = payload.binding) == null ? void 0 : _b.peripheral_usage) ?? row.usage
        });
        applySyncedBinding(row, result.physicalDevice, result.binding);
      } catch (e) {
      }
    }
  );
  (0, import_react.useEffect)(() => {
    var _a2;
    const pubsub = ((_a2 = getAppInstance()) == null ? void 0 : _a2.pubsub) || (utils == null ? void 0 : utils.pubsub);
    if (!(pubsub == null ? void 0 : pubsub.subscribe)) return void 0;
    const handler = (payload) => {
      void handlePeripheralStatusChange(payload);
    };
    const subscription = pubsub.subscribe(
      PERIPHERAL_STATUS_CHANGE_CHANNEL,
      handler
    );
    return () => {
      unsubscribePubsub(pubsub, subscription, handler);
    };
  }, [
    handlePeripheralStatusChange,
    getAppInstance,
    utils == null ? void 0 : utils.getApp,
    utils == null ? void 0 : utils.pubsub
  ]);
  (0, import_ahooks.useMount)(() => {
    if (!storedIotDevice.id) return;
    if (utils == null ? void 0 : utils.request) {
      import_utils2.request.setRequest(utils.request);
    }
    const runInitialLoad = async () => {
      setInitializing(true);
      try {
        await Promise.all([
          currentDeviceRequest.runAsync(storedIotDevice.id),
          workAreaRequest.runAsync(),
          typeRequest.runAsync(),
          loadConnections({ hydrateLocal: true })
        ]);
      } finally {
        setInitializing(false);
      }
    };
    runInitialLoad();
  });
  const getPeripheral = (connection) => (connection == null ? void 0 : connection.target_device) || void 0;
  const getPeripheralName = (connection) => {
    const peripheral = getPeripheral(connection);
    return peripheral ? translation(peripheral.name) || String(peripheral.id) : "-";
  };
  const toPeripheralRow = (device) => (0, import_utils3.createDeviceRow)(device, translation);
  const handleCreateConnection = async (payload) => {
    try {
      await createConnectionRequest.runAsync(payload);
      (0, import_materials.PisellToast)({
        content: getText("pisell2.saas.app-peripheral.connect-success"),
        duration: 2
      });
      setConnectModal(void 0);
      reloadConnectionsImmediately();
    } catch (e) {
    }
  };
  const handleUpdateConnection = async (id, payload) => {
    try {
      await updateConnectionRequest.runAsync({ id, payload });
      (0, import_materials.PisellToast)({
        content: getText("pisell2.saas.app-peripheral.connect-success"),
        duration: 2
      });
      setConnectModal(void 0);
      reloadConnectionsImmediately();
    } catch (e) {
    }
  };
  const handleUpdateDevice = async (id, payload) => {
    try {
      await updateDeviceRequest.runAsync({ id, payload });
      (0, import_materials.PisellToast)({
        content: getText("pisell2.saas.app-peripheral.save-success"),
        duration: 2
      });
      setEditingDevice(void 0);
      reloadConnectionsImmediately();
    } catch (e) {
    }
  };
  const handleConfirmDangerAction = async () => {
    if (!removingConnection || !confirmAction) return;
    try {
      if (confirmAction === "remove-connection") {
        await deleteConnectionRequest.runAsync(removingConnection.id);
        (0, import_materials.PisellToast)({
          content: getText("pisell2.saas.app-peripheral.remove-success"),
          duration: 2
        });
      } else {
        const peripheral = getPeripheral(removingConnection);
        if (!peripheral) return;
        await deleteDeviceRequest.runAsync(peripheral.id);
        (0, import_materials.PisellToast)({
          content: getText("pisell2.saas.app-peripheral.delete-success"),
          duration: 2
        });
      }
      setConfirmAction(void 0);
      setRemovingConnection(void 0);
      reloadConnectionsImmediately();
    } catch (e) {
    }
  };
  const addMenuItems = [
    {
      key: "existing",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.LinkOutlined, null),
      label: getText("pisell2.saas.app-peripheral.add-existing"),
      onClick: () => setConnectModal({ mode: "existing" })
    },
    {
      key: "new",
      icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null),
      label: getText("pisell2.saas.app-peripheral.add-new"),
      onClick: () => setConnectModal({ mode: "new" })
    }
  ];
  const removeName = getPeripheralName(removingConnection);
  const dangerSubmitting = deleteConnectionRequest.loading || deleteDeviceRequest.loading;
  return /* @__PURE__ */ import_react.default.createElement(
    "div",
    {
      className: (0, import_classnames.default)(
        "saas-app-peripheral",
        `saas-app-peripheral--${currentVariant}`,
        className
      ),
      style
    },
    /* @__PURE__ */ import_react.default.createElement("header", { className: "saas-app-peripheral__header" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__header-main" }, showBack ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.Button,
      {
        type: "text",
        icon: /* @__PURE__ */ import_react.default.createElement(import_icons.ArrowLeftOutlined, null),
        className: "saas-app-peripheral__back",
        onClick: onBack
      }
    ) : null, /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__title" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "ApiOutlined" }), /* @__PURE__ */ import_react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.title"))), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__subtitle" }, getText("pisell2.saas.app-peripheral.subtitle")))), /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__header-actions" }, /* @__PURE__ */ import_react.default.createElement(import_materials.Button, { onClick: onManageProfiles }, getText("pisell2.saas.app-peripheral.manage-profiles")), /* @__PURE__ */ import_react.default.createElement(
      import_antd.Dropdown,
      {
        menu: { items: addMenuItems },
        trigger: ["click"],
        placement: "bottomRight",
        disabled: !currentDevice
      },
      /* @__PURE__ */ import_react.default.createElement(
        import_materials.Button,
        {
          type: "primary",
          icon: /* @__PURE__ */ import_react.default.createElement(import_icons.PlusOutlined, null),
          disabled: !currentDevice
        },
        getText("pisell2.saas.app-peripheral.add")
      )
    ))),
    /* @__PURE__ */ import_react.default.createElement(import_antd.Spin, { spinning: loading, wrapperClassName: "saas-app-peripheral__spin" }, !storedIotDevice.id ? /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Empty,
      {
        image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE,
        description: getText(
          "pisell2.saas.app-peripheral.no-current-device"
        )
      }
    )) : rows.length ? /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__list" }, rows.map((row) => /* @__PURE__ */ import_react.default.createElement(
      import_PeripheralConnectionCardContainer.default,
      {
        key: row.id,
        row,
        getText,
        variant: currentVariant,
        translation,
        getAppInstance,
        onPhysicalChange: patchRowPhysical,
        onUsageChange: patchRowUsage,
        onTest,
        onEdit: (item) => {
          const peripheral = getPeripheral(item);
          if (peripheral) {
            setEditingDevice(toPeripheralRow(peripheral));
          }
        },
        onRemove: setRemovingConnection
      }
    ))) : /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ import_react.default.createElement(
      import_antd.Empty,
      {
        image: import_antd.Empty.PRESENTED_IMAGE_SIMPLE,
        description: getText(
          "pisell2.saas.app-peripheral.no-peripherals"
        )
      }
    ))),
    connectModal && currentDevice ? /* @__PURE__ */ import_react.default.createElement(
      import_ConnectExistingDeviceModal.default,
      {
        open: true,
        mode: connectModal.mode,
        currentDevice,
        editConnection: connectModal.mode === "edit" ? connectModal.connection : void 0,
        connectedDeviceIds: rows.map((row) => row.peripheralId),
        currentWorkAreaId: currentDevice.workarea_id,
        variant: currentVariant,
        getText,
        translation,
        submitting: createConnectionRequest.loading || updateConnectionRequest.loading,
        onClose: () => setConnectModal(void 0),
        onSubmit: handleCreateConnection,
        onUpdate: handleUpdateConnection
      }
    ) : null,
    editingDevice ? /* @__PURE__ */ import_react.default.createElement(
      import_EditDeviceModal.default,
      {
        open: true,
        record: editingDevice,
        variant: currentVariant,
        workAreas,
        models,
        submitting: updateDeviceRequest.loading,
        getText,
        translation,
        onCancel: () => setEditingDevice(void 0),
        onSubmit: handleUpdateDevice
      }
    ) : null,
    removingConnection ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellModal,
      {
        open: true,
        title: getText("pisell2.saas.app-peripheral.remove.title"),
        headerDivider: false,
        footerDivider: false,
        okVisible: false,
        cancelText: getText("pisell2.saas.app-peripheral.cancel"),
        cancelButtonProps: {
          block: true,
          size: "large",
          type: "default",
          disabled: dangerSubmitting,
          onClick: () => setRemovingConnection(void 0)
        },
        width: 520,
        platform: currentVariant === "phone" ? "h5" : void 0,
        mobileModalHeight: currentVariant === "phone" ? "auto" : void 0,
        className: (0, import_classnames.default)("saas-app-peripheral-remove-modal", {
          "saas-app-peripheral-remove-modal--phone": currentVariant === "phone"
        }),
        destroyOnClose: true,
        maskClosable: !dangerSubmitting,
        onCancel: () => {
          if (dangerSubmitting) return;
          setRemovingConnection(void 0);
        }
      },
      /* @__PURE__ */ import_react.default.createElement("div", { className: "saas-app-peripheral-remove-modal__desc" }, (0, import_constants.formatToken)(getText("pisell2.saas.app-peripheral.remove.choose"), {
        name: removeName
      })),
      /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: "saas-app-peripheral-remove-modal__option",
          onClick: () => setConfirmAction("remove-connection")
        },
        /* @__PURE__ */ import_react.default.createElement(import_materials.Icon, { type: "LinkOutlined" }),
        /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.connection")), /* @__PURE__ */ import_react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.connection-desc")))
      ),
      /* @__PURE__ */ import_react.default.createElement(
        "button",
        {
          type: "button",
          className: "saas-app-peripheral-remove-modal__option is-danger",
          onClick: () => setConfirmAction("delete-peripheral")
        },
        /* @__PURE__ */ import_react.default.createElement(import_icons.DeleteOutlined, null),
        /* @__PURE__ */ import_react.default.createElement("div", null, /* @__PURE__ */ import_react.default.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.delete")), /* @__PURE__ */ import_react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.delete-desc")))
      )
    ) : null,
    confirmAction && removingConnection ? /* @__PURE__ */ import_react.default.createElement(
      import_materials.PisellModal,
      {
        open: true,
        title: confirmAction === "remove-connection" ? getText("pisell2.saas.app-peripheral.remove.connection") : getText("pisell2.saas.app-peripheral.remove.delete"),
        headerDivider: false,
        okText: getText("pisell2.saas.app-peripheral.confirm"),
        cancelText: getText("pisell2.saas.app-peripheral.cancel"),
        okButtonProps: {
          block: true,
          size: "large",
          danger: true,
          loading: dangerSubmitting,
          onClick: handleConfirmDangerAction
        },
        cancelButtonProps: {
          block: true,
          size: "large",
          type: "default",
          disabled: dangerSubmitting,
          onClick: () => setConfirmAction(void 0)
        },
        width: 460,
        platform: currentVariant === "phone" ? "h5" : void 0,
        mobileModalHeight: currentVariant === "phone" ? "auto" : void 0,
        className: (0, import_classnames.default)("saas-app-peripheral-confirm-modal", {
          "saas-app-peripheral-confirm-modal--phone": currentVariant === "phone"
        }),
        destroyOnClose: true,
        maskClosable: !dangerSubmitting,
        onCancel: () => {
          if (dangerSubmitting) return;
          setConfirmAction(void 0);
        }
      },
      (0, import_constants.formatToken)(
        getText(
          confirmAction === "remove-connection" ? "pisell2.saas.app-peripheral.confirm.remove-connection" : "pisell2.saas.app-peripheral.confirm.delete"
        ),
        { name: removeName }
      )
    ) : null
  );
};
SaasAppPeripheral.displayName = "SaasAppPeripheral";
var appPeripheral_default = (0, import_responsive.withResponsive)(SaasAppPeripheral);
