You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { Button, ButtonGroup, Typography } from '@mui/material';
  2. import { Box } from '@mui/system';
  3. import { useTranslation } from 'next-i18next';
  4. import Image from 'next/image';
  5. import { useState } from 'react';
  6. interface DataProps {
  7. name: string;
  8. description: string;
  9. }
  10. interface ProductInfoProps {
  11. data: DataProps;
  12. bColor: string;
  13. inCart: boolean;
  14. addProductToCart: (quantity: number) => void;
  15. }
  16. const ProductInfo: React.FC<ProductInfoProps> = ({ data, bColor, addProductToCart, inCart }) => {
  17. const { t } = useTranslation('home');
  18. const [quantity, setQuantity] = useState<number>(1);
  19. const handleIncrement = () => {
  20. setQuantity((prevState) => prevState + 1);
  21. };
  22. const handleDecrement = () => {
  23. if (quantity > 1) {
  24. setQuantity((prevState) => prevState - 1);
  25. }
  26. };
  27. return (
  28. <Box
  29. sx={{
  30. display: 'flex',
  31. flexDirection: 'column',
  32. alignItems: { xs: 'center', md: 'flex-start' },
  33. width: { xs: '100%', md: '50%' },
  34. height: '100%',
  35. }}
  36. >
  37. <Typography variant="h3" sx={{ mt: { xs: 5 }, color: 'white' }}>
  38. {data.name}
  39. </Typography>
  40. <Box
  41. sx={{
  42. display: 'flex',
  43. alignItems: { xs: 'center', md: 'flex-start' },
  44. justifyContent: { xs: 'center', md: 'flex-start' },
  45. width: '100%',
  46. py: { xs: 2 },
  47. }}
  48. >
  49. <Image
  50. src="/images/Stars.svg"
  51. alt="reviews"
  52. width={100}
  53. height={50}
  54. ></Image>
  55. </Box>
  56. <Typography
  57. sx={{
  58. color: 'white',
  59. }}
  60. >
  61. {data.description}
  62. </Typography>
  63. <Box
  64. sx={{
  65. width: '100%',
  66. display: 'flex',
  67. mt: 6,
  68. flexDirection: { md: 'row' },
  69. alignItems: { xs: 'center' },
  70. justifyContent: { xs: 'center', md: 'flex-start' },
  71. }}
  72. >
  73. <ButtonGroup
  74. disabled={inCart}
  75. size="small"
  76. aria-label="small outlined button group"
  77. sx={{
  78. height: 50,
  79. backgroundColor: bColor === 'light' ? '#664c47' : '#8f7772',
  80. color: 'white',
  81. border: 0,
  82. }}
  83. >
  84. <Button
  85. disableRipple
  86. sx={{
  87. '&.Mui-disabled': {
  88. color: 'rgba(255, 255, 255, 0.6)',
  89. },
  90. color: 'white',
  91. fontSize: 20,
  92. width: 50,
  93. }}
  94. onClick={() => {
  95. handleDecrement();
  96. }}
  97. >
  98. -
  99. </Button>
  100. <Button
  101. disableRipple
  102. sx={{
  103. '&.Mui-disabled': {
  104. color: 'rgba(255, 255, 255, 0.6)',
  105. },
  106. color: 'white',
  107. fontSize: 17,
  108. width: 50,
  109. }}
  110. >
  111. {quantity}
  112. </Button>
  113. <Button
  114. disableRipple
  115. sx={{
  116. '&.Mui-disabled': {
  117. color: 'rgba(255, 255, 255, 0.6)',
  118. },
  119. color: 'white',
  120. fontSize: 20,
  121. width: 50,
  122. }}
  123. onClick={() => {
  124. handleIncrement();
  125. }}
  126. >
  127. +
  128. </Button>
  129. </ButtonGroup>
  130. <Button
  131. disableRipple
  132. sx={{
  133. mt: { md: 0 },
  134. ml: { xs: 2 },
  135. backgroundColor: '#CBA213',
  136. height: 50,
  137. width: 150,
  138. color: 'white',
  139. '&.Mui-disabled': {
  140. backgroundColor: '#f2d675',
  141. color: '#464646',
  142. },
  143. '&:hover': {
  144. backgroundColor: '#f2d675',
  145. color: '#464646',
  146. boxShadow: 'none',
  147. },
  148. }}
  149. disabled={inCart}
  150. onClick={() => addProductToCart(quantity)}
  151. >
  152. {inCart ? t('home:in') : t('home:add')}
  153. </Button>
  154. </Box>
  155. </Box>
  156. );
  157. };
  158. export default ProductInfo;