/** * External dependencies */ import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import TextInput from '@woocommerce/base-components/text-input'; import { BillingCountryInput, ShippingCountryInput, } from '@woocommerce/base-components/country-input'; import { BillingStateInput, ShippingStateInput, } from '@woocommerce/base-components/state-input'; import { COUNTRY_LOCALE, DEFAULT_ADDRESS_FIELDS, } from '@woocommerce/block-settings'; export const defaultFieldConfig = { first_name: { autocomplete: 'given-name', }, last_name: { autocomplete: 'family-name', }, company: { autocomplete: 'organization', }, address_1: { autocomplete: 'address-line1', }, address_2: { autocomplete: 'address-line2', }, country: { autocomplete: 'country', priority: 65, required: true, }, city: { autocomplete: 'address-level2', }, postcode: { autocomplete: 'postal-code', }, state: { autocomplete: 'address-level1', }, }; const AddressForm = ( { fields = Object.keys( defaultFieldConfig ), fieldConfig = defaultFieldConfig, onChange, type = 'shipping', values, } ) => { const countryLocale = COUNTRY_LOCALE[ values.country ] || {}; const addressFields = fields.map( ( field ) => ( { key: field, ...DEFAULT_ADDRESS_FIELDS[ field ], ...countryLocale[ field ], ...fieldConfig[ field ], } ) ); const sortedAddressFields = addressFields.sort( ( a, b ) => a.priority - b.priority ); const optionalText = __( '(optional)', 'woo-gutenberg-products-block' ); return (