import React from 'react';
import { Text } from 'react-native';

import styles from './styles';
import { useTheme } from '../../theme';
import Touchable from '../message/Touchable';

const PlaybackSpeed = ({
	onChange,
	loaded = false,
	rate = 1
}: {
	onChange: (value: number) => void;
	loaded: boolean;
	rate: number;
}) => {
	const { colors } = useTheme();

	const onPress = () => {
		const nextRate = rate === 2 ? 0.5 : rate + 0.5;
		onChange(nextRate);
	};

	return (
		<Touchable
			disabled={!loaded}
			onPress={onPress}
			style={[styles.containerPlaybackSpeed, { backgroundColor: colors.buttonBackgroundSecondaryDefault }]}
		>
			<Text style={[styles.playbackSpeedText, { color: colors.buttonFontOnSecondary }]}>{rate}x</Text>
		</Touchable>
	);
};

export default PlaybackSpeed;
