import clsx from 'clsx'; import { useAppSelector } from '@akinon/next/redux/hooks'; import { RootState } from '@theme/redux/store'; import { useSetPaymentOptionMutation } from '@akinon/next/data/client/checkout'; import { CheckoutPaymentOption } from '@akinon/next/types'; import { Radio } from '@theme/components'; import { partAttrs } from '@akinon/pz-theme/src/utils/part-styles'; import { usePaymentOptions } from '@akinon/next/hooks/use-payment-options'; import { useMemo } from 'react'; const PaymentOptionButtons = () => { const { preOrder, attributeBasedShippingOptions } = useAppSelector( (state: RootState) => state.checkout ); const [setPaymentOption] = useSetPaymentOptionMutation(); const { filteredPaymentOptions } = usePaymentOptions(); const onClickHandler = (option: CheckoutPaymentOption) => { setPaymentOption(option.pk); }; const scrollToTop = () => { window.scrollTo({ top: 0, behavior: 'smooth' }); }; const displayedPaymentOptions = useMemo(() => { if ( attributeBasedShippingOptions && Object.keys(attributeBasedShippingOptions).length > 0 ) { return filteredPaymentOptions.filter( (option) => option.slug.toLowerCase() !== 'pay-on-delivery' ); } return filteredPaymentOptions; }, [filteredPaymentOptions, attributeBasedShippingOptions]); return ( <>
{displayedPaymentOptions.map((option) => ( // The mobile radio row's typography sits on the
{displayedPaymentOptions.map((option) => ( ))}
); }; export default PaymentOptionButtons;