@fayz-ai/plugin-agenda 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/dist/chunk-DRZF6CV2.js +421 -0
  2. package/dist/chunk-DRZF6CV2.js.map +1 -0
  3. package/dist/chunk-LFUELUIT.cjs +423 -0
  4. package/dist/chunk-LFUELUIT.cjs.map +1 -0
  5. package/dist/data/mock.d.ts.map +1 -1
  6. package/dist/index.cjs +300 -421
  7. package/dist/index.cjs.map +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +297 -420
  10. package/dist/index.js.map +1 -1
  11. package/dist/migrations/index.d.ts +2 -0
  12. package/dist/migrations/index.d.ts.map +1 -0
  13. package/dist/public/BookingWidget.d.ts +11 -0
  14. package/dist/public/BookingWidget.d.ts.map +1 -0
  15. package/dist/public/components/BrandHeader.d.ts +6 -0
  16. package/dist/public/components/BrandHeader.d.ts.map +1 -0
  17. package/dist/public/components/ServiceCard.d.ts +5 -0
  18. package/dist/public/components/ServiceCard.d.ts.map +1 -0
  19. package/dist/public/components/SidebarExtras.d.ts +4 -0
  20. package/dist/public/components/SidebarExtras.d.ts.map +1 -0
  21. package/dist/public/components/StepRailItem.d.ts +4 -0
  22. package/dist/public/components/StepRailItem.d.ts.map +1 -0
  23. package/dist/public/components/SuccessPanel.d.ts +4 -0
  24. package/dist/public/components/SuccessPanel.d.ts.map +1 -0
  25. package/dist/public/components/SummaryRail.d.ts +27 -0
  26. package/dist/public/components/SummaryRail.d.ts.map +1 -0
  27. package/dist/public/components/defaults.d.ts +3 -0
  28. package/dist/public/components/defaults.d.ts.map +1 -0
  29. package/dist/public/context.d.ts +51 -0
  30. package/dist/public/context.d.ts.map +1 -0
  31. package/dist/public/createPublicBookingPlugin.d.ts +62 -0
  32. package/dist/public/createPublicBookingPlugin.d.ts.map +1 -0
  33. package/dist/public/data.d.ts +37 -0
  34. package/dist/public/data.d.ts.map +1 -0
  35. package/dist/public/data.supabase.d.ts +7 -0
  36. package/dist/public/data.supabase.d.ts.map +1 -0
  37. package/dist/public/format.d.ts +18 -0
  38. package/dist/public/format.d.ts.map +1 -0
  39. package/dist/public/hooks.d.ts +34 -0
  40. package/dist/public/hooks.d.ts.map +1 -0
  41. package/dist/public/index.cjs +1423 -0
  42. package/dist/public/index.cjs.map +1 -0
  43. package/dist/public/index.d.ts +20 -0
  44. package/dist/public/index.d.ts.map +1 -0
  45. package/dist/public/index.js +1402 -0
  46. package/dist/public/index.js.map +1 -0
  47. package/dist/public/steps/ContactStep.d.ts +30 -0
  48. package/dist/public/steps/ContactStep.d.ts.map +1 -0
  49. package/dist/public/steps/DateTimeStep.d.ts +23 -0
  50. package/dist/public/steps/DateTimeStep.d.ts.map +1 -0
  51. package/dist/public/steps/OverviewStep.d.ts +16 -0
  52. package/dist/public/steps/OverviewStep.d.ts.map +1 -0
  53. package/dist/public/steps/PaymentStep.d.ts +20 -0
  54. package/dist/public/steps/PaymentStep.d.ts.map +1 -0
  55. package/dist/public/types.d.ts +185 -0
  56. package/dist/public/types.d.ts.map +1 -0
  57. package/package.json +20 -14
  58. package/src/data/mock.ts +4 -1
  59. package/src/index.ts +14 -0
  60. package/src/integrations/google-calendar/integration.test.ts +1 -1
  61. package/src/migrations/001_public_booking.sql +278 -0
  62. package/src/migrations/index.ts +282 -0
  63. package/src/public/BookingWidget.tsx +315 -0
  64. package/src/public/components/BrandHeader.tsx +27 -0
  65. package/src/public/components/ServiceCard.tsx +39 -0
  66. package/src/public/components/SidebarExtras.tsx +30 -0
  67. package/src/public/components/StepRailItem.tsx +27 -0
  68. package/src/public/components/SuccessPanel.tsx +27 -0
  69. package/src/public/components/SummaryRail.tsx +90 -0
  70. package/src/public/components/defaults.ts +14 -0
  71. package/src/public/context.tsx +100 -0
  72. package/src/public/createPublicBookingPlugin.ts +265 -0
  73. package/src/public/data.supabase.ts +94 -0
  74. package/src/public/data.ts +99 -0
  75. package/src/public/format.ts +61 -0
  76. package/src/public/hooks.ts +105 -0
  77. package/src/public/index.ts +68 -0
  78. package/src/public/steps/ContactStep.tsx +179 -0
  79. package/src/public/steps/DateTimeStep.tsx +138 -0
  80. package/src/public/steps/OverviewStep.tsx +81 -0
  81. package/src/public/steps/PaymentStep.tsx +180 -0
  82. package/src/public/types.ts +229 -0
@@ -0,0 +1,99 @@
1
+ // ---------------------------------------------------------------------------
2
+ // PublicBookingDataProvider — the narrow data seam the public booking surface
3
+ // depends on. The admin calendar's 15-method AgendaDataProvider is deliberately
4
+ // NOT used here: a public page needs exactly three capabilities, and the
5
+ // Supabase implementation must be anon-safe (SECURITY DEFINER RPCs + whitelisted
6
+ // views) rather than the authenticated table access the admin provider does.
7
+ // ---------------------------------------------------------------------------
8
+
9
+ import type { TimeSlot } from '../types'
10
+ import { createMockAgendaProvider, type MockAgendaSeed } from '../data/mock'
11
+ import type { PublicService, ContactInfo } from './types'
12
+
13
+ export interface PublicSlotQuery {
14
+ /** Staff person id; null → any active professional for the tenant. */
15
+ assigneeId: string | null
16
+ /** 'YYYY-MM-DD' local calendar day. */
17
+ date: string
18
+ durationMinutes: number
19
+ slotInterval: number
20
+ }
21
+
22
+ export interface PublicCreateBookingInput {
23
+ serviceId: string
24
+ /** ISO datetime of the chosen slot start. */
25
+ startsAt: string
26
+ /** name required; phone should include the country dial for real backends. */
27
+ contact: ContactInfo
28
+ }
29
+
30
+ export interface PublicBookingResult {
31
+ bookingId: string
32
+ startsAt: string
33
+ endsAt: string
34
+ }
35
+
36
+ export interface PublicBookingDataProvider {
37
+ /** Bookable catalog. Used when the host doesn't pass static `services`. */
38
+ getServices(): Promise<PublicService[]>
39
+ getAvailableSlots(query: PublicSlotQuery): Promise<TimeSlot[]>
40
+ createBooking(input: PublicCreateBookingInput): Promise<PublicBookingResult>
41
+ }
42
+
43
+ // ---------------------------------------------------------------------------
44
+ // Mock implementation — adapter over the admin mock provider (reuses its slot
45
+ // algorithm + seed machinery, so mock and live behave identically).
46
+ // ---------------------------------------------------------------------------
47
+
48
+ export interface MockPublicBookingOptions {
49
+ seed: MockAgendaSeed
50
+ services: PublicService[]
51
+ /** The seed professional bookings are created against. */
52
+ professionalId: string
53
+ }
54
+
55
+ export function createMockPublicBookingProvider(options: MockPublicBookingOptions): PublicBookingDataProvider {
56
+ const inner = createMockAgendaProvider({ seed: options.seed })
57
+ const { services, professionalId } = options
58
+
59
+ return {
60
+ async getServices() {
61
+ return services
62
+ },
63
+ async getAvailableSlots(query) {
64
+ return inner.getAvailableSlots({
65
+ assigneeId: query.assigneeId ?? professionalId,
66
+ date: query.date,
67
+ durationMinutes: query.durationMinutes,
68
+ slotInterval: query.slotInterval,
69
+ })
70
+ },
71
+ async createBooking(input) {
72
+ const service = services.find((s) => s.id === input.serviceId)
73
+ if (!service) throw new Error('Serviço inválido')
74
+ const booking = await inner.createBooking({
75
+ kind: 'appointment',
76
+ // Mock: the customer is captured as the booking title; the Supabase
77
+ // path upserts a person record server-side instead.
78
+ clientId: 'public-guest',
79
+ professionalId,
80
+ startsAt: input.startsAt,
81
+ title: input.contact.name,
82
+ notes:
83
+ [input.contact.phone, input.contact.email, input.contact.notes].filter(Boolean).join(' · ') || undefined,
84
+ services: [
85
+ {
86
+ serviceId: service.id,
87
+ name: service.name,
88
+ durationMinutes: service.durationMinutes,
89
+ price: service.price,
90
+ assigneeId: professionalId,
91
+ },
92
+ ],
93
+ })
94
+ const endsAt =
95
+ booking.endsAt ?? new Date(new Date(input.startsAt).getTime() + service.durationMinutes * 60_000).toISOString()
96
+ return { bookingId: booking.id, startsAt: booking.startsAt, endsAt }
97
+ },
98
+ }
99
+ }
@@ -0,0 +1,61 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Date/price formatting + calendar helpers shared by the booking widget and
3
+ // its (host-overridable) subcomponents.
4
+ // ---------------------------------------------------------------------------
5
+
6
+ import { useMemo } from 'react'
7
+ import type { BookingFormatters } from './types'
8
+
9
+ export const DAY_NAMES = ['Domingo', 'Segunda-feira', 'Terça-feira', 'Quarta-feira', 'Quinta-feira', 'Sexta-feira', 'Sábado']
10
+ export const WEEK_ORDER = [1, 2, 3, 4, 5, 6, 0] // Monday-first, like the reference
11
+
12
+ export function useFormatters(locale: string, currency: string): BookingFormatters {
13
+ return useMemo(
14
+ () => ({
15
+ price: new Intl.NumberFormat(locale, { style: 'currency', currency }),
16
+ time: new Intl.DateTimeFormat(locale, { hour: '2-digit', minute: '2-digit' }),
17
+ weekday: new Intl.DateTimeFormat(locale, { weekday: 'short' }),
18
+ dayNum: new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit' }),
19
+ longDay: new Intl.DateTimeFormat(locale, { weekday: 'long', day: '2-digit', month: 'long' }),
20
+ dateShort: new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric' }),
21
+ month: new Intl.DateTimeFormat(locale, { month: 'long', year: 'numeric' }),
22
+ }),
23
+ [locale, currency],
24
+ )
25
+ }
26
+
27
+ /** Local 'YYYY-MM-DD' for a Date. */
28
+ export function toIso(d: Date): string {
29
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
30
+ }
31
+
32
+ /** Read a preselected service id from the URL (?service=…), router-agnostic. */
33
+ export function readServiceParam(): string | null {
34
+ if (typeof window === 'undefined') return null
35
+ return new URLSearchParams(window.location.search).get('service')
36
+ }
37
+
38
+ export interface DayCell {
39
+ iso: string
40
+ date: Date
41
+ isToday: boolean
42
+ }
43
+
44
+ /** 7 consecutive days starting `weekOffset*7` days from today. */
45
+ export function buildWeek(weekOffset: number): DayCell[] {
46
+ const base = new Date()
47
+ base.setHours(0, 0, 0, 0)
48
+ const cells: DayCell[] = []
49
+ for (let i = 0; i < 7; i++) {
50
+ const d = new Date(base.getFullYear(), base.getMonth(), base.getDate() + weekOffset * 7 + i)
51
+ cells.push({ iso: toIso(d), date: d, isToday: weekOffset === 0 && i === 0 })
52
+ }
53
+ return cells
54
+ }
55
+
56
+ /** "13/07/2026 – 21:30 até 22:00 (30min)" */
57
+ export function formatSlotRange(startIso: string, durationMin: number, fmt: BookingFormatters): string {
58
+ const start = new Date(startIso)
59
+ const end = new Date(start.getTime() + durationMin * 60_000)
60
+ return `${fmt.dateShort.format(start)} – ${fmt.time.format(start)} até ${fmt.time.format(end)} (${durationMin}min)`
61
+ }
@@ -0,0 +1,105 @@
1
+ import { useEffect, useState } from 'react'
2
+ import { useBooking } from './context'
3
+ import type { PublicService } from './types'
4
+ import type { PublicCreateBookingInput, PublicBookingResult } from './data'
5
+ import type { TimeSlot } from '../types'
6
+
7
+ /** The resolved bookable services (static option or fetched from the provider). */
8
+ export function useServices(): PublicService[] {
9
+ return useBooking().services
10
+ }
11
+
12
+ export interface UsePublicServicesResult {
13
+ services: PublicService[]
14
+ loading: boolean
15
+ }
16
+
17
+ /** Like useServices, but exposes the fetch state for skeletons. */
18
+ export function usePublicServices(): UsePublicServicesResult {
19
+ const { services, servicesLoading } = useBooking()
20
+ return { services, loading: servicesLoading }
21
+ }
22
+
23
+ export interface UseAvailableSlotsResult {
24
+ slots: TimeSlot[]
25
+ loading: boolean
26
+ error: Error | null
27
+ }
28
+
29
+ /**
30
+ * Available time slots for a service on a given date. Delegates to
31
+ * provider.getAvailableSlots — mock now, Supabase RPC when configured, same call.
32
+ */
33
+ export function useAvailableSlots(params: { serviceId: string | null; date: string | null }): UseAvailableSlotsResult {
34
+ const { provider, professionalId, services, window } = useBooking()
35
+ const [slots, setSlots] = useState<TimeSlot[]>([])
36
+ const [loading, setLoading] = useState(false)
37
+ const [error, setError] = useState<Error | null>(null)
38
+
39
+ const { serviceId, date } = params
40
+ const service = services.find((s) => s.id === serviceId)
41
+ const durationMinutes = service?.durationMinutes ?? 0
42
+
43
+ useEffect(() => {
44
+ let active = true
45
+ if (!serviceId || !date || !durationMinutes) {
46
+ setSlots([])
47
+ return
48
+ }
49
+ setLoading(true)
50
+ provider
51
+ .getAvailableSlots({ assigneeId: professionalId, date, durationMinutes, slotInterval: window.slotInterval })
52
+ .then((result) => {
53
+ if (!active) return
54
+ setSlots(result)
55
+ setError(null)
56
+ })
57
+ .catch((err) => {
58
+ if (!active) return
59
+ setError(err instanceof Error ? err : new Error(String(err)))
60
+ })
61
+ .finally(() => {
62
+ if (active) setLoading(false)
63
+ })
64
+ return () => {
65
+ active = false
66
+ }
67
+ }, [provider, professionalId, serviceId, date, durationMinutes, window.slotInterval])
68
+
69
+ return { slots, loading, error }
70
+ }
71
+
72
+ export type CreatePublicBookingInput = PublicCreateBookingInput
73
+
74
+ export interface UseCreateBookingResult {
75
+ submit: (input: CreatePublicBookingInput) => Promise<PublicBookingResult>
76
+ submitting: boolean
77
+ error: Error | null
78
+ done: boolean
79
+ }
80
+
81
+ /** Create a booking via the provider (mock append / Supabase RPC). */
82
+ export function useCreateBooking(): UseCreateBookingResult {
83
+ const { provider } = useBooking()
84
+ const [submitting, setSubmitting] = useState(false)
85
+ const [error, setError] = useState<Error | null>(null)
86
+ const [done, setDone] = useState(false)
87
+
88
+ async function submit(input: CreatePublicBookingInput): Promise<PublicBookingResult> {
89
+ setSubmitting(true)
90
+ setError(null)
91
+ try {
92
+ const result = await provider.createBooking(input)
93
+ setDone(true)
94
+ return result
95
+ } catch (err) {
96
+ const e = err instanceof Error ? err : new Error(String(err))
97
+ setError(e)
98
+ throw e
99
+ } finally {
100
+ setSubmitting(false)
101
+ }
102
+ }
103
+
104
+ return { submit, submitting, error, done }
105
+ }
@@ -0,0 +1,68 @@
1
+ // ---------------------------------------------------------------------------
2
+ // @fayz-ai/plugin-agenda/public — customer-facing booking surface.
3
+ //
4
+ // Separate entry from the admin plugin so a website host imports only the lean
5
+ // booking widget + data seam (no @fayz-ai/saas / calendar admin graph).
6
+ //
7
+ // Customization levers (cheapest first): `labels` → `brand` → `components`
8
+ // (swap subcomponents; defaults exported below for wrapping/composition).
9
+ // Data: PublicBookingDataProvider — mock seed by default, Supabase RPCs when a
10
+ // global client is configured (requires `tenantId`).
11
+ // ---------------------------------------------------------------------------
12
+
13
+ export { createPublicBookingPlugin } from './createPublicBookingPlugin'
14
+ export type { PublicBookingOptions, PublicBookingPlugin } from './createPublicBookingPlugin'
15
+ export { BookingWidget } from './BookingWidget'
16
+ export { BookingProvider, useBooking } from './context'
17
+ export type { PublicBookingContextValue, OnIdentityVerified } from './context'
18
+ export { useServices, usePublicServices, useAvailableSlots, useCreateBooking } from './hooks'
19
+ export type {
20
+ UsePublicServicesResult,
21
+ UseAvailableSlotsResult,
22
+ UseCreateBookingResult,
23
+ CreatePublicBookingInput,
24
+ } from './hooks'
25
+
26
+ // Data seam
27
+ export type {
28
+ PublicBookingDataProvider,
29
+ PublicSlotQuery,
30
+ PublicCreateBookingInput,
31
+ PublicBookingResult,
32
+ MockPublicBookingOptions,
33
+ } from './data'
34
+ export { createMockPublicBookingProvider } from './data'
35
+ export { createSupabasePublicBookingProvider } from './data.supabase'
36
+ export type { SupabasePublicBookingOptions } from './data.supabase'
37
+
38
+ // Customization seam — default components (wrap or replace via `components`)
39
+ export { DEFAULT_BOOKING_COMPONENTS } from './components/defaults'
40
+ export { DefaultBrandHeader } from './components/BrandHeader'
41
+ export { DefaultServiceCard } from './components/ServiceCard'
42
+ export { DefaultSidebarExtras } from './components/SidebarExtras'
43
+ export { DefaultStepRailItem } from './components/StepRailItem'
44
+ export { DefaultSuccessPanel } from './components/SuccessPanel'
45
+
46
+ // Formatting helpers (useful inside custom components)
47
+ export { useFormatters, formatSlotRange, DAY_NAMES, WEEK_ORDER } from './format'
48
+
49
+ export type {
50
+ PublicService,
51
+ ContactInfo,
52
+ BookingWindow,
53
+ PublicBookingLabels,
54
+ WorkingHours,
55
+ PaymentConfig,
56
+ ResolvedPayment,
57
+ BookingBrand,
58
+ ResolvedBookingBrand,
59
+ BookingHighlight,
60
+ BookingFormatters,
61
+ BookingComponents,
62
+ BrandHeaderProps,
63
+ ServiceCardProps,
64
+ SidebarExtrasProps,
65
+ SuccessPanelProps,
66
+ StepRailItemProps,
67
+ StepState,
68
+ } from './types'
@@ -0,0 +1,179 @@
1
+ import { Check, ChevronDown, CreditCard, Loader2, ShieldCheck } from 'lucide-react'
2
+ import { COUNTRIES, maskPhone, unmaskPhone, type CountryDef } from '@fayz-ai/core'
3
+ import type { PublicBookingLabels, ResolvedPayment } from '../types'
4
+
5
+ export interface ContactDraft {
6
+ name: string
7
+ phone: string
8
+ email: string
9
+ notes: string
10
+ }
11
+
12
+ interface ContactStepProps {
13
+ labels: PublicBookingLabels
14
+ contact: ContactDraft
15
+ onContactChange: (contact: ContactDraft) => void
16
+ contactStep: 'phone' | 'code' | 'details'
17
+ country: CountryDef
18
+ onCountryChange: (iso2: string) => void
19
+ code: string
20
+ onCodeChange: (code: string) => void
21
+ codeError: boolean
22
+ onSendCode: () => void
23
+ onConfirmCode: () => void
24
+ onBackToPhone: () => void
25
+ onSubmitDetails: () => void
26
+ payment: ResolvedPayment | null
27
+ submitting: boolean
28
+ error: Error | null
29
+ }
30
+
31
+ /** Contact step — phone verification first (Quaddro-style), then details. */
32
+ export function ContactStep({
33
+ labels, contact, onContactChange, contactStep, country, onCountryChange,
34
+ code, onCodeChange, codeError, onSendCode, onConfirmCode, onBackToPhone,
35
+ onSubmitDetails, payment, submitting, error,
36
+ }: ContactStepProps) {
37
+ return (
38
+ <div>
39
+ <h3 className="font-heading text-xl font-bold text-foreground">{labels.contactStep}</h3>
40
+
41
+ {/* Sub-step: phone */}
42
+ {contactStep === 'phone' ? (
43
+ <form onSubmit={(e) => { e.preventDefault(); onSendCode() }}>
44
+ <p className="mt-1 text-sm text-muted-foreground">{labels.contactIntro}</p>
45
+ <div className="mt-5">
46
+ <label htmlFor="bk-phone" className="mb-1 block text-sm font-medium text-foreground">{labels.phoneLabel}</label>
47
+ <div className="flex">
48
+ <div className="relative">
49
+ <select
50
+ aria-label="País"
51
+ value={country.iso2}
52
+ onChange={(e) => onCountryChange(e.target.value)}
53
+ className="h-full appearance-none rounded-l-xl border border-r-0 border-border bg-muted py-3 pl-3 pr-8 text-sm font-medium text-foreground outline-none focus-visible:ring-2 focus-visible:ring-ring"
54
+ >
55
+ {COUNTRIES.map((c) => (
56
+ <option key={c.iso2} value={c.iso2}>{c.flag} {c.dial}</option>
57
+ ))}
58
+ </select>
59
+ <ChevronDown className="pointer-events-none absolute right-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
60
+ </div>
61
+ <input
62
+ id="bk-phone" type="tel" autoComplete="tel" inputMode="tel" value={contact.phone}
63
+ onChange={(e) => onContactChange({ ...contact, phone: maskPhone(e.target.value, country.mask) })}
64
+ className="w-full rounded-r-xl border border-border bg-background px-4 py-3 text-foreground outline-none transition-colors focus:border-primary focus-visible:ring-2 focus-visible:ring-ring"
65
+ placeholder={`Ex.: ${maskPhone('11987654321', country.mask)}`}
66
+ />
67
+ </div>
68
+ <p className="mt-2 text-xs text-muted-foreground">{labels.phoneHint}</p>
69
+ </div>
70
+ <button
71
+ type="submit"
72
+ disabled={unmaskPhone(contact.phone).length < 8}
73
+ className="mt-5 w-full rounded-xl bg-primary py-3 font-semibold text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
74
+ >
75
+ {labels.sendCodeCta}
76
+ </button>
77
+ </form>
78
+ ) : null}
79
+
80
+ {/* Sub-step: details (after verification) */}
81
+ {contactStep === 'details' ? (
82
+ <form onSubmit={(e) => { e.preventDefault(); onSubmitDetails() }}>
83
+ <p className="mt-1 text-sm text-muted-foreground">{labels.contactIntro}</p>
84
+ <div className="mt-4 flex items-center justify-between rounded-xl border border-border bg-muted/40 px-4 py-3">
85
+ <span className="flex items-center gap-2 text-sm text-foreground">
86
+ <ShieldCheck className="h-4 w-4 text-primary" /> {labels.phoneVerified} · {country.flag} {country.dial} {contact.phone}
87
+ </span>
88
+ <button
89
+ type="button"
90
+ onClick={onBackToPhone}
91
+ className="rounded text-sm font-medium text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
92
+ >
93
+ {labels.changePhone}
94
+ </button>
95
+ </div>
96
+ <div className="mt-4 space-y-3">
97
+ <div>
98
+ <label htmlFor="bk-name" className="mb-1 block text-sm font-medium text-foreground">{labels.nameLabel}</label>
99
+ <input
100
+ id="bk-name" type="text" autoComplete="name" value={contact.name}
101
+ onChange={(e) => onContactChange({ ...contact, name: e.target.value })}
102
+ className="w-full rounded-xl border border-border bg-background px-4 py-3 text-foreground outline-none transition-colors focus:border-primary focus-visible:ring-2 focus-visible:ring-ring"
103
+ placeholder={labels.namePlaceholder}
104
+ />
105
+ </div>
106
+ <div>
107
+ <label htmlFor="bk-email" className="mb-1 block text-sm font-medium text-foreground">{labels.emailLabel}</label>
108
+ <input
109
+ id="bk-email" type="email" autoComplete="email" inputMode="email" value={contact.email}
110
+ onChange={(e) => onContactChange({ ...contact, email: e.target.value })}
111
+ className="w-full rounded-xl border border-border bg-background px-4 py-3 text-foreground outline-none transition-colors focus:border-primary focus-visible:ring-2 focus-visible:ring-ring"
112
+ placeholder={labels.emailPlaceholder}
113
+ />
114
+ <p className="mt-1 text-xs text-muted-foreground">{labels.emailHint}</p>
115
+ </div>
116
+ <div>
117
+ <label htmlFor="bk-notes" className="mb-1 block text-sm font-medium text-foreground">{labels.notesLabel}</label>
118
+ <textarea
119
+ id="bk-notes" rows={3} value={contact.notes}
120
+ onChange={(e) => onContactChange({ ...contact, notes: e.target.value })}
121
+ className="w-full resize-none rounded-xl border border-border bg-background px-4 py-3 text-foreground outline-none transition-colors focus:border-primary focus-visible:ring-2 focus-visible:ring-ring"
122
+ placeholder={labels.notesPlaceholder}
123
+ />
124
+ </div>
125
+ </div>
126
+ {error ? (
127
+ <p role="alert" className="mt-3 text-sm text-destructive">{labels.submitError}</p>
128
+ ) : null}
129
+ <button
130
+ type="submit"
131
+ disabled={!contact.name.trim() || submitting}
132
+ className="mt-5 flex w-full items-center justify-center gap-2 rounded-xl bg-primary py-3 font-semibold text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
133
+ >
134
+ {submitting ? <Loader2 className="h-4 w-4 animate-spin" /> : <Check className="h-4 w-4" />}
135
+ {payment ? labels.saveAndContinueCta : labels.confirmCta}
136
+ </button>
137
+ {!payment ? (
138
+ <p className="mt-3 flex items-center justify-center gap-1.5 text-xs text-muted-foreground">
139
+ <CreditCard className="h-3.5 w-3.5" /> {labels.noChargeNote}
140
+ </p>
141
+ ) : null}
142
+ </form>
143
+ ) : null}
144
+
145
+ {/* Code verification modal */}
146
+ {contactStep === 'code' ? (
147
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-foreground/40 p-4" role="dialog" aria-modal="true" aria-label={labels.codeTitle}>
148
+ <div className="w-full max-w-md rounded-2xl border border-border bg-card p-6 shadow-xl">
149
+ <h4 className="font-heading text-lg font-bold text-foreground">{labels.codeTitle}</h4>
150
+ <p className="mt-1 text-sm text-muted-foreground">{labels.codeBody}</p>
151
+ <form onSubmit={(e) => { e.preventDefault(); onConfirmCode() }}>
152
+ <input
153
+ type="text" inputMode="numeric" value={code} autoFocus
154
+ onChange={(e) => onCodeChange(e.target.value)}
155
+ className="mt-4 w-full rounded-xl border border-border bg-background px-4 py-3 text-center text-lg tracking-[0.4em] text-foreground outline-none transition-colors focus:border-primary focus-visible:ring-2 focus-visible:ring-ring placeholder:text-sm placeholder:tracking-normal"
156
+ placeholder="Digite o código"
157
+ />
158
+ {codeError ? (
159
+ <p role="alert" className="mt-2 text-sm text-destructive">{labels.codeInvalid}</p>
160
+ ) : null}
161
+ <button
162
+ type="submit"
163
+ className="mt-4 w-full rounded-xl bg-primary py-3 font-semibold text-primary-foreground transition-opacity hover:opacity-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
164
+ >
165
+ {labels.codeConfirmCta}
166
+ </button>
167
+ </form>
168
+ <div className="mt-3 flex items-center justify-between text-xs text-muted-foreground">
169
+ <span>{labels.codeResendHint}</span>
170
+ <button type="button" onClick={onBackToPhone} className="font-medium text-primary hover:underline">
171
+ {labels.back}
172
+ </button>
173
+ </div>
174
+ </div>
175
+ </div>
176
+ ) : null}
177
+ </div>
178
+ )
179
+ }
@@ -0,0 +1,138 @@
1
+ import { ChevronLeft, ChevronRight, Clock } from 'lucide-react'
2
+ import type { TimeSlot } from '../../types'
3
+ import type { DayCell } from '../format'
4
+ import type { BookingFormatters, PublicBookingLabels, WorkingHours } from '../types'
5
+
6
+ interface DateTimeStepProps {
7
+ labels: PublicBookingLabels
8
+ fmt: BookingFormatters
9
+ week: DayCell[]
10
+ weekOffset: number
11
+ maxWeekOffset: number
12
+ onWeekOffset: (updater: (w: number) => number) => void
13
+ businessHours: WorkingHours
14
+ date: string | null
15
+ onSelectDate: (iso: string) => void
16
+ slots: TimeSlot[]
17
+ slotsLoading: boolean
18
+ slotStart: string | null
19
+ onSelectSlot: (startIso: string) => void
20
+ onContinue: () => void
21
+ }
22
+
23
+ /** Week strip + available-slot grid. */
24
+ export function DateTimeStep({
25
+ labels, fmt, week, weekOffset, maxWeekOffset, onWeekOffset, businessHours,
26
+ date, onSelectDate, slots, slotsLoading, slotStart, onSelectSlot, onContinue,
27
+ }: DateTimeStepProps) {
28
+ const openDays = new Set(businessHours.daysOfWeek)
29
+ return (
30
+ <div>
31
+ <div className="flex flex-wrap items-baseline justify-between gap-2">
32
+ <h3 className="font-heading text-xl font-bold text-foreground">{labels.dateStep}</h3>
33
+ <span className="flex items-center gap-1 text-xs text-muted-foreground">
34
+ <Clock className="h-3.5 w-3.5" /> {labels.timezoneNote}
35
+ </span>
36
+ </div>
37
+
38
+ <div className="mt-5 flex items-center justify-between">
39
+ <span className="text-sm font-semibold capitalize text-foreground">{fmt.month.format(week[0].date)}</span>
40
+ <div className="flex items-center gap-1">
41
+ <button
42
+ type="button"
43
+ disabled={weekOffset === 0}
44
+ onClick={() => onWeekOffset((w) => Math.max(0, w - 1))}
45
+ className="flex h-9 w-9 items-center justify-center rounded-lg border border-border text-foreground transition-colors hover:bg-accent disabled:opacity-40 disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
46
+ aria-label={labels.prevWeek}
47
+ >
48
+ <ChevronLeft className="h-4 w-4" />
49
+ </button>
50
+ <button
51
+ type="button"
52
+ disabled={weekOffset >= maxWeekOffset}
53
+ onClick={() => onWeekOffset((w) => Math.min(maxWeekOffset, w + 1))}
54
+ className="flex h-9 w-9 items-center justify-center rounded-lg border border-border text-foreground transition-colors hover:bg-accent disabled:opacity-40 disabled:hover:bg-transparent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
55
+ aria-label={labels.nextWeek}
56
+ >
57
+ <ChevronRight className="h-4 w-4" />
58
+ </button>
59
+ </div>
60
+ </div>
61
+
62
+ <div className="mt-3 grid grid-cols-7 gap-1.5">
63
+ {week.map((d) => {
64
+ const selected = date === d.iso
65
+ const closed = !openDays.has(d.date.getDay())
66
+ return (
67
+ <button
68
+ key={d.iso}
69
+ type="button"
70
+ disabled={closed}
71
+ onClick={() => onSelectDate(d.iso)}
72
+ className={[
73
+ 'flex flex-col items-center gap-0.5 rounded-xl border py-2.5 transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
74
+ closed
75
+ ? 'cursor-not-allowed border-transparent text-muted-foreground/40'
76
+ : selected
77
+ ? 'border-primary bg-primary text-primary-foreground'
78
+ : 'border-border text-foreground hover:border-primary/60 hover:bg-accent/40',
79
+ ].join(' ')}
80
+ >
81
+ <span className="text-[11px] font-medium capitalize opacity-80">
82
+ {fmt.weekday.format(d.date).replace('.', '')}
83
+ </span>
84
+ <span className="text-sm font-bold tabular-nums">{fmt.dayNum.format(d.date)}</span>
85
+ </button>
86
+ )
87
+ })}
88
+ </div>
89
+
90
+ {date ? (
91
+ <div className="mt-6">
92
+ <p className="mb-2 text-sm font-semibold text-foreground">{labels.slotsHeading}</p>
93
+ {slotsLoading ? (
94
+ <div className="grid grid-cols-3 gap-2 sm:grid-cols-4">
95
+ {Array.from({ length: 8 }).map((_, i) => (
96
+ <div key={i} className="h-10 animate-pulse rounded-lg bg-muted" />
97
+ ))}
98
+ </div>
99
+ ) : slots.length === 0 ? (
100
+ <div className="rounded-xl border border-dashed border-border p-6 text-center text-sm text-muted-foreground">
101
+ {labels.noSlots}
102
+ </div>
103
+ ) : (
104
+ <div className="grid grid-cols-3 gap-2 sm:grid-cols-4">
105
+ {slots.map((s) => {
106
+ const selected = slotStart === s.start
107
+ return (
108
+ <button
109
+ key={s.start}
110
+ type="button"
111
+ onClick={() => onSelectSlot(s.start)}
112
+ className={[
113
+ 'rounded-lg border py-2.5 text-sm font-semibold tabular-nums transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring',
114
+ selected
115
+ ? 'border-primary bg-primary text-primary-foreground'
116
+ : 'border-border text-foreground hover:border-primary/60 hover:bg-accent/40',
117
+ ].join(' ')}
118
+ >
119
+ {fmt.time.format(new Date(s.start))}
120
+ </button>
121
+ )
122
+ })}
123
+ </div>
124
+ )}
125
+ </div>
126
+ ) : null}
127
+
128
+ <button
129
+ type="button"
130
+ disabled={!slotStart}
131
+ onClick={onContinue}
132
+ className="mt-6 w-full rounded-xl bg-primary py-3 font-semibold text-primary-foreground transition-opacity hover:opacity-90 disabled:opacity-40 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
133
+ >
134
+ {labels.continueCta}
135
+ </button>
136
+ </div>
137
+ )
138
+ }