import * as React from 'react'; import { __ } from '@wordpress/i18n'; import type { BookingApi } from '../booking-ui/api'; import { formatDateTime, formatRange } from '../booking-ui/dateTime'; interface DailyRow { id: number; reference: string; resource_name: string; customer_name: string; starts_at: string; ends_at: string; admin_note: string | null; customer_note: string | null; cancelled_at?: string | null; cancelled_by_name?: string; cancelled_by_role?: string | null; cancellation_reason?: string | null; } interface DailyData { date: string; timezone: string; admin_notes: DailyRow[]; customer_notes: DailyRow[]; cancelled_bookings: DailyRow[]; } export function DailyOverview({ api, date, refresh, onBooking }: { api: BookingApi; date: string; refresh: number; onBooking: (id: number) => void; }) { const [data, setData] = React.useState(null), [error, setError] = React.useState(''); React.useEffect(() => { let live = true; setData(null); setError(''); if (date) api.request('admin/daily-overview', 'GET', undefined, { date }).then(d => { if (live) setData(d); }).catch(e => { if (live) setError(e.message); }); return () => { live = false; }; }, [api, date, refresh]); const sections = [{ key: 'admin_notes' as const, title: __('Operational notes', 'abece-booking'), empty: __('No operational notes.', 'abece-booking') }, { key: 'customer_notes' as const, title: __('Booking notes', 'abece-booking'), empty: __('No customer notes.', 'abece-booking') }, { key: 'cancelled_bookings' as const, title: __('Cancelled bookings', 'abece-booking'), empty: __('No cancelled bookings.', 'abece-booking') }]; return

{__('Daily overview', 'abece-booking')}

{error &&

{error}

}{!data && !error &&

{__('Loading…', 'abece-booking')}

}{data && sections.map(s =>

{s.title}

{data[s.key].length ?
{s.key === 'cancelled_bookings' && <>}{data[s.key].map(b => {s.key === 'cancelled_bookings' && <>})}
{s.key === 'cancelled_bookings' ? __('Original time', 'abece-booking') : __('Time', 'abece-booking')}{__('Resource', 'abece-booking')}{__('Customer', 'abece-booking')}{__('Reference', 'abece-booking')}{s.key === 'admin_notes' ? __('Internal note', 'abece-booking') : s.key === 'customer_notes' ? __('Note', 'abece-booking') : __('Cancellation reason', 'abece-booking')}{__('Cancelled by', 'abece-booking')}{__('Cancelled at', 'abece-booking')}{__('Actions', 'abece-booking')}
{formatRange(b.starts_at, b.ends_at, data.timezone, false)}{b.resource_name}{b.customer_name}{b.reference}{s.key === 'admin_notes' ? b.admin_note : s.key === 'customer_notes' ? b.customer_note : b.cancellation_reason || '—'}{b.cancelled_by_name}{b.cancelled_by_role && {b.cancelled_by_role === 'admin' ? __('Admin', 'abece-booking') : __('Customer', 'abece-booking')}}{formatDateTime(b.cancelled_at, data.timezone)}
:

{s.empty}

}
)}
; }