import React from 'react'; import Link from 'next/link'; import moment from 'moment'; import { DragSourceMonitor, useDrag } from 'react-dnd'; import ListActionsPopover from '../ListActionsPopover'; type Props = { item: any; column: { id: string; label: string }; entityName: string; showFieldName: string; setItemIdToDelete: (id: string) => void; }; const humanize = (value?: string | null) => { if (!value) return ''; return value .replace(/_/g, ' ') .replace(/\b\w/g, (char) => char.toUpperCase()); }; const formatDateRange = (start?: string, end?: string) => { if (!start && !end) return ''; if (start && end) { return `${moment(start).format('MMM D')} – ${moment(end).format('MMM D')}`; } return moment(start || end).format('MMM D'); }; const KanbanCard = ({ item, entityName, showFieldName, setItemIdToDelete, column, }: Props) => { const [{ isDragging }, drag] = useDrag( () => ({ type: 'box', item: { item, column }, collect: (monitor: DragSourceMonitor) => ({ isDragging: monitor.isDragging(), }), }), [item, column], ); const title = item?.[showFieldName] ?? 'Untitled'; const dateRange = formatDateRange(item?.check_in_at || item?.start_at, item?.check_out_at || item?.end_at); const locationLabel = item?.preferred_property?.name || item?.property?.name || item?.unit?.unit_number || item?.unit_type?.name || ''; const supportingLabel = item?.requested_by?.email || item?.requested_by?.firstName || item?.organization?.name || item?.organizations?.name || ''; const updatedAt = item?.updatedAt || item?.createdAt; const stats = [ item?.guest_count ? { label: 'Guests', value: String(item.guest_count) } : null, item?.priority ? { label: 'Priority', value: humanize(item.priority) } : null, dateRange ? { label: entityName === 'booking_requests' ? 'Stay' : 'Dates', value: dateRange } : null, locationLabel ? { label: 'Location', value: locationLabel } : null, ].filter(Boolean) as Array<{ label: string; value: string }>; return (
{title} {supportingLabel && (

{supportingLabel}

)}
setItemIdToDelete(id)} hasUpdatePermission={true} className='h-5 w-5 text-gray-400 dark:text-gray-500' iconClassName='w-5 text-gray-400 dark:text-gray-500' />
{stats.length > 0 && (
{stats.slice(0, 3).map((stat) => (
{stat.label} {stat.value}
))}
)}
{humanize(column.label)} {updatedAt ? moment(updatedAt).format('MMM D') : '—'}
); }; export default KanbanCard;