import { useState } from 'react'; import { __ } from '@wordpress/i18n'; import { Button, Card, CardBody, Flex, Notice, TextControl, } from '@wordpress/components'; import z from 'zod'; interface IOSSSectionProps { isIOSSEligible: boolean; isValidating: boolean; onSubmitIOSS: (ioss: string | null) => void; } const iossSchema = z .string() .transform((v) => v.replace(/\s+/g, '')) .refine((v) => v === '' || /^\d{12}$/.test(v), { message: 'IOSS must be exactly 12 digits', }); export default function IOSSSection({ isIOSSEligible, isValidating, onSubmitIOSS, }: IOSSSectionProps) { const [ioss, setIoss] = useState(''); const [showIOSSInput, setShowIOSSInput] = useState(false); const [iossResponse, setIossResponse] = useState(''); if (!isIOSSEligible) return null; return ( {showIOSSInput && (

{__( 'If you have an IOSS number, enter it here to simplify VAT collection for your EU shipments only and for parcels less than 150 EUR.', 'parcel2go-shipping' )}

setIoss(value)} placeholder={__( 'Enter your 12-digit IOSS number', 'parcel2go-shipping' )} __nextHasNoMarginBottom />

{__('12-digit number used for EU VAT (IOSS)', 'parcel2go-shipping')}

{iossResponse && ( setIossResponse('')} > {iossResponse} )}
)}
); }