import {useState, useEffect} from '@wordpress/element'; import {__, sprintf} from '@wordpress/i18n'; import {DateTimePicker} from '@wordpress/components'; import ButtonGroup from '../components/ButtonGroup'; import DateRangePicker from '../components/DateRangePicker'; import {DayPicker} from 'react-day-picker'; import '../scss/_schedule.scss'; const SchedulePeriodField = ( {field, allMetaData, onDataChange} ) => { // Get the saved values. If empty, they are null or undefined. const startDate = allMetaData['start_date']; const endDate = allMetaData['end_date']; const startMode = startDate ? 'scheduled' : 'now'; const endMode = endDate ? 'scheduled' : 'no_end'; const timezoneLabel = window.adpressoData?.timezone || ''; const handleStartModeChange = ( newMode ) => { if ( newMode === 'now' ) { onDataChange( 'start_date', '' ); } else { onDataChange( 'start_date', new Date().toISOString() ); } }; const handleEndModeChange = ( newMode ) => { if ( newMode === 'no_end' ) { onDataChange( 'end_date', '' ); } else { // Initialise with startDate + 1 week, or today when empty const baseDate = startDate ? new Date( startDate ) : new Date(); baseDate.setDate( baseDate.getDate() + 7 ); onDataChange( 'end_date', baseDate.toISOString() ); } }; return (
{/* --- START DATE --- */}
{startMode === 'scheduled' && (
onDataChange( 'start_date', date )} is12Hour={false} // Oder dynamisch basierend auf WP-Settings />
)}
{/* --- END DATE --- */}
{endMode === 'scheduled' && (
onDataChange( 'end_date', date )} is12Hour={false} /> {startDate && endDate && new Date( endDate ) < new Date( startDate ) && (

{__( 'Warning: End date is before start date.', 'adpresso' )}

)}
)}
); }; export default SchedulePeriodField;