import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js";
import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
import useEngineContext from "../../../hooks/useEngineContext.js";
import withResponsive from "../../../responsive/withResponsive.js";
import { request } from "../../../utils/index.js";
import useLocale from "../../../hooks/useLocale.js";
import { createDeviceConnection, deleteDevice, deleteDeviceConnection, getDeviceConnections, getDeviceDetail, getDeviceTypes, getWorkAreas, updateDevice, updateDeviceConnection } from "./serve.js";
import { useTranslation } from "./hooks.js";
import { createLocalPeripheralBinding, getPeripheralUuid, mergeConnectionRows } from "./utils/peripheralRuntime.js";
import { syncLocalPeripheralBindings, syncPeripheralConnectionStatus } from "./services/peripheralConnectionService.js";
import locales_default from "./locales.js";
import { formatToken } from "./constants.js";
import { createDeviceRow, flattenDeviceModels } from "./utils.js";
import ConnectExistingDeviceModal from "./components/ConnectExistingDeviceModal.js";
import EditDeviceModal from "./components/EditDeviceModal.js";
import PeripheralConnectionCardContainer from "./components/PeripheralConnectionCardContainer.js";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { Dropdown, Empty, Spin } from "antd";
import { locales } from "@pisell/utils";
import { Button as Button$1, Icon, PisellModal, PisellToast } from "@pisell/materials";
import classNames from "classnames";
import { useMemoizedFn, useMount, useRequest } from "ahooks";
import { ArrowLeftOutlined, DeleteOutlined, LinkOutlined, PlusOutlined } from "@ant-design/icons";
import "./index.less";
//#region src/plus/saasDevice/appPeripheral/index.tsx
const PERIPHERAL_STATUS_CHANGE_CHANNEL = "peripheral.statusChange";
const localBindingHydrationCache = /* @__PURE__ */ new Map();
const getStoredIotDevice = (app) => {
	try {
		var _app$storage;
		const iotDevice = JSON.parse((app === null || app === void 0 || (_app$storage = app.storage) === null || _app$storage === void 0 ? void 0 : _app$storage.getStorage("iotDevice")) || "{}");
		return { id: (iotDevice === null || iotDevice === void 0 ? void 0 : iotDevice.id) !== void 0 && (iotDevice === null || iotDevice === void 0 ? void 0 : iotDevice.id) !== null ? Number(iotDevice.id) : void 0 };
	} catch (e) {
		return {};
	}
};
const getConnectionListParams = (sourceDeviceId) => ({
	type: "dumb",
	source_device_id: sourceDeviceId,
	with: [
		"targetDevice.type",
		"targetDevice.model.brand",
		"targetDevice.workarea",
		"profiles"
	]
});
/** 将 SQLite 本地记录按 connection_id 建索引，用于初始化 row 的 usage/physical。 */
const createLocalBindingMap = (bindings) => bindings.reduce((result, binding) => {
	result[Number(binding.connection_id)] = binding;
	return result;
}, {});
const hydrateLocalBindingMapOnce = function() {
	var _ref = _asyncToGenerator(function* (sourceDeviceId, loadBindings) {
		const cached = localBindingHydrationCache.get(sourceDeviceId);
		if (cached === null || cached === void 0 ? void 0 : cached.hydrated) return cached.bindingMap;
		if (cached === null || cached === void 0 ? 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 || cached === void 0 ? void 0 : cached.bindingMap) || {},
			promise
		});
		return promise;
	});
	return function hydrateLocalBindingMapOnce(_x, _x2) {
		return _ref.apply(this, arguments);
	};
}();
const updateLocalBindingMapCache = (sourceDeviceId, bindingMap) => {
	localBindingHydrationCache.set(sourceDeviceId, {
		hydrated: true,
		bindingMap
	});
};
const unsubscribePubsub = (pubsub, subscription, handler) => {
	var _pubsub$unsubscribe;
	if (typeof subscription === "function") {
		subscription();
		return;
	}
	if (typeof (subscription === null || subscription === void 0 ? void 0 : subscription.unsubscribe) === "function") {
		subscription.unsubscribe();
		return;
	}
	pubsub === null || pubsub === void 0 || (_pubsub$unsubscribe = pubsub.unsubscribe) === null || _pubsub$unsubscribe === void 0 || _pubsub$unsubscribe.call(pubsub, PERIPHERAL_STATUS_CHANGE_CHANNEL, handler);
};
const findStatusChangeRow = (rows, payload, physicalDevice) => {
	var _payload$binding, _payload$binding2, _payload$binding3;
	const connectionId = (_payload$binding = payload.binding) === null || _payload$binding === void 0 ? void 0 : _payload$binding.connection_id;
	if (connectionId) return rows.find((row) => row.id === Number(connectionId));
	const uuid = (physicalDevice === null || physicalDevice === void 0 ? void 0 : physicalDevice.uuid) || ((_payload$binding2 = payload.binding) === null || _payload$binding2 === void 0 ? void 0 : _payload$binding2.physical_uuid) || ((_payload$binding3 = payload.binding) === null || _payload$binding3 === void 0 || (_payload$binding3 = _payload$binding3.physical_device) === null || _payload$binding3 === void 0 ? void 0 : _payload$binding3.uuid);
	if (!uuid) return void 0;
	return rows.find((row) => {
		var _row$physical;
		return ((_row$physical = row.physical) === null || _row$physical === void 0 ? void 0 : _row$physical.uuid) === uuid || getPeripheralUuid(row.connection) === uuid;
	});
};
const SaasAppPeripheral = ({ className, style, showBack = false, onBack, onManageProfiles, onTest, variant }) => {
	var _context$appHelper;
	const context = useEngineContext();
	const locale = useLocale();
	const currentVariant = variant || "desktop";
	locales.init(locales_default, locale || "en");
	const getText = locales.getText;
	const translation = useTranslation();
	const utils = (context === null || context === void 0 || (_context$appHelper = context.appHelper) === null || _context$appHelper === void 0 ? void 0 : _context$appHelper.utils) || {};
	const [storedIotDevice, setStoredIotDevice] = useState(() => {
		var _utils$getApp;
		return getStoredIotDevice(utils === null || utils === void 0 || (_utils$getApp = utils.getApp) === null || _utils$getApp === void 0 ? void 0 : _utils$getApp.call(utils));
	});
	const [connectModal, setConnectModal] = useState();
	const [editingDevice, setEditingDevice] = useState();
	const [removingConnection, setRemovingConnection] = useState();
	const [confirmAction, setConfirmAction] = useState();
	const [initializing, setInitializing] = useState(false);
	/** 页面唯一渲染列表：云端 connection/peripheral + 本地 physical/usage。 */
	const [rows, setRows] = useState([]);
	const localBindingMapRef = useRef({});
	const rowsRef = useRef([]);
	useEffect(() => {
		if (utils === null || utils === void 0 ? void 0 : utils.request) request.setRequest(utils.request);
	}, [utils === null || utils === void 0 ? void 0 : utils.request]);
	useEffect(() => {
		var _utils$getApp2;
		const nextDevice = getStoredIotDevice(utils === null || utils === void 0 || (_utils$getApp2 = utils.getApp) === null || _utils$getApp2 === void 0 ? void 0 : _utils$getApp2.call(utils));
		setStoredIotDevice((prev) => prev.id === nextDevice.id ? prev : nextDevice);
	}, [utils === null || utils === void 0 ? void 0 : utils.getApp]);
	const getAppInstance = useMemoizedFn(() => {
		var _utils$getApp3;
		return utils === null || utils === void 0 || (_utils$getApp3 = utils.getApp) === null || _utils$getApp3 === void 0 ? void 0 : _utils$getApp3.call(utils);
	});
	useEffect(() => {
		rowsRef.current = rows;
	}, [rows]);
	const currentDeviceRequest = useRequest(getDeviceDetail, { manual: true });
	const connectionRequest = useRequest(getDeviceConnections, { manual: true });
	const workAreaRequest = useRequest(getWorkAreas, { manual: true });
	const typeRequest = useRequest(() => getDeviceTypes({
		kind: "dumb",
		with: [
			"activeModels",
			"activeModels.activeProfiles",
			"activeModels.brand"
		]
	}), { manual: true });
	const createConnectionRequest = useRequest(createDeviceConnection, { manual: true });
	const updateConnectionRequest = useRequest((params) => updateDeviceConnection(params.id, params.payload), { manual: true });
	const updateDeviceRequest = useRequest((params) => updateDevice(params.id, params.payload), { manual: true });
	const deleteConnectionRequest = useRequest(deleteDeviceConnection, { manual: true });
	const deleteDeviceRequest = useRequest(deleteDevice, { manual: true });
	const currentDevice = currentDeviceRequest.data || void 0;
	const workAreas = useMemo(() => workAreaRequest.data || [], [workAreaRequest.data]);
	const models = useMemo(() => flattenDeviceModels(typeRequest.data || []), [typeRequest.data]);
	const loading = initializing || currentDeviceRequest.loading || connectionRequest.loading || workAreaRequest.loading;
	const hydrateLocalBindings = useMemoizedFn(function() {
		var _ref2 = _asyncToGenerator(function* (nextConnections) {
			const sourceDeviceId = storedIotDevice.id;
			if (!sourceDeviceId) return localBindingMapRef.current;
			localBindingMapRef.current = yield hydrateLocalBindingMapOnce(sourceDeviceId, _asyncToGenerator(function* () {
				return createLocalBindingMap(yield syncLocalPeripheralBindings({
					app: getAppInstance(),
					connections: nextConnections
				}));
			}));
			return localBindingMapRef.current;
		});
		return function(_x3) {
			return _ref2.apply(this, arguments);
		};
	}());
	const patchLocalBindingMap = useMemoizedFn((row, physical, usage) => {
		const binding = createLocalPeripheralBinding(row.connection, physical, usage);
		localBindingMapRef.current = _objectSpread2(_objectSpread2({}, localBindingMapRef.current), {}, { [row.id]: binding });
		updateLocalBindingMapCache(row.connection.source_device_id, localBindingMapRef.current);
	});
	const loadConnections = useMemoizedFn(_asyncToGenerator(function* (options = {}) {
		if (!storedIotDevice.id) return;
		const nextConnections = yield connectionRequest.runAsync(getConnectionListParams(storedIotDevice.id));
		const localBindingMap = options.hydrateLocal ? yield hydrateLocalBindings(nextConnections || []) : localBindingMapRef.current;
		setRows((prevRows) => mergeConnectionRows(prevRows, nextConnections || [], localBindingMap));
		return nextConnections;
	}));
	const reloadConnectionsImmediately = useMemoizedFn(() => {
		loadConnections();
	});
	const patchRowPhysical = useMemoizedFn((rowId, physical) => {
		setRows((prevRows) => prevRows.map((row) => {
			if (row.id !== rowId) return row;
			patchLocalBindingMap(row, physical, row.usage);
			return _objectSpread2(_objectSpread2({}, row), {}, { physical });
		}));
	});
	const patchRowUsage = useMemoizedFn((rowId, usage) => {
		setRows((prevRows) => prevRows.map((row) => {
			if (row.id !== rowId) return row;
			patchLocalBindingMap(row, row.physical, usage);
			return _objectSpread2(_objectSpread2({}, row), {}, { usage });
		}));
	});
	const applySyncedBinding = useMemoizedFn((row, physical, binding) => {
		localBindingMapRef.current = _objectSpread2(_objectSpread2({}, localBindingMapRef.current), {}, { [row.id]: binding });
		updateLocalBindingMapCache(row.connection.source_device_id, localBindingMapRef.current);
		setRows((prevRows) => {
			const nextRows = prevRows.map((prevRow) => prevRow.id === row.id ? _objectSpread2(_objectSpread2({}, prevRow), {}, {
				physical,
				usage: binding.peripheral_usage
			}) : prevRow);
			rowsRef.current = nextRows;
			return nextRows;
		});
	});
	const handlePeripheralStatusChange = useMemoizedFn(function() {
		var _ref3 = _asyncToGenerator(function* (payload) {
			var _payload$event;
			const physicalDevice = (payload === null || payload === void 0 ? void 0 : payload.data) || (payload === null || payload === void 0 || (_payload$event = payload.event) === null || _payload$event === void 0 ? void 0 : _payload$event.data);
			if (!(physicalDevice === null || physicalDevice === void 0 ? void 0 : physicalDevice.uuid)) return;
			const row = findStatusChangeRow(rowsRef.current, payload, physicalDevice);
			if (!row) return;
			try {
				var _payload$binding$peri, _payload$binding4;
				const result = yield syncPeripheralConnectionStatus({
					app: getAppInstance(),
					connection: row.connection,
					physicalDevice,
					peripheralUsage: (_payload$binding$peri = (_payload$binding4 = payload.binding) === null || _payload$binding4 === void 0 ? void 0 : _payload$binding4.peripheral_usage) !== null && _payload$binding$peri !== void 0 ? _payload$binding$peri : row.usage
				});
				applySyncedBinding(row, result.physicalDevice, result.binding);
			} catch (e) {}
		});
		return function(_x4) {
			return _ref3.apply(this, arguments);
		};
	}());
	useEffect(() => {
		var _getAppInstance;
		const pubsub = ((_getAppInstance = getAppInstance()) === null || _getAppInstance === void 0 ? void 0 : _getAppInstance.pubsub) || (utils === null || utils === void 0 ? void 0 : utils.pubsub);
		if (!(pubsub === null || pubsub === void 0 ? void 0 : pubsub.subscribe)) return void 0;
		const handler = (payload) => {
			handlePeripheralStatusChange(payload);
		};
		const subscription = pubsub.subscribe(PERIPHERAL_STATUS_CHANGE_CHANNEL, handler);
		return () => {
			unsubscribePubsub(pubsub, subscription, handler);
		};
	}, [
		handlePeripheralStatusChange,
		getAppInstance,
		utils === null || utils === void 0 ? void 0 : utils.getApp,
		utils === null || utils === void 0 ? void 0 : utils.pubsub
	]);
	useMount(() => {
		if (!storedIotDevice.id) return;
		if (utils === null || utils === void 0 ? void 0 : utils.request) request.setRequest(utils.request);
		(function() {
			var _ref4 = _asyncToGenerator(function* () {
				setInitializing(true);
				try {
					yield Promise.all([
						currentDeviceRequest.runAsync(storedIotDevice.id),
						workAreaRequest.runAsync(),
						typeRequest.runAsync(),
						loadConnections({ hydrateLocal: true })
					]);
				} finally {
					setInitializing(false);
				}
			});
			return function runInitialLoad() {
				return _ref4.apply(this, arguments);
			};
		})()();
	});
	const getPeripheral = (connection) => (connection === null || connection === void 0 ? 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) => createDeviceRow(device, translation);
	const handleCreateConnection = function() {
		var _ref5 = _asyncToGenerator(function* (payload) {
			try {
				yield createConnectionRequest.runAsync(payload);
				PisellToast({
					content: getText("pisell2.saas.app-peripheral.connect-success"),
					duration: 2
				});
				setConnectModal(void 0);
				reloadConnectionsImmediately();
			} catch (e) {}
		});
		return function handleCreateConnection(_x5) {
			return _ref5.apply(this, arguments);
		};
	}();
	const handleUpdateConnection = function() {
		var _ref6 = _asyncToGenerator(function* (id, payload) {
			try {
				yield updateConnectionRequest.runAsync({
					id,
					payload
				});
				PisellToast({
					content: getText("pisell2.saas.app-peripheral.connect-success"),
					duration: 2
				});
				setConnectModal(void 0);
				reloadConnectionsImmediately();
			} catch (e) {}
		});
		return function handleUpdateConnection(_x6, _x7) {
			return _ref6.apply(this, arguments);
		};
	}();
	const handleUpdateDevice = function() {
		var _ref7 = _asyncToGenerator(function* (id, payload) {
			try {
				yield updateDeviceRequest.runAsync({
					id,
					payload
				});
				PisellToast({
					content: getText("pisell2.saas.app-peripheral.save-success"),
					duration: 2
				});
				setEditingDevice(void 0);
				reloadConnectionsImmediately();
			} catch (e) {}
		});
		return function handleUpdateDevice(_x8, _x9) {
			return _ref7.apply(this, arguments);
		};
	}();
	const handleConfirmDangerAction = function() {
		var _ref8 = _asyncToGenerator(function* () {
			if (!removingConnection || !confirmAction) return;
			try {
				if (confirmAction === "remove-connection") {
					yield deleteConnectionRequest.runAsync(removingConnection.id);
					PisellToast({
						content: getText("pisell2.saas.app-peripheral.remove-success"),
						duration: 2
					});
				} else {
					const peripheral = getPeripheral(removingConnection);
					if (!peripheral) return;
					yield deleteDeviceRequest.runAsync(peripheral.id);
					PisellToast({
						content: getText("pisell2.saas.app-peripheral.delete-success"),
						duration: 2
					});
				}
				setConfirmAction(void 0);
				setRemovingConnection(void 0);
				reloadConnectionsImmediately();
			} catch (e) {}
		});
		return function handleConfirmDangerAction() {
			return _ref8.apply(this, arguments);
		};
	}();
	const addMenuItems = [{
		key: "existing",
		icon: /* @__PURE__ */ React.createElement(LinkOutlined, null),
		label: getText("pisell2.saas.app-peripheral.add-existing"),
		onClick: () => setConnectModal({ mode: "existing" })
	}, {
		key: "new",
		icon: /* @__PURE__ */ React.createElement(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__ */ React.createElement("div", {
		className: classNames("saas-app-peripheral", `saas-app-peripheral--${currentVariant}`, className),
		style
	}, /* @__PURE__ */ React.createElement("header", { className: "saas-app-peripheral__header" }, /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__header-main" }, showBack ? /* @__PURE__ */ React.createElement(Button$1, {
		type: "text",
		icon: /* @__PURE__ */ React.createElement(ArrowLeftOutlined, null),
		className: "saas-app-peripheral__back",
		onClick: onBack
	}) : null, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__title" }, /* @__PURE__ */ React.createElement(Icon, { type: "ApiOutlined" }), /* @__PURE__ */ React.createElement("span", null, getText("pisell2.saas.app-peripheral.title"))), /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__subtitle" }, getText("pisell2.saas.app-peripheral.subtitle")))), /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__header-actions" }, /* @__PURE__ */ React.createElement(Button$1, { onClick: onManageProfiles }, getText("pisell2.saas.app-peripheral.manage-profiles")), /* @__PURE__ */ React.createElement(Dropdown, {
		menu: { items: addMenuItems },
		trigger: ["click"],
		placement: "bottomRight",
		disabled: !currentDevice
	}, /* @__PURE__ */ React.createElement(Button$1, {
		type: "primary",
		icon: /* @__PURE__ */ React.createElement(PlusOutlined, null),
		disabled: !currentDevice
	}, getText("pisell2.saas.app-peripheral.add"))))), /* @__PURE__ */ React.createElement(Spin, {
		spinning: loading,
		wrapperClassName: "saas-app-peripheral__spin"
	}, !storedIotDevice.id ? /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ React.createElement(Empty, {
		image: Empty.PRESENTED_IMAGE_SIMPLE,
		description: getText("pisell2.saas.app-peripheral.no-current-device")
	})) : rows.length ? /* @__PURE__ */ React.createElement("div", { className: "saas-app-peripheral__list" }, rows.map((row) => /* @__PURE__ */ React.createElement(PeripheralConnectionCardContainer, {
		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__ */ React.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ React.createElement(Empty, {
		image: Empty.PRESENTED_IMAGE_SIMPLE,
		description: getText("pisell2.saas.app-peripheral.no-peripherals")
	}))), connectModal && currentDevice ? /* @__PURE__ */ React.createElement(ConnectExistingDeviceModal, {
		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__ */ React.createElement(EditDeviceModal, {
		open: true,
		record: editingDevice,
		variant: currentVariant,
		workAreas,
		models,
		submitting: updateDeviceRequest.loading,
		getText,
		translation,
		onCancel: () => setEditingDevice(void 0),
		onSubmit: handleUpdateDevice
	}) : null, removingConnection ? /* @__PURE__ */ React.createElement(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: classNames("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__ */ React.createElement("div", { className: "saas-app-peripheral-remove-modal__desc" }, formatToken(getText("pisell2.saas.app-peripheral.remove.choose"), { name: removeName })), /* @__PURE__ */ React.createElement("button", {
		type: "button",
		className: "saas-app-peripheral-remove-modal__option",
		onClick: () => setConfirmAction("remove-connection")
	}, /* @__PURE__ */ React.createElement(Icon, { type: "LinkOutlined" }), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.connection")), /* @__PURE__ */ React.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.connection-desc")))), /* @__PURE__ */ React.createElement("button", {
		type: "button",
		className: "saas-app-peripheral-remove-modal__option is-danger",
		onClick: () => setConfirmAction("delete-peripheral")
	}, /* @__PURE__ */ React.createElement(DeleteOutlined, null), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.delete")), /* @__PURE__ */ React.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.delete-desc"))))) : null, confirmAction && removingConnection ? /* @__PURE__ */ React.createElement(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: classNames("saas-app-peripheral-confirm-modal", { "saas-app-peripheral-confirm-modal--phone": currentVariant === "phone" }),
		destroyOnClose: true,
		maskClosable: !dangerSubmitting,
		onCancel: () => {
			if (dangerSubmitting) return;
			setConfirmAction(void 0);
		}
	}, 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 = withResponsive(SaasAppPeripheral);
//#endregion
export { appPeripheral_default as default };
