/**
 * JS mirror of App\API\Attributes::slugify() for the live preview only —
 * PHP remains authoritative at create time.
 *
 * @param {string} label Human label.
 * @return {string} Brevo attribute name.
 */
export function slugify( label ) {
	let name = ( label || '' ).trim().toUpperCase();

	name = name.replace( /[^A-Z0-9_]+/g, '_' );
	name = name.replace( /_+/g, '_' );
	name = name.replace( /^_+|_+$/g, '' );

	if ( name && /^\d/.test( name ) ) {
		name = 'F_' + name;
	}

	return name.slice( 0, 50 );
}
