// Copyright (c) 2022, JINGROW
// For license information, please see license.txt

jingrow.ui.form.on('Virtual Disk Snapshot', {
	refresh: function (frm) {
		[
			[__('Sync'), 'sync'],
			[__('Delete'), 'delete_snapshot'],
		].forEach(([label, method]) => {
			frm.add_custom_button(
				label,
				() => {
					frm.call(method).then((r) => frm.refresh());
				},
				__('Actions'),
			);
		});
		if (frm.pg.snapshot_id) {
			frm.add_web_link(
				`https://${frm.pg.region}.console.aws.amazon.com/ec2/v2/home?region=${frm.pg.region}#SnapshotDetails:snapshotId=${frm.pg.snapshot_id}`,
				__('Visit AWS Dashboard'),
			);
		}
	},
});
