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

const enabled = value => [true, 1, '1', 'true', 'yes', 'on'].includes(value);

/**
 * Notify before delivery: always quoted, or offered to the shopper as an option. The two exclude
 * each other, as the appointment delivery pair does.
 */
const NotifyBeforeDelivery = ({ state, handleChange }) => (
	<Grid container spacing={1} mt={3} mb={3} className='woo-rtsq-notify-before-delivery'>
		<Grid item xs={4}>
			<Typography variant='subtitle1' fontWeight='bold'>Notify before delivery settings</Typography>
			<p><strong>Always quote notify before delivery</strong> - When checked, every quote will include the carrier’s notify before delivery fee.</p>
			<p><strong>Offer notify before delivery as an option</strong> - When checked, an additional option will be presented to the shopper that will include the notify before delivery fee. The shopper will be able to choose between options that exclude or include notify before delivery.</p>
		</Grid>
		<Grid item xs={8}>
			<Box>
				<FormControlLabel label='Always quote notify before delivery' title='Always quote notify before delivery' control={
					<Checkbox checked={enabled(state?.always_quote_notify_before_delivery)} onChange={e => {
						handleChange('always_quote_notify_before_delivery', e.target.checked);
						handleChange('notify_before_delivery_as_option', false);
					}} />
				} />
			</Box>
			<FormControlLabel label='Offer notify before delivery as an option' title='Offer notify before delivery as an option' control={
				<Checkbox checked={enabled(state?.notify_before_delivery_as_option)} onChange={e => {
					handleChange('notify_before_delivery_as_option', e.target.checked);
					handleChange('always_quote_notify_before_delivery', false);
				}} />
			} />
		</Grid>
	</Grid>
);

export default NotifyBeforeDelivery;
