/**
* External dependencies
*/
import PropTypes from 'prop-types';
import { _n, sprintf } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
import Label from '@woocommerce/base-components/label';
import classNames from 'classnames';
import { PanelBody, PanelRow } from 'wordpress-components';
/**
* Internal dependencies
*/
import PackageOptions from './package-options';
import './style.scss';
const Package = ( {
className,
collapsible = false,
noResultsMessage,
onChange,
renderOption,
selected,
shippingRate,
showItems,
title,
} ) => {
const header = (
<>
{ title && (
{ title }
) }
{ showItems && (
{ Object.values( shippingRate.items ).map( ( v ) => {
const name = decodeEntities( v.name );
const quantity = v.quantity;
return (
-
);
} ) }
) }
>
);
const body = (
);
if ( collapsible ) {
return (
{ body }
);
}
return (
{ header }
{ body }
);
};
Package.propTypes = {
onChange: PropTypes.func.isRequired,
renderOption: PropTypes.func.isRequired,
shippingRate: PropTypes.shape( {
shipping_rates: PropTypes.arrayOf( PropTypes.object ).isRequired,
items: PropTypes.arrayOf(
PropTypes.shape( {
name: PropTypes.string.isRequired,
key: PropTypes.string.isRequired,
quantity: PropTypes.number.isRequired,
} ).isRequired
).isRequired,
} ).isRequired,
className: PropTypes.string,
collapsible: PropTypes.bool,
noResultsMessage: PropTypes.string,
selected: PropTypes.string,
showItems: PropTypes.bool,
title: PropTypes.string,
};
export default Package;