const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
const require_useEngineContext = require("../../../hooks/useEngineContext.js");
const require_withResponsive = require("../../../responsive/withResponsive.js");
const require_index = require("../../../utils/index.js");
const require_useLocale = require("../../../hooks/useLocale.js");
const require_serve = require("./serve.js");
const require_hooks = require("./hooks.js");
const require_peripheralRuntime = require("./utils/peripheralRuntime.js");
const require_peripheralConnectionService = require("./services/peripheralConnectionService.js");
const require_locales = require("./locales.js");
const require_constants = require("./constants.js");
const require_utils = require("./utils.js");
const require_ConnectExistingDeviceModal = require("./components/ConnectExistingDeviceModal.js");
const require_EditDeviceModal = require("./components/EditDeviceModal.js");
const require_PeripheralConnectionCardContainer = require("./components/PeripheralConnectionCardContainer.js");
let react = require("react");
react = require_runtime.__toESM(react);
let antd = require("antd");
let _pisell_utils = require("@pisell/utils");
let _pisell_materials = require("@pisell/materials");
let classnames = require("classnames");
classnames = require_runtime.__toESM(classnames);
let ahooks = require("ahooks");
let _ant_design_icons = require("@ant-design/icons");
require("./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 = require_asyncToGenerator._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 || require_peripheralRuntime.getPeripheralUuid(row.connection) === uuid;
	});
};
const SaasAppPeripheral = ({ className, style, showBack = false, onBack, onManageProfiles, onTest, variant }) => {
	var _context$appHelper;
	const context = require_useEngineContext.default();
	const locale = require_useLocale.default();
	const currentVariant = variant || "desktop";
	_pisell_utils.locales.init(require_locales.default, locale || "en");
	const getText = _pisell_utils.locales.getText;
	const translation = require_hooks.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] = (0, react.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] = (0, react.useState)();
	const [editingDevice, setEditingDevice] = (0, react.useState)();
	const [removingConnection, setRemovingConnection] = (0, react.useState)();
	const [confirmAction, setConfirmAction] = (0, react.useState)();
	const [initializing, setInitializing] = (0, react.useState)(false);
	/** 页面唯一渲染列表：云端 connection/peripheral + 本地 physical/usage。 */
	const [rows, setRows] = (0, react.useState)([]);
	const localBindingMapRef = (0, react.useRef)({});
	const rowsRef = (0, react.useRef)([]);
	(0, react.useEffect)(() => {
		if (utils === null || utils === void 0 ? void 0 : utils.request) require_index.request.setRequest(utils.request);
	}, [utils === null || utils === void 0 ? void 0 : utils.request]);
	(0, react.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 = (0, ahooks.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);
	});
	(0, react.useEffect)(() => {
		rowsRef.current = rows;
	}, [rows]);
	const currentDeviceRequest = (0, ahooks.useRequest)(require_serve.getDeviceDetail, { manual: true });
	const connectionRequest = (0, ahooks.useRequest)(require_serve.getDeviceConnections, { manual: true });
	const workAreaRequest = (0, ahooks.useRequest)(require_serve.getWorkAreas, { manual: true });
	const typeRequest = (0, ahooks.useRequest)(() => require_serve.getDeviceTypes({
		kind: "dumb",
		with: [
			"activeModels",
			"activeModels.activeProfiles",
			"activeModels.brand"
		]
	}), { manual: true });
	const createConnectionRequest = (0, ahooks.useRequest)(require_serve.createDeviceConnection, { manual: true });
	const updateConnectionRequest = (0, ahooks.useRequest)((params) => require_serve.updateDeviceConnection(params.id, params.payload), { manual: true });
	const updateDeviceRequest = (0, ahooks.useRequest)((params) => require_serve.updateDevice(params.id, params.payload), { manual: true });
	const deleteConnectionRequest = (0, ahooks.useRequest)(require_serve.deleteDeviceConnection, { manual: true });
	const deleteDeviceRequest = (0, ahooks.useRequest)(require_serve.deleteDevice, { manual: true });
	const currentDevice = currentDeviceRequest.data || void 0;
	const workAreas = (0, react.useMemo)(() => workAreaRequest.data || [], [workAreaRequest.data]);
	const models = (0, react.useMemo)(() => require_utils.flattenDeviceModels(typeRequest.data || []), [typeRequest.data]);
	const loading = initializing || currentDeviceRequest.loading || connectionRequest.loading || workAreaRequest.loading;
	const hydrateLocalBindings = (0, ahooks.useMemoizedFn)(function() {
		var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (nextConnections) {
			const sourceDeviceId = storedIotDevice.id;
			if (!sourceDeviceId) return localBindingMapRef.current;
			localBindingMapRef.current = yield hydrateLocalBindingMapOnce(sourceDeviceId, require_asyncToGenerator._asyncToGenerator(function* () {
				return createLocalBindingMap(yield require_peripheralConnectionService.syncLocalPeripheralBindings({
					app: getAppInstance(),
					connections: nextConnections
				}));
			}));
			return localBindingMapRef.current;
		});
		return function(_x3) {
			return _ref2.apply(this, arguments);
		};
	}());
	const patchLocalBindingMap = (0, ahooks.useMemoizedFn)((row, physical, usage) => {
		const binding = require_peripheralRuntime.createLocalPeripheralBinding(row.connection, physical, usage);
		localBindingMapRef.current = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, localBindingMapRef.current), {}, { [row.id]: binding });
		updateLocalBindingMapCache(row.connection.source_device_id, localBindingMapRef.current);
	});
	const loadConnections = (0, ahooks.useMemoizedFn)(require_asyncToGenerator._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) => require_peripheralRuntime.mergeConnectionRows(prevRows, nextConnections || [], localBindingMap));
		return nextConnections;
	}));
	const reloadConnectionsImmediately = (0, ahooks.useMemoizedFn)(() => {
		loadConnections();
	});
	const patchRowPhysical = (0, ahooks.useMemoizedFn)((rowId, physical) => {
		setRows((prevRows) => prevRows.map((row) => {
			if (row.id !== rowId) return row;
			patchLocalBindingMap(row, physical, row.usage);
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, row), {}, { physical });
		}));
	});
	const patchRowUsage = (0, ahooks.useMemoizedFn)((rowId, usage) => {
		setRows((prevRows) => prevRows.map((row) => {
			if (row.id !== rowId) return row;
			patchLocalBindingMap(row, row.physical, usage);
			return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, row), {}, { usage });
		}));
	});
	const applySyncedBinding = (0, ahooks.useMemoizedFn)((row, physical, binding) => {
		localBindingMapRef.current = require_objectSpread2._objectSpread2(require_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 ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, prevRow), {}, {
				physical,
				usage: binding.peripheral_usage
			}) : prevRow);
			rowsRef.current = nextRows;
			return nextRows;
		});
	});
	const handlePeripheralStatusChange = (0, ahooks.useMemoizedFn)(function() {
		var _ref3 = require_asyncToGenerator._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 require_peripheralConnectionService.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);
		};
	}());
	(0, react.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
	]);
	(0, ahooks.useMount)(() => {
		if (!storedIotDevice.id) return;
		if (utils === null || utils === void 0 ? void 0 : utils.request) require_index.request.setRequest(utils.request);
		(function() {
			var _ref4 = require_asyncToGenerator._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) => require_utils.createDeviceRow(device, translation);
	const handleCreateConnection = function() {
		var _ref5 = require_asyncToGenerator._asyncToGenerator(function* (payload) {
			try {
				yield createConnectionRequest.runAsync(payload);
				(0, _pisell_materials.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 = require_asyncToGenerator._asyncToGenerator(function* (id, payload) {
			try {
				yield updateConnectionRequest.runAsync({
					id,
					payload
				});
				(0, _pisell_materials.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 = require_asyncToGenerator._asyncToGenerator(function* (id, payload) {
			try {
				yield updateDeviceRequest.runAsync({
					id,
					payload
				});
				(0, _pisell_materials.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 = require_asyncToGenerator._asyncToGenerator(function* () {
			if (!removingConnection || !confirmAction) return;
			try {
				if (confirmAction === "remove-connection") {
					yield deleteConnectionRequest.runAsync(removingConnection.id);
					(0, _pisell_materials.PisellToast)({
						content: getText("pisell2.saas.app-peripheral.remove-success"),
						duration: 2
					});
				} else {
					const peripheral = getPeripheral(removingConnection);
					if (!peripheral) return;
					yield deleteDeviceRequest.runAsync(peripheral.id);
					(0, _pisell_materials.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.default.createElement(_ant_design_icons.LinkOutlined, null),
		label: getText("pisell2.saas.app-peripheral.add-existing"),
		onClick: () => setConnectModal({ mode: "existing" })
	}, {
		key: "new",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_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__ */ react.default.createElement("div", {
		className: (0, classnames.default)("saas-app-peripheral", `saas-app-peripheral--${currentVariant}`, className),
		style
	}, /* @__PURE__ */ react.default.createElement("header", { className: "saas-app-peripheral__header" }, /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__header-main" }, showBack ? /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "text",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.ArrowLeftOutlined, null),
		className: "saas-app-peripheral__back",
		onClick: onBack
	}) : null, /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__title" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "ApiOutlined" }), /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.title"))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__subtitle" }, getText("pisell2.saas.app-peripheral.subtitle")))), /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__header-actions" }, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, { onClick: onManageProfiles }, getText("pisell2.saas.app-peripheral.manage-profiles")), /* @__PURE__ */ react.default.createElement(antd.Dropdown, {
		menu: { items: addMenuItems },
		trigger: ["click"],
		placement: "bottomRight",
		disabled: !currentDevice
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Button, {
		type: "primary",
		icon: /* @__PURE__ */ react.default.createElement(_ant_design_icons.PlusOutlined, null),
		disabled: !currentDevice
	}, getText("pisell2.saas.app-peripheral.add"))))), /* @__PURE__ */ react.default.createElement(antd.Spin, {
		spinning: loading,
		wrapperClassName: "saas-app-peripheral__spin"
	}, !storedIotDevice.id ? /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ react.default.createElement(antd.Empty, {
		image: antd.Empty.PRESENTED_IMAGE_SIMPLE,
		description: getText("pisell2.saas.app-peripheral.no-current-device")
	})) : rows.length ? /* @__PURE__ */ react.default.createElement("div", { className: "saas-app-peripheral__list" }, rows.map((row) => /* @__PURE__ */ react.default.createElement(require_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__ */ react.default.createElement("div", { className: "saas-app-peripheral__empty" }, /* @__PURE__ */ react.default.createElement(antd.Empty, {
		image: antd.Empty.PRESENTED_IMAGE_SIMPLE,
		description: getText("pisell2.saas.app-peripheral.no-peripherals")
	}))), connectModal && currentDevice ? /* @__PURE__ */ react.default.createElement(require_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__ */ react.default.createElement(require_EditDeviceModal.default, {
		open: true,
		record: editingDevice,
		variant: currentVariant,
		workAreas,
		models,
		submitting: updateDeviceRequest.loading,
		getText,
		translation,
		onCancel: () => setEditingDevice(void 0),
		onSubmit: handleUpdateDevice
	}) : null, removingConnection ? /* @__PURE__ */ react.default.createElement(_pisell_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, 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__ */ react.default.createElement("div", { className: "saas-app-peripheral-remove-modal__desc" }, require_constants.formatToken(getText("pisell2.saas.app-peripheral.remove.choose"), { name: removeName })), /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		className: "saas-app-peripheral-remove-modal__option",
		onClick: () => setConfirmAction("remove-connection")
	}, /* @__PURE__ */ react.default.createElement(_pisell_materials.Icon, { type: "LinkOutlined" }), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.connection")), /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.connection-desc")))), /* @__PURE__ */ react.default.createElement("button", {
		type: "button",
		className: "saas-app-peripheral-remove-modal__option is-danger",
		onClick: () => setConfirmAction("delete-peripheral")
	}, /* @__PURE__ */ react.default.createElement(_ant_design_icons.DeleteOutlined, null), /* @__PURE__ */ react.default.createElement("div", null, /* @__PURE__ */ react.default.createElement("strong", null, getText("pisell2.saas.app-peripheral.remove.delete")), /* @__PURE__ */ react.default.createElement("span", null, getText("pisell2.saas.app-peripheral.remove.delete-desc"))))) : null, confirmAction && removingConnection ? /* @__PURE__ */ react.default.createElement(_pisell_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, 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);
		}
	}, require_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 = require_withResponsive.default(SaasAppPeripheral);
//#endregion
exports.default = appPeripheral_default;
