import { statusLabel, statusTone } from '../admin-data';

/**
 * Maps the shared status tone (ready/warning/danger) onto the design-system
 * badge class names used by the locked CSS (scheduled/running/success/failed/
 * canceled). One mapper, so no section reimplements badge tone logic.
 */
export type BadgeTone =
	| 'scheduled'
	| 'running'
	| 'success'
	| 'failed'
	| 'canceled';

export interface StatusView {
	label: string;
	badgeTone: BadgeTone;
}

const toBadgeTone = ( value: unknown ): BadgeTone => {
	switch ( statusTone( value ) ) {
		case 'ready':
			return 'success';
		case 'danger':
			return 'failed';
		case 'warning':
		default:
			return 'running';
	}
};

export const launchStatusView = ( value: unknown ): StatusView => ( {
	label: statusLabel( value ),
	badgeTone: toBadgeTone( value ),
} );
