"use client";
/*! © 2026 Yahoo, Inc. UDS v0.0.0-development */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_runtime = require('../../../_virtual/_rolldown/runtime.cjs');
const require_tokens_utils_fromEntries = require('../../../tokens/utils/fromEntries.cjs');
const require_utils_entries = require('../../../utils/entries.cjs');
const require_components_client_Toast_ToastContainer = require('./ToastContainer.cjs');
const require_components_client_Toast_Toast = require('./Toast.cjs');
let react_jsx_runtime = require("react/jsx-runtime");
let lodash_merge_js = require("lodash/merge.js");
lodash_merge_js = require_runtime.__toESM(lodash_merge_js);
let lodash_pick_js = require("lodash/pick.js");
lodash_pick_js = require_runtime.__toESM(lodash_pick_js);
let react_toastify = require("react-toastify");

//#region src/components/client/Toast/createToast.tsx
const splitCreateToastArgs = (args) => {
	return {
		options: {
			toastId: args.id,
			...createToastOptionsToToastOptions((0, lodash_pick_js.default)(args, [
				"closeOnClick",
				"pauseOnHover",
				"onClose",
				"containerId",
				"data",
				"position",
				"autoClose"
			]))
		},
		props: { ...(0, lodash_pick_js.default)(args, [
			"actionButton",
			"onClickActionButton",
			"startIcon",
			"closeIcon",
			"className"
		]) },
		data: { ...(0, lodash_pick_js.default)(args, [
			"variant",
			"message",
			"promise",
			"content"
		]) }
	};
};
const POSTION_MAP = {
	"top-start": "top-left",
	"top-center": "top-center",
	"top-end": "top-right",
	"bottom-start": "bottom-left",
	"bottom-center": "bottom-center",
	"bottom-end": "bottom-right"
};
const reverseTypeMap = require_tokens_utils_fromEntries.fromEntries(require_utils_entries.entries(require_components_client_Toast_ToastContainer.typeMap).map(([key, value]) => [value, key]));
function makeToastAPI(toastId, originalProps, originalData) {
	return {
		update(args) {
			const { data, options, props } = splitCreateToastArgs(args);
			const variant = data.variant ?? originalData.variant;
			if (variant === "custom") {
				const content = data.content ?? originalData.content;
				return react_toastify.toast.update(toastId, {
					...options,
					render: content
				});
			}
			const message = data.message ?? originalData.message;
			react_toastify.toast.update(toastId, {
				...options,
				type: reverseTypeMap[variant],
				render: ({ closeToast, toastProps: { toastId } }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Toast_Toast.Toast, {
					...(0, lodash_merge_js.default)({}, originalProps, props),
					variant,
					message,
					closeToast,
					id: String(toastId)
				})
			});
		},
		close() {
			react_toastify.toast.dismiss(toastId);
		}
	};
}
const createToastOptionsToToastOptions = (toastOptions) => {
	if (!toastOptions) return {};
	const { position, ...rest } = toastOptions;
	return {
		...rest,
		position: position ? POSTION_MAP[position] : void 0
	};
};
function createToast(args) {
	const { data, options, props } = splitCreateToastArgs(args);
	const { variant } = data;
	if (variant === "loading") return makeToastAPI(createLoadingToast(data.message, data.promise, props, options), props, data);
	if (variant === "custom") return makeToastAPI((0, react_toastify.toast)(data.content, options), props, data);
	return makeToastAPI((0, react_toastify.toast)(({ closeToast, toastProps: { toastId } }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Toast_Toast.Toast, {
		...props,
		variant,
		message: data.message,
		closeToast,
		id: String(toastId)
	}), {
		...options,
		type: reverseTypeMap[variant]
	}), props, data);
}
const createLoadingToast = (message, promise, props, options) => {
	const variant = "loading";
	const id = react_toastify.toast.loading(({ closeToast, toastProps: { toastId } }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Toast_Toast.Toast, {
		...props,
		variant,
		message,
		closeToast,
		id: String(toastId)
	}), {
		...options,
		type: reverseTypeMap[variant]
	});
	let finalVariant;
	let finalMessage;
	promise.then(({ result, message }) => {
		finalVariant = result === "success" ? "success" : "error";
		finalMessage = message;
	}).catch(() => {
		finalVariant = "error";
		finalMessage = "Unknown error occurred";
	}).finally(() => {
		react_toastify.toast.update(id, {
			...options,
			type: reverseTypeMap[finalVariant],
			render: ({ closeToast, toastProps: { toastId } }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_components_client_Toast_Toast.Toast, {
				...props,
				variant: finalVariant,
				message: finalMessage,
				closeToast,
				id: String(toastId)
			})
		});
	});
	return id;
};

//#endregion
exports.POSTION_MAP = POSTION_MAP;
exports.createToast = createToast;