/** * External dependencies */ import classNames from 'classnames'; import { _n, sprintf } from '@wordpress/i18n'; import { decodeEntities } from '@wordpress/html-entities'; import Label from '@woocommerce/base-components/label'; import Title from '@woocommerce/base-components/title'; import type { ReactElement } from 'react'; import type { Rate, PackageRateOption } from '@woocommerce/type-defs/shipping'; import { Panel } from '@woocommerce/blocks-checkout'; import { useSelectShippingRate } from '@woocommerce/base-context/hooks'; /** * Internal dependencies */ import PackageRates from './package-rates'; import './style.scss'; interface PackageItem { name: string; key: string; quantity: number; } interface Destination { // eslint-disable-next-line camelcase address_1: string; // eslint-disable-next-line camelcase address_2: string; city: string; state: string; postcode: string; country: string; } interface PackageProps { packageId: string; renderOption: ( option: Rate ) => PackageRateOption; collapse: boolean; packageData: { destination: Destination; name: string; // eslint-disable-next-line camelcase shipping_rates: Rate[]; items: PackageItem[]; }; className?: string; collapsible?: boolean; noResultsMessage: ReactElement; showItems: boolean; } export const ShippingRatesControlPackage = ( { packageId, className, noResultsMessage, renderOption, packageData, collapsible = false, collapse = false, showItems = false, }: PackageProps ): ReactElement => { const { selectShippingRate, selectedShippingRate } = useSelectShippingRate( packageId, packageData.shipping_rates ); const header = ( <> { ( showItems || collapsible ) && (