jingrow.listview_settings["Deleted Page"] = {
	onload: function (doclist) {
		const action = () => {
			const selected_pgs = doclist.get_checked_items();
			if (selected_pgs.length > 0) {
				let pagenames = selected_pgs.map((pg) => pg.name);
				jingrow.call({
					method: "jingrow.core.pagetype.deleted_document.deleted_document.bulk_restore",
					args: { pagenames },
					callback: function (r) {
						if (r.message) {
							let body = (pagenames) => {
								const html = pagenames.map((pagename) => {
									return `<li><a href='/app/deleted-document/${pagename}'>${pagename}</a></li>`;
								});
								return "<br><ul>" + html.join("");
							};

							let message = (title, pagenames) => {
								return pagenames.length > 0 ? title + body(pagenames) + "</ul>" : "";
							};

							const { restored, invalid, failed } = r.message;
							const restored_summary = message(
								__("Documents restored successfully"),
								restored
							);
							const invalid_summary = message(
								__("Documents that were already restored"),
								invalid
							);
							const failed_summary = message(
								__("Documents that failed to restore"),
								failed
							);
							const summary = restored_summary + invalid_summary + failed_summary;

							jingrow.msgprint(summary, __("Document Restoration Summary"), true);

							if (restored.length > 0) {
								doclist.refresh();
							}
						}
					},
				});
			}
		};
		doclist.page.add_actions_menu_item(__("Restore"), action, false);
	},
};
