function _sync_bank_codes(callback) {
	frappe.show_alert({ message: __("Syncing bank codes..."), indicator: "blue" });
	frappe.call({
		method: "kapital_bank.payment_api.sync_bank_codes",
		callback(r) {
			const res = r.message;
			if (!res) return;
			frappe.show_alert({
				message: __("Bank codes synced: {0} added, {1} updated (total {2})", [res.added, res.updated, res.total]),
				indicator: "green",
			}, 6);
			if (callback) callback();
		},
	});
}

frappe.listview_settings["Kapital Bank Bank Code"] = {
	onload(listview) {
		listview.page.add_inner_button(__("Sync Bank Codes"), () => {
			_sync_bank_codes(() => listview.refresh());
		});
	},
};
