import { __ } from '@wordpress/i18n' import classNames from 'classnames' import { ReactComponent as AnyAvailableIcon } from '../../../../public/images/icon-any-available.svg' import { ReactComponent as CheckIcon } from '../../../../public/images/icon-checkmark-staff.svg' import { IStaffOption, IStaffSelectorProps } from './types' import './StaffSelector.scss' import { useWording } from '../../hooks/useWording' export const STAFF_ANY_AVAILABLE = '0' export const StaffSelector = ({ staffOptions, selectedStaffId, onSelect, treatNullAsAnyAvailable = true, }: IStaffSelectorProps) => { const isAnyAvailableSelected = (id: string | null) => id === STAFF_ANY_AVAILABLE || (treatNullAsAnyAvailable && id === null) const wording = useWording() return (
{ e.preventDefault() e.stopPropagation() onSelect(STAFF_ANY_AVAILABLE) }} > {wording.any_available ?? __('Any Available', 'webba-booking-lite')} {wording.best_available_time ?? __('Best available time.', 'webba-booking-lite')} {isAnyAvailableSelected(selectedStaffId) && ( )}
{staffOptions.map((staff: IStaffOption) => { const isSelected = selectedStaffId === staff.id return (
{ e.preventDefault() e.stopPropagation() onSelect(staff.id) }} > {staff.photo ? ( {staff.label} ) : ( {staff.label .split(/\s+/) .map((w: string) => w[0]) .join('') .slice(0, 2) .toUpperCase()} )} {staff.label} {isSelected && ( )}
) })}
) }