import * as React from 'react'; import { __ } from '@wordpress/i18n'; import type { Config } from './types'; type Step = { key: string; label: string; status: string; url: string | null; }; type Start = { steps: Step[]; page_state: string; booking_url: string | null; dismissed: boolean; }; type Health = { checks: { key: string; label: string; status: string; value: string; }[]; report: string; }; const statusLabels: Record = { ok: __('OK', 'abece-booking'), warning: __('Warning', 'abece-booking'), error: __('Error', 'abece-booking'), info: __('Info', 'abece-booking'), optional: __('Optional', 'abece-booking') }; const pageLabels: Record = { ready: __('Booking page is ready.', 'abece-booking'), missing: __('No booking page is selected.', 'abece-booking'), deleted: __('The selected booking page was deleted.', 'abece-booking'), unpublished: __('The selected booking page is not published.', 'abece-booking'), shortcode_missing: __('The booking page does not contain the booking shortcode.', 'abece-booking') }; export function PilotToolsApp({ config }: { config: Config; }) { const [start, setStart] = React.useState(null), [health, setHealth] = React.useState(null), [error, setError] = React.useState(''), [notice, setNotice] = React.useState(''), [busy, setBusy] = React.useState(false), [recipient, setRecipient] = React.useState(''), [confirmation, setConfirmation] = React.useState(''), [showReport, setShowReport] = React.useState(false); const system = config.page === 'system-status'; async function request(path: string, method = 'GET', body?: unknown) { const url = new URL(config.restUrl + 'admin/tools/' + path); url.searchParams.set('_locale', 'user'); const response = await fetch(url, { method, headers: { 'X-WP-Nonce': config.nonce, 'Content-Type': 'application/json' }, ...(body !== undefined ? { body: JSON.stringify(body) } : {}) }); const data = await response.json(); if (!response.ok) throw new Error(data.message || __('The request could not be completed.', 'abece-booking')); return data; } async function load() { setError(''); try { if (system) setHealth(await request('status')); else setStart(await request('onboarding')); } catch (e) { setError((e as Error).message); } } React.useEffect(() => { void load(); }, [system]); async function action(operation: () => Promise) { setError(''); setNotice(''); setBusy(true); try { await operation(); } catch (e) { setError((e as Error).message); } finally { setBusy(false); } } return

{system ? __('System Status', 'abece-booking') : __('Getting Started', 'abece-booking')}

{error &&

{error}

}{notice &&

{notice}

} {!system && start && <>

{__('Follow these steps to prepare your venue. Nothing creates sample bookings or accounts automatically.', 'abece-booking')}

{start.dismissed &&

{__('You marked this checklist as complete. You can still review every step.', 'abece-booking')}

}
    {start.steps.map(step =>
  1. {step.status === 'ok' ? '✓' : step.status === 'warning' ? '⚠' : '○'} {statusLabels[step.status]}{step.label}{step.url && {__('Go to step', 'abece-booking')}}
  2. )}

{__('Booking page', 'abece-booking')}

{pageLabels[start.page_state]}

{__('Use an existing published page with [abece_booking], or explicitly create one. An existing booking page will be reused.', 'abece-booking')}

} {system && health && <>

{__('Status checks do not repair or change your data. The support report excludes customer data, credentials and full bank details.', 'abece-booking')}

{showReport &&