import { __, sprintf } from '@wordpress/i18n';

export type QuietHoursWindow = {
	from: string;
	to: string;
};

const WINDOW_SEPARATOR = '-';

export const QUIET_HOURS_WINDOWS: readonly QuietHoursWindow[] = [
	{ from: '23:00', to: '05:00' },
	{ from: '01:00', to: '05:00' },
	{ from: '02:00', to: '06:00' },
];

export function windowValue( quietWindow: QuietHoursWindow ): string {
	return `${ quietWindow.from }${ WINDOW_SEPARATOR }${ quietWindow.to }`;
}

export function windowOf( value: string ): QuietHoursWindow {
	const [ from = '', to = '' ] = value.split( WINDOW_SEPARATOR );

	return { from, to };
}

export function windowLabel( quietWindow: QuietHoursWindow ): string {
	return sprintf(
		/* translators: 1: start time, 2: end time, for example 01:00 and 05:00 */
		__( '%1$s to %2$s', 'aiplaz-link-checkup' ),
		quietWindow.from,
		quietWindow.to
	);
}

export function windowChangedText( quietWindow: QuietHoursWindow ): string {
	return sprintf(
		/* translators: 1: start time, 2: end time, for example 01:00 and 05:00 */
		__( 'Night hours set to %1$s to %2$s.', 'aiplaz-link-checkup' ),
		quietWindow.from,
		quietWindow.to
	);
}

export function quietHoursSwitchedText( isEnabled: boolean ): string {
	if ( isEnabled ) {
		return __(
			'The full check now waits for the night.',
			'aiplaz-link-checkup'
		);
	}

	return __( 'The full check can run at any time.', 'aiplaz-link-checkup' );
}
