
//#region src/index.ts
const plugin = { folderActions: [{
	label: "Send All",
	icon: "send_horizontal",
	async onSelect(ctx, args) {
		const targetFolder = args.folder;
		const [allFolders, allRequests] = await Promise.all([ctx.folder.list(), ctx.httpRequest.list()]);
		const compareByOrder = (a, b) => {
			if (a.sortPriority === b.sortPriority) return a.updatedAt > b.updatedAt ? 1 : -1;
			return a.sortPriority - b.sortPriority;
		};
		const childrenByFolderId = /* @__PURE__ */ new Map();
		for (const folder of allFolders) {
			if (folder.folderId == null) continue;
			const children = childrenByFolderId.get(folder.folderId) ?? [];
			children.push(folder);
			childrenByFolderId.set(folder.folderId, children);
		}
		for (const request of allRequests) {
			if (request.folderId == null) continue;
			const children = childrenByFolderId.get(request.folderId) ?? [];
			children.push(request);
			childrenByFolderId.set(request.folderId, children);
		}
		const requestsToSend = [];
		const collectRequests = (folderId) => {
			const children = (childrenByFolderId.get(folderId) ?? []).slice().sort(compareByOrder);
			for (const child of children) if (child.model === "folder") collectRequests(child.id);
			else if (child.model === "http_request") requestsToSend.push(child);
		};
		collectRequests(targetFolder.id);
		if (requestsToSend.length === 0) {
			await ctx.toast.show({
				message: "No requests in folder",
				icon: "info",
				color: "info"
			});
			return;
		}
		let successCount = 0;
		let errorCount = 0;
		for (const request of requestsToSend) try {
			await ctx.httpRequest.send({ httpRequest: request });
			successCount++;
		} catch (error) {
			errorCount++;
			console.error(`Failed to send request ${request.id}:`, error);
		}
		if (errorCount === 0) await ctx.toast.show({
			message: `Sent ${successCount} request${successCount !== 1 ? "s" : ""}`,
			icon: "send_horizontal",
			color: "success"
		});
		else await ctx.toast.show({
			message: `Sent ${successCount}, failed ${errorCount}`,
			icon: "alert_triangle",
			color: "warning"
		});
	}
}] };

//#endregion
exports.plugin = plugin;