import { Button, Card, Divider, Typography } from '@mui/material';
import { Box } from '@mui/system';
import Image from 'next/image';
import { useRouter } from 'next/router';
import { setCookie } from 'nookies';
import PropType from 'prop-types';

const OrderSummaryCard = ({ data }) => {
  const router = useRouter();
  return (
    <Card sx={{ p: 3, width: '100%', mb: 2, backgroundColor: '#f1f1f1' }}>
      <Typography
        sx={{
          fontSize: 26,
          color: 'primary.main',
          textAlign: 'center',
          width: '100%',
        }}
      >
        Order Summary
      </Typography>
      <Typography sx={{ mt: 4 }}>
        Items total:${data.totalPrice.toFixed(2)}
      </Typography>
      <Typography sx={{ mt: 1.5 }}>Shipping Costs: FREE</Typography>
      <Typography sx={{ mt: 1.5, mb: 1.5 }}>
        Total: ${data.totalPrice.toFixed(2)}
      </Typography>
      <Divider />
      <Box sx={{ textAlign: 'center', mt: 4, width: '100%' }}>
        <Button
          disableRipple
          sx={{
            '&.Mui-disabled': {
              backgroundColor: '#0066ff',
              color: '#fff',
              opacity: '0.6',
            },
            '&:hover': {
              backgroundColor: '#0066ff',
              color: 'white',
              boxShadow: 'none',
            },
            backgroundColor: '#0066ff',
            color: 'white',
            textTransform: 'none',
            px: 2,
          }}
          startIcon={
            <Image src="/images/lock.svg" alt="lock" width={18} height={18} />
          }
          disabled={data.totalQuantity > 0 ? false : true}
          onClick={() => {
            router.push('/checkout');
            setCookie(null, 'checkout-session', 'active', {
              maxAge: 3600,
              expires: new Date(Date.now() + 3600),
              path: '/',
            });
          }}
        >
          Proceed to Checkout
        </Button>
      </Box>
      <Typography sx={{ mt: 3, fontSize: 13 }}>
        Once the checkout process begins you will have an hour to complete your
        checkout otherwise you will be returned back to the cart to start over.
      </Typography>
    </Card>
  );
};

OrderSummaryCard.propTypes = {
  data: PropType.shape({
    totalPrice: PropType.number,
    totalQuantity: PropType.number,
  }),
};

export default OrderSummaryCard;
