import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import Divider from '@mui/material/Divider'; import { formHelperTextClasses } from '@mui/material/FormHelperText'; import Link, { linkClasses } from '@mui/material/Link'; import MenuItem from '@mui/material/MenuItem'; import Rating from '@mui/material/Rating'; import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { useCallback } from 'react'; import { Controller, useForm } from 'react-hook-form'; import { ColorPicker } from 'src/components/color-utils'; import { Field, Form } from 'src/components/hook-form'; import { Iconify } from 'src/components/iconify'; import { Label } from 'src/components/label'; import { NumberInput } from 'src/components/number-input'; import { useRouter } from 'src/routes/hooks'; import { paths } from 'src/routes/paths'; import type { CheckoutContextValue } from 'src/types/checkout'; import type { IPartyEventItem } from 'src/types/party-event'; import { fCurrency, fShortenNumber } from 'src/utils/format-number'; // ---------------------------------------------------------------------- type Props = { partyEvent: IPartyEventItem; disableActions?: boolean; items?: CheckoutContextValue['state']['items']; onAddToCart?: CheckoutContextValue['onAddToCart']; }; export function PartyEventDetailsSummary({ items, partyEvent, onAddToCart, disableActions, ...other }: Props) { const router = useRouter(); const { id, name, sizes, price, colors, coverUrl, newLabel, available, priceSale, saleLabel, totalRatings, totalReviews, inventoryType, subDescription, } = partyEvent; const existProduct = !!items?.length && items.map((item) => item.id).includes(id); const isMaxQuantity = !!items?.length && items.filter((item) => item.id === id).map((item) => item.quantity)[0] >= available; const defaultValues = { id, name, coverUrl, available, price, colors: colors[0], size: sizes[4], quantity: available < 1 ? 0 : 1, }; const methods = useForm({ defaultValues, }); const { watch, control, setValue, handleSubmit } = methods; const values = watch(); const onSubmit = handleSubmit(async (data) => { console.info('DATA', JSON.stringify(data, null, 2)); try { if (!existProduct) { onAddToCart?.({ ...data, colors: [values.colors] }); } router.push(paths.product.checkout); } catch (error) { console.error(error); } }); const handleAddCart = useCallback(() => { try { onAddToCart?.({ ...values, colors: [values.colors], subtotal: values.price * values.quantity, }); } catch (error) { console.error(error); } }, [onAddToCart, values]); const renderPrice = () => ( {priceSale && ( {fCurrency(priceSale)} )} {fCurrency(price)} ); const renderShare = () => ( Compare Favorite Share ); const renderColorOptions = () => ( Color ( field.onChange(color as string)} limit={4} /> )} /> ); const renderSizeOptions = () => ( Size Size chart } sx={{ maxWidth: 88, [`& .${formHelperTextClasses.root}`]: { mx: 0, mt: 1, textAlign: 'right' }, }} > {sizes.map((size) => ( {size} ))} ); const renderQuantity = () => ( Quantity setValue('quantity', quantity)} max={available} sx={{ maxWidth: 112 }} /> Available: {available} ); const renderActions = () => ( ); const renderSubDescription = () => ( {subDescription} ); const renderRating = () => ( {`(${fShortenNumber(totalReviews)} reviews)`} ); const renderLabels = () => (newLabel.enabled || saleLabel.enabled) && ( {newLabel.enabled && } {saleLabel.enabled && } ); const renderInventoryType = () => ( {inventoryType} ); return (
{renderLabels()} {renderInventoryType()} {name} {renderRating()} {renderPrice()} {renderSubDescription()} {renderColorOptions()} {renderSizeOptions()} {renderQuantity()} {renderActions()} {renderShare()}
); }