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

const LABEL = "Add UPS's per package commercial invoice fee to international shipments";
const FEE_PATTERN = /^[0-9]*\.?[0-9]*$/;

/**
 * UPS's per package commercial invoice fee, added to international quotes once for every package.
 */
const CommercialInvoiceFee = ({ state = {}, handleChange = (name = '', val = '') => {} }) => {
	return (
		<Grid container spacing={1} flex mt={3} mb={3}>
			<Grid item flex={1} xs={4}>
				<Typography variant='subtitle1' fontWeight='bold'>
					Commercial invoice settings
				</Typography>
			</Grid>

			<Grid item flex={2} xs={8}>
				<Box component='form'>
					<TextField
						label={LABEL}
						title={LABEL}
						variant='standard'
						helperText='Enter the fee to apply per package, e.g. 5.00. This will be multiplied by the number of packages in international shipments.'
						InputLabelProps={{ shrink: true }}
						inputProps={{ maxLength: 6, 'aria-label': LABEL }}
						fullWidth
						value={state?.commercial_invoice_fee ?? ''}
						onChange={e =>
							e.target.value.length < 7 &&
							FEE_PATTERN.test(e.target.value) &&
							handleChange('commercial_invoice_fee', e.target.value)
						}
					/>
				</Box>
			</Grid>
		</Grid>
	);
};

export default CommercialInvoiceFee;
