define([
    'Magento_Checkout/js/model/quote',
    'uiRegistry',
    'Magento_Checkout/js/action/select-shipping-address',
    'Magento_Checkout/js/checkout-data'], 
    function(quote, registry, selectShippingAddress, checkoutData) {
		'use strict';
		var shippingSelector = 'checkout.steps.shipping-step.shippingAddress';
		
		var mixin = {
			initObservable: function () {
				this._super();
				
				if (!quote.isVirtual()) {
	                quote.billingAddress.subscribe(this.billingAddressObserver.bind(this));
	            }
				
				return this;
			},
			
			shippingAddressObserver: function (address) {
	            if (!address) {
	                return;
	            }
	
	            this.isAccountLoggedInAmazon();
	/*MNM - prevent update billing
	            this.setShippingToBilling(address);
	*/
	        },
	        
	//MNM - update shipping with selected billing address if shippingSameAsBilling      
	        billingAddressObserver: function(address) {
	        	if(address != null && typeof registry.get(shippingSelector) !== 'undefined')
	        	{
	        		if(registry.get(shippingSelector).isShippingSameAsBilling()) 
	        		{
	        			selectShippingAddress(address);
	        			checkoutData.setSelectedShippingAddress(address.getKey());
	        		}
	        	}
	        }
		};
		
		return function(target) {
			return target.extend(mixin);
		}
	}
);