import { DailyOverview } from './DailyOverview'; import * as React from 'react'; import { __ } from '@wordpress/i18n'; import { BookingApi } from '../booking-ui/api'; import { Bookings } from '../booking-ui/Bookings'; import { Calendar, CalendarPanel, type CalendarPrefill } from '../booking-ui/Calendar'; import { CalendarBookingPanel } from '../booking-ui/CalendarBookingPanel'; import type { Booking } from '../booking-ui/types'; import { BookingEditor } from './BookingEditor'; export function ReservationsApp({ api }: { api: BookingApi; }) { const [tab, setTab] = React.useState(new URLSearchParams(window.location.search).get('view') === 'list' ? 'list' : 'calendar'); const [editor, setEditor] = React.useState(null), [prefill, setPrefill] = React.useState(), [detail, setDetail] = React.useState(Number(new URLSearchParams(window.location.search).get('booking')) || null); const [selectedDate, setSelectedDate] = React.useState(''); const [refresh, setRefresh] = React.useState(0), [message, setMessage] = React.useState(''); const dirty = React.useRef(false); const close = React.useCallback(() => { setEditor(null); setDetail(null); setPrefill(undefined); }, []); const requestClose = () => { if (!dirty.current || window.confirm(__('Discard unsaved booking changes?', 'abece-booking'))) { dirty.current = false; close(); } }; const edit = (b: Booking) => { dirty.current = false; setDetail(null); setEditor(b); setPrefill(undefined); setMessage(''); }; return

{__('Reservations', 'abece-booking')}

{false}{__('Outstanding amounts', 'abece-booking')}{__('External contacts', 'abece-booking')}
{message &&

{message}

} {tab === 'calendar' ? setRefresh(n => n + 1)} refresh={refresh} paused={editor !== null || detail !== null} onSelect={p => { dirty.current = false; setPrefill(p); setEditor('new'); setMessage(''); }} onBooking={setDetail}/> : } {tab === 'calendar' && selectedDate && } {editor && { dirty.current = value; }} onSaved={() => { dirty.current = false; close(); setRefresh(r => r + 1); setMessage(__('Changes saved.', 'abece-booking')); }} onClose={requestClose}/>} {detail && setRefresh(r => r + 1)} onEdit={edit}/>}
; }