/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { useShippingData } from '@woocommerce/base-context/hooks';
import {
__experimentalRadio as Radio,
__experimentalRadioGroup as RadioGroup,
} from 'wordpress-components';
import classnames from 'classnames';
import { Icon, store, shipping } from '@wordpress/icons';
import type { CartShippingPackageShippingRate } from '@woocommerce/type-defs/cart';
/**
* Internal dependencies
*/
import './style.scss';
import {
RatePrice,
getLocalPickupStartingPrice,
getShippingStartingPrice,
} from './shared';
const LocalPickupSelector = ( {
checked,
rate,
showPrice,
showIcon,
toggleText,
}: {
checked: string;
rate: CartShippingPackageShippingRate;
showPrice: boolean;
showIcon: boolean;
toggleText: string;
} ) => {
return (
{ showIcon === true && (
) }
{ toggleText }
{ showPrice === true && }
);
};
const ShippingSelector = ( {
checked,
rate,
showPrice,
showIcon,
toggleText,
}: {
checked: string;
rate: CartShippingPackageShippingRate;
showPrice: boolean;
showIcon: boolean;
toggleText: string;
} ) => {
const Price =
rate === undefined ? (
{ __(
'calculated with an address',
'woo-gutenberg-products-block'
) }
) : (
);
return (
{ showIcon === true && (
) }
{ toggleText }
{ showPrice === true && Price }
);
};
const Block = ( {
checked,
onChange,
showPrice,
showIcon,
localPickupText,
shippingText,
}: {
checked: string;
onChange: ( value: string ) => void;
showPrice: boolean;
showIcon: boolean;
localPickupText: string;
shippingText: string;
} ): JSX.Element | null => {
const { shippingRates, needsShipping, hasCalculatedShipping } =
useShippingData();
if ( ! needsShipping || ! hasCalculatedShipping ) {
return null;
}
const localPickupStartingPrice = getLocalPickupStartingPrice(
shippingRates[ 0 ]?.shipping_rates
);
const shippingStartingPrice = getShippingStartingPrice(
shippingRates[ 0 ]?.shipping_rates
);
if ( ! localPickupStartingPrice && ! shippingStartingPrice ) {
return null;
}
return (
);
};
export default Block;