import { __ } from '@wordpress/i18n'; import type { Field } from './fields'; import type { SchedulePage } from './types'; export const weekdays: [ string, string ][] = [ ['1', __('Monday', 'abece-booking')], ['2', __('Tuesday', 'abece-booking')], ['3', __('Wednesday', 'abece-booking')], ['4', __('Thursday', 'abece-booking')], ['5', __('Friday', 'abece-booking')], ['6', __('Saturday', 'abece-booking')], ['7', __('Sunday', 'abece-booking')], ]; export const blockTypes: [ string, string ][] = [ ['maintenance', __('Maintenance', 'abece-booking')], ['tournament', __('Tournament', 'abece-booking')], ['club_event', __('Club event', 'abece-booking')], ['weather', __('Weather', 'abece-booking')], ['private', __('Private', 'abece-booking')], ['other', __('Other', 'abece-booking')], ]; export const scheduleLabels = { 'opening-hours': { title: __('Opening hours', 'abece-booking'), add: __('Add opening hours', 'abece-booking'), create: __('Create opening hours', 'abece-booking'), edit: __('Edit opening hours', 'abece-booking') }, 'schedule-exceptions': { title: __('Operating exceptions', 'abece-booking'), add: __('Add exception', 'abece-booking'), create: __('Create exception', 'abece-booking'), edit: __('Edit exception', 'abece-booking') }, 'resource-blocks': { title: __('Resource blocks', 'abece-booking'), add: __('Add block', 'abece-booking'), create: __('Create block', 'abece-booking'), edit: __('Edit block', 'abece-booking') }, }; export function scheduleFields(kind: SchedulePage): Field[] { const resource: Field = { key: 'resource_id', label: __('Resource', 'abece-booking'), type: 'select', nullable: kind !== 'resource-blocks', required: kind === 'resource-blocks' }; const times: Field[] = [{ key: 'opens_at', label: __('Opens at', 'abece-booking'), type: 'time', nullable: true }, { key: 'closes_at', label: __('Closes at', 'abece-booking'), type: 'time', nullable: true }]; const title: Field = { key: 'public_title', label: __('Title for customers', 'abece-booking'), type: 'text', nullable: true, maxLength: 190 }; if (kind === 'resource-blocks') return [resource, title, { key: 'starts_at', label: __('Starts at', 'abece-booking'), type: 'datetime-local', required: true }, { key: 'ends_at', label: __('Ends at', 'abece-booking'), type: 'datetime-local', required: true }, { key: 'block_type', label: __('Block type', 'abece-booking'), type: 'select', options: blockTypes }, { key: 'reason', label: __('Internal reason', 'abece-booking'), type: 'text', nullable: true, maxLength: 255 }, { key: 'note', label: __('Internal note', 'abece-booking'), type: 'textarea', nullable: true }, ]; const closed: Field = { key: 'is_closed', label: __('Closed', 'abece-booking'), type: 'checkbox' }; if (kind === 'schedule-exceptions') return [resource, title, { key: 'exception_date', label: __('Date', 'abece-booking'), type: 'date', required: true }, closed, ...times, { key: 'reason', label: __('Internal reason', 'abece-booking'), type: 'text', nullable: true, maxLength: 255 }, { key: 'note', label: __('Internal note', 'abece-booking'), type: 'textarea', nullable: true }]; return [resource, { key: 'day_of_week', label: __('Day of week', 'abece-booking'), type: 'select', options: weekdays }, closed, { key: 'opening_mode', label: __('Opening mode', 'abece-booking'), type: 'select', options: [['fixed', __('Fixed', 'abece-booking')], ['sun', __('Sun-based', 'abece-booking')]] }, ...times, { key: 'sunrise_offset_minutes', label: __('Sunrise offset (minutes)', 'abece-booking'), type: 'number', nullable: true, min: -32768 }, { key: 'sunset_offset_minutes', label: __('Sunset offset (minutes)', 'abece-booking'), type: 'number', nullable: true, min: -32768 }, { key: 'min_open_time', label: __('Earliest opening time', 'abece-booking'), type: 'time', nullable: true }, { key: 'max_close_time', label: __('Latest closing time', 'abece-booking'), type: 'time', nullable: true }, ]; }