import React, { useEffect } from 'react';

const AMAZON_ADDRESS_BOOK_DIV_ID = 'addressBookWidgetDiv';

export const AddressBook = (props: any) => {
  const { sellerId, agreementType, onAddressSelect, onReady, onError, setOro } = props;

  useEffect(() => {
    // @ts-ignore
    new window.OffAmazonPayments.Widgets.AddressBook({
      onReady: onReady,
      onAddressSelect: onAddressSelect,
      onError: onError,
      sellerId,
      agreementType,
      onOrderReferenceCreate: function(orderReference: any) {
        setOro(orderReference.getAmazonOrderReferenceId());
      },
      design:                 {
        designMode: 'responsive',
      },
    }).bind(AMAZON_ADDRESS_BOOK_DIV_ID);
  }, [])

  return (
      <div
          style={{
            height: 228,
            display: 'none'
          }}
          id={AMAZON_ADDRESS_BOOK_DIV_ID}
      />
  )
}
