import React, { FC } from 'react' import { Spinner, TextControl } from '@wordpress/components' import { Text } from '@wordpress/ui' import { useI18n } from '@wordpress/react-i18n' import HsCodeSelector from './HsCodeSelector' import { ProductNeedingCustomsInfo } from '../customsRules' import { GoodsDescriptionSuggestion } from '../model/models' const GOODS_DESCRIPTION_MAX_LENGTH = 44 export declare interface EnteredForProduct { hsCode?: string sku?: string goodsDescription?: string } export declare interface CustomsProductCardProps { product: ProductNeedingCustomsInfo entered: EnteredForProduct suggestion?: GoodsDescriptionSuggestion loadingSuggestion: boolean sameHsCodeForAll: boolean disabled: boolean onChange: (changes: EnteredForProduct) => void } const CustomsProductCard: FC = ({ product: { item, missingHsCode, missingSku, missingGoodsDescription }, entered, suggestion, loadingSuggestion, sameHsCodeForAll, disabled, onChange, }) => { const { __ } = useI18n() const goodsDescriptionHelp = () => { if (loadingSuggestion) { return ( {__('Suggesting a description…', 'posten-bring-checkout')} ) } switch (suggestion?.status) { case 'SUGGESTED': return __( 'Suggested from the product information. Check it, and edit it if needed.', 'posten-bring-checkout' ) case 'NOT_IDENTIFIED': case 'UNAVAILABLE': return __( 'We could not suggest a description. Please write one in English.', 'posten-bring-checkout' ) default: return __('What the item is, in a few words.', 'posten-bring-checkout') } } return (
{item.name} {item.name}
{missingHsCode && !sameHsCodeForAll && ( onChange({ hsCode: hsCode ?? '' })} /> )} {missingSku && ( onChange({ sku })} /> )} {missingGoodsDescription && ( onChange({ goodsDescription })} /> )}
) } export default CustomsProductCard