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

jingrow.ui.form.on('TLS Certificate', {
	refresh: function (frm) {
		frm.add_custom_button(__('Obtain Certificate'), () => {
			frm.call({
				method: 'obtain_certificate',
				pg: frm.pg,
				callback: (result) => frm.refresh(),
			});
		});
		if (frm.pg.wildcard) {
			frm.add_custom_button(__('Trigger Callback'), () => {
				frm.call({
					method: 'trigger_server_tls_setup_callback',
					pg: frm.pg,
					callback: (result) => frm.refresh(),
				});
			});
		}
		if (frm.pg.private_key) {
			frm.add_custom_button(__('Copy Private Key'), () => {
				jingrow.utils.copy_to_clipboard(frm.pg.private_key);
			});
		}
	},
});
