import _find from 'lodash/find' import _forEach from 'lodash/forEach' import _isEmpty from 'lodash/isEmpty' import _values from 'lodash/values' export const getTierIdBasedOnSeatId = (seatId: string, eventSeats: Array) => { let tierId: number | string = '' _forEach(eventSeats, group => { _forEach(group.seats, (seatsCount, rowId) => { const [row_id, seat_id] = seatId.split(':') if (row_id === rowId && seat_id <= seatsCount) { tierId = Number(group.tier_id) return false } return true }) }) return tierId } export const getButtonLabel = (count: number, tableMapEnabled: boolean) => { if (!count) { return tableMapEnabled ? `GET TABLES` : `GET TICKETS` } else if (count === 1) { return tableMapEnabled ? `GET ${count} TABLE` : `GET ${count} TICKET` } return tableMapEnabled ? `GET ${count} TABLES` : `GET ${count} TICKETS` } export const getOwnReservationsBasedOnStatuses = (statuses: any) => { const ownReservations: string[] = [] Object.keys(statuses).forEach((groupRowId: string) => Object.keys(statuses[groupRowId]).forEach((seatIndex: string | number) => { if (statuses[groupRowId][seatIndex] === 'OR') { ownReservations.push(`${groupRowId}:${seatIndex}`) } else if (statuses[groupRowId][seatIndex] === 'H') { statuses[groupRowId][seatIndex] = 'BLOCKED' } }) ) return ownReservations } export const getTicketDropdownData = ( reservationData: Array, tierReleations: TicketTypeTierRelations ) => { const ticketsDropdownsData: Array = [] _forEach(reservationData, reservation => { if (tierReleations[reservation.tierId]) { const ticketsData = _values(tierReleations[reservation.tierId]) ticketsDropdownsData.push({ seatId: reservation.seatId, tierId: reservation.tierId, ticketsData, }) } else { ticketsDropdownsData.push({ seatId: reservation.seatId, tierId: reservation.tierId, ticketsData: [ { ticket_type_tier_id: reservation.tierId, ticket_type_name: 'Please select Ticket Type', ticket_type_price: '', ticket_type_id: 'default', }, ], }) } }) return ticketsDropdownsData } export const getAddToCartRequestData = ({ eventId, reservations = [], selectedSeats = [], selectedTickets = [], guestCounts = {}, }: any) => { const hasGuests = !_isEmpty(guestCounts) const addToCartData: ICartRequestData = { attributes: { alternative_view_id: null, product_cart_quantity: reservations.length, product_options: {}, product_id: eventId, ticket_types: {}, }, } const productOptions = {} as any const ticketTypes = {} as any _forEach(reservations, (item, index) => { const ticket = _find( selectedSeats[item], sitem => sitem.ticket_type_id === selectedTickets[item] ) productOptions[ticket.ticket_type_option] = ticket.ticket_type_id const ticketTypesKey = hasGuests ? index : ticket.ticket_type_id const quantity = hasGuests ? guestCounts[item] : (ticketTypes[ticket.ticket_type_id]?.quantity || 0) + 1 ticketTypes[ticketTypesKey] = { quantity, product_options: { [ticket.ticket_type_option]: ticket.ticket_type_id, ticket_price: ticket.ticket_type_price, }, } }) addToCartData.attributes.product_options = productOptions addToCartData.attributes.ticket_types = ticketTypes return addToCartData } export const getTierRelationsArray = (data: Array) => { const ticketTypeTireRelationsArray: Array = [] _forEach(data, (item: TicketTypeTierRelationsData) => { ticketTypeTireRelationsArray.push(...(_values(item) as any)) }) return ticketTypeTireRelationsArray }