import { CSSProperties } from '@emotion/serialize' import { Select, SelectChangeEvent, ThemeOptions } from '@mui/material' import CircularProgress from '@mui/material/CircularProgress' import FormControl from '@mui/material/FormControl' import InputLabel from '@mui/material/InputLabel' import MenuItem from '@mui/material/MenuItem' import { createTheme, ThemeProvider } from '@mui/material/styles' import Tooltip from '@mui/material/Tooltip' import _find from 'lodash/find' import _identity from 'lodash/identity' import _isEmpty from 'lodash/isEmpty' import _keys from 'lodash/keys' import _map from 'lodash/map' import _some from 'lodash/some' import React, { useState } from 'react' import { Button } from 'react-bootstrap' import { createFixedFloatNormalizer } from '../../normalizers' import { createMarkup } from '../../utils' import { getButtonLabel, getTicketDropdownData } from './utils' export const TicketsSection = ( props: ITicketsSectionProps & { themeOptions?: ThemeOptions & { input?: CSSProperties; checkbox?: CSSProperties; }; } ) => { const { ticketTypeTierRelations, reservedSeats, theme = 'light', getTicketsBtnLabel, contentStyle = {}, isButtonScrollable = false, themeOptions, handleGetTicketClick, handleCancelReservation, ticketDeleteButtonContent = 'Delete', ticketInfoContent = 'Info', selectedTickets, handleTicketSelect, currencySymbol, tableMapEnabled = false, guestCounts, setGuestCounts, isAddingToCart, } = props const [selectedTicketsInfo, setSelectedTicketsInfo] = useState<{ [seatId: string]: boolean | undefined; }>({}) const bookButtonIsDisabled = _some(selectedTickets, item => !item) || _isEmpty(reservedSeats) || reservedSeats.length !== _keys(selectedTickets).length const themeMui = createTheme(themeOptions) const ticketsDropdownsData = getTicketDropdownData( reservedSeats, ticketTypeTierRelations ) const handleTicketChange = (event: SelectChangeEvent, seatId: string) => { const { target: { value }, } = event if (value !== 'default') { handleTicketSelect(value, seatId) } } const handleShowtTicketInfo = (seatId: string) => { setSelectedTicketsInfo(prevState => ({ ...prevState, [seatId]: !prevState[seatId] })) } return (
{_map(selectedTickets, (ticketItem: string, key: string) => { const dropdownData = _find(ticketsDropdownsData, item => item.seatId === key) || ({} as ITicketsDropdownsData) const selectedTicketData = _find( dropdownData.ticketsData, ticket => ticket.ticket_type_id === ticketItem ) as TicketTypeTierRelationsData // guest count dropdown options const startNum = Number(selectedTicketData?.ticket_type_min_number_of_guests) const endNum = Number(selectedTicketData?.ticket_type_max_number_of_guests) const numLength = endNum - startNum + 1 const showGuestCountDropdown = Boolean(startNum && endNum) const showDescription = Boolean(selectedTicketData?.description) // prices const guestPrice = (guestCounts[dropdownData.seatId] - startNum) * Number(selectedTicketData?.guest_price) const finalPrice = createFixedFloatNormalizer(2)( selectedTicketData?.ticket_type_price + guestPrice ) return (
{selectedTicketData && ( <>
Price: {`${currencySymbol} ${finalPrice}`} {selectedTicketData.fee_included ? ' (incl. Fees)' : ' (excl. Fees)'}
{!_isEmpty(selectedTicketData.ticket_type_deposit) && (
Deposit: {` ${selectedTicketData?.ticket_type_deposit}%`}
)}
{showDescription && (
handleShowtTicketInfo(dropdownData.seatId)} onKeyDown={() => handleShowtTicketInfo(dropdownData.seatId)} > {ticketInfoContent}
)} {showGuestCountDropdown && ( GUESTS )}
{selectedTicketsInfo[dropdownData.seatId] && (
)} )}
) })}
) }