import type { SeatMap } from '@/constants/seatMap/SeatMap' import type { SeatRow } from '@/constants/seatMap/SeatRow' import { IataTravelerTypes } from '@/constants/seatMap/IataTravelerTypes' export type SeatMapLayout = (string | null)[] export interface FormattedSeatMapZone { id: string layout: SeatMapLayout title: string } /** A zone wider than this many columns switches the map to its compact treatment. */ const LARGE_PLANE_COLUMNS = 6 export const displaySeat = (seat: { column: string; row: number }) => `${seat.row}${seat.column}` export const getSeatMapZones = (seatMap: SeatMap): FormattedSeatMapZone[] => { return Object.keys(seatMap.zones).map((zoneId) => { const zone = seatMap.zones[zoneId] return { id: zoneId, title: zone?.title || '', layout: zone?.layout || [], } }) } export const getZoneRows = (seatMap: SeatMap, zoneId: string): SeatRow[] => { return seatMap.rows.filter((row) => row.zone === zoneId).sort((a, b) => a.number - b.number) } export const isLargeSeatMap = (zones: FormattedSeatMapZone[]) => { return zones.some((zone) => zone.layout.length > LARGE_PLANE_COLUMNS) } /** A `null` column is an aisle; it gets a named grid area so row numbers can sit in it. */ export const getGridTemplateAreas = (layout: SeatMapLayout) => { let hallwayIndex = 0 return layout .map((column) => { if (column === null) { hallwayIndex++ return `HALLWAY-${hallwayIndex}` } return column }) .join(' ') } export const getGridTemplateColumns = (layout: SeatMapLayout) => { return layout.map((column) => (column === null ? 'var(--hallway-width)' : 'var(--seat-width)')).join(' ') } /** Number of columns before the first aisle, used to span row facilities. */ export const getSeatBlockSize = (layout: SeatMapLayout) => { const firstNullIndex = layout.indexOf(null) return firstNullIndex > 0 ? firstNullIndex + 1 : layout.length } export const hasHallway = (layout: SeatMapLayout) => layout.includes(null) export const getHallways = (layout: SeatMapLayout) => { return layout.filter((column) => column === null).map((column, index) => ({ column, index: index + 1 })) } export const getTravelerIcon = (passengerType?: IataTravelerTypes) => { if (!passengerType || passengerType === IataTravelerTypes.ADULT) return '' if ([IataTravelerTypes.CHILD, IataTravelerTypes.UNACCOMPANIED_MINOR].includes(passengerType)) return 'child' return 'infant' }