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

jingrow.ui.form.on("SSH Access Audit", {
    refresh(frm) {
        [
            [__('Run'), 'run', frm.pg.status === 'Pending'],
        ].forEach(([label, method, condition]) => {
            if (condition) {
                frm.add_custom_button(
                    label,
                    () => {
                        jingrow.confirm(
                            `Are you sure you want to ${label.toLowerCase()}?`,
                            () => frm.call(method).then(() => frm.refresh()),
                        );
                    },
                    __('Actions'),
                );
            }
        });
    },
});
