import { Checkbox, FormControlLabel, Grid, Typography, Box } from '@mui/material';

const enabled = value => [true, 1, '1', 'true', 'yes', 'on'].includes(value);
const AppointmentDelivery = ({ state, handleChange }) => (
	<Grid container spacing={1} mt={3} mb={3}>
		<Grid item xs={4}>
			<Typography variant='subtitle1' fontWeight='bold'>Appointment delivery settings</Typography>
			<p><strong>Always quote appointment delivery</strong> - When checked, every quote will include the carrier’s appointment delivery fee.</p>
			<p><strong>Offer appointment delivery as an option</strong> - When checked, an additional option will be presented to the shopper that will include the appointment delivery fee. The shopper will be able to choose between options that exclude or include appointment delivery.</p>
		</Grid>
		<Grid item xs={8}>
			<Box>
				<FormControlLabel label='Always quote appointment delivery' control={
					<Checkbox checked={enabled(state?.always_quote_appointment_delivery)} onChange={e => {
						handleChange('always_quote_appointment_delivery', e.target.checked);
						handleChange('appointment_delivery_as_option', false);
					}} />
				} />
			</Box>
			<FormControlLabel label='Offer appointment delivery as an option' control={
				<Checkbox checked={enabled(state?.appointment_delivery_as_option)} onChange={e => {
					handleChange('appointment_delivery_as_option', e.target.checked);
					handleChange('always_quote_appointment_delivery', false);
				}} />
			} />
		</Grid>
	</Grid>
);

export default AppointmentDelivery;
