import React from 'react'; import { YStack } from '@tamagui/stacks'; import { SizableText as Text } from '@tamagui/text'; import { MobileSheet } from './Sheet'; import { CTAButton } from './Primitives'; import { useAdminTheme } from '../theme'; type Translator = any; type LegalConsentSheetProps = { open: boolean; onClose: () => void; onConfirm: (consents: { acceptedTerms: boolean; acceptedWaiver: boolean }) => Promise | void; busy?: boolean; requireTerms?: boolean; requireWaiver?: boolean; copy?: { title?: string; description?: string; checkboxTerms?: string; checkboxWaiver?: string; errorTerms?: string; errorWaiver?: string; confirm?: string; cancel?: string; }; t: Translator; }; export function LegalConsentSheet({ open, onClose, onConfirm, busy = false, requireTerms = true, requireWaiver = true, copy, t, }: LegalConsentSheetProps) { const { primary, border, surface, danger, text } = useAdminTheme(); const [acceptedTerms, setAcceptedTerms] = React.useState(false); const [acceptedWaiver, setAcceptedWaiver] = React.useState(false); const [error, setError] = React.useState(null); const checkboxStyle = { marginTop: 4, width: 18, height: 18, accentColor: primary, backgroundColor: surface, border: `1px solid ${border}`, borderRadius: 4, appearance: 'auto', WebkitAppearance: 'auto', } as any; React.useEffect(() => { if (open) { setAcceptedTerms(false); setAcceptedWaiver(false); setError(null); } }, [open]); async function handleConfirm() { if (requireTerms && !acceptedTerms) { setError(copy?.errorTerms ?? t('events.legalConsent.errorTerms', 'Please confirm the terms.')); return; } if (requireWaiver && !acceptedWaiver) { setError(copy?.errorWaiver ?? t('events.legalConsent.errorWaiver', 'Please confirm the waiver.')); return; } setError(null); await onConfirm({ acceptedTerms: requireTerms ? acceptedTerms : true, acceptedWaiver: requireWaiver ? acceptedWaiver : true, }); } return ( {error ? ( {error} ) : null} } > {copy?.description ?? t('events.legalConsent.description', 'Please confirm the legal notes before buying an add-on.')} {requireTerms ? ( ) : null} {requireWaiver ? ( ) : null} ); }