const require_runtime = require("../../../_virtual/_rolldown/runtime.js");
const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
const require_toast = require("./toast.js");
const require_renderImperatively = require("./renderImperatively.js");
let react = require("react");
react = require_runtime.__toESM(react);
//#region src/components/pisellToast/squareToast/methods.tsx
let currentHandler = null;
let currentTimeout = null;
const defaultProps = {
	duration: 2e3,
	mask: false,
	icon: "info"
};
function mergeProps(a, b) {
	const filteredB = Object.keys(b).reduce((acc, key) => {
		if (b[key] !== void 0) acc[key] = b[key];
		return acc;
	}, {});
	return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, a), filteredB);
}
const show = (configOrContent, duration, afterClose) => {
	let props;
	if (typeof configOrContent === "string" || react.default.isValidElement(configOrContent)) props = mergeProps(defaultProps, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ content: configOrContent }, duration !== void 0 && { duration }), afterClose !== void 0 && { afterClose }));
	else props = mergeProps(defaultProps, configOrContent || {});
	const element = /* @__PURE__ */ react.default.createElement(require_toast.default, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { onCancel: () => {
		currentHandler = null;
	} }));
	if (currentHandler) {
		var _currentHandler$isRen;
		if ((_currentHandler$isRen = currentHandler.isRendered) === null || _currentHandler$isRen === void 0 ? void 0 : _currentHandler$isRen.call(currentHandler)) currentHandler.replace(element);
		else {
			currentHandler.close();
			currentHandler = require_renderImperatively.renderImperatively(element);
		}
	} else currentHandler = require_renderImperatively.renderImperatively(element);
	if (currentTimeout) window.clearTimeout(currentTimeout);
	if (props.duration !== 0) currentTimeout = window.setTimeout(() => {
		clear();
	}, props.duration);
	return { close: () => {
		if (currentHandler) {
			currentHandler.close();
			currentHandler = null;
		}
		if (currentTimeout) {
			window.clearTimeout(currentTimeout);
			currentTimeout = null;
		}
	} };
};
const clear = () => {
	if (currentHandler) {
		currentHandler.close();
		currentHandler = null;
	}
	if (currentTimeout) {
		window.clearTimeout(currentTimeout);
		currentTimeout = null;
	}
};
const success = (content, duration, afterClose) => {
	return show({
		content,
		icon: "success",
		duration,
		afterClose
	});
};
const info = (content, duration, afterClose) => {
	return show({
		content,
		icon: "info",
		duration,
		afterClose
	});
};
const loading = (content, duration, afterClose) => {
	return show({
		content,
		icon: "loading",
		duration,
		afterClose
	});
};
const fail = (content, duration, afterClose) => {
	return show({
		content,
		icon: "error",
		duration,
		afterClose
	});
};
const hide = () => {
	clear();
};
//#endregion
exports.clear = clear;
exports.fail = fail;
exports.hide = hide;
exports.info = info;
exports.loading = loading;
exports.show = show;
exports.success = success;
