// Centralized list-view subject translator.
//
// For doctypes whose record names are translatable data (translated_doctype=1),
// Link references already translate, but the doctype's OWN list view shows the
// subject/title column untranslated: list_view.js only auto-translates columns
// whose df.options is a translated doctype (i.e. Link columns), not the subject.
// get_subject_text() does apply a formatter registered for the subject field, so
// we register one here that runs the value through __().
//
// Map: doctype -> subject fieldname. That is the doctype's title_field if it has
// one, otherwise "name" (the list subject column falls back to name — see
// list_view.js setup_columns()).
const AZ_LOCALE_SUBJECT_FIELDS = {
	"Supplier Scorecard Standing": "name",
	"Supplier Scorecard Variable": "name",
	"Activity Type": "name",
	"Market Segment": "name",
	"Role": "name",
	"Role Profile": "role_profile",
	UOM: "name",
	"UOM Category": "name",
	Territory: "name",
	"Price List": "name",
};

for (const [doctype, field] of Object.entries(AZ_LOCALE_SUBJECT_FIELDS)) {
	const existing = frappe.listview_settings[doctype] || {};
	frappe.listview_settings[doctype] = Object.assign(existing, {
		formatters: Object.assign(existing.formatters || {}, {
			[field](value) {
				return __(value);
			},
		}),
	});
}
