frappe.ui.form.on("Company", {
    refresh: function (frm) {
        frm.add_custom_button(__("Export Defaults"), function () {
            frappe.call({
                method: "jey_erp.custom.company_export.export_company_defaults",
                callback: function (r) {
                    if (!r.message) return;
                    const json = JSON.stringify(r.message, null, 2);
                    const blob = new Blob([json], { type: "application/json" });
                    const url = URL.createObjectURL(blob);
                    const a = document.createElement("a");
                    a.href = url;
                    a.download = "company_defaults.json";
                    a.click();
                    URL.revokeObjectURL(url);
                },
            });
        });
    },
});
