/**
 * Created by alex on 31/01/2017.
 */

function BillingManager() {
    var self = this;
    var type = "billing";

    self.countryChanged = function( country ) {
        CheckoutPageManager.getCurrencyRate();
        self.country.getCountryStates( country );
        self.country.onCountryChange();

        if( $( '#tax-country-addon' ).length ) {
            var code = country;

            if (EXCEPTION_VAT_COUNTIES[code] !== undefined) {
                code = EXCEPTION_VAT_COUNTIES[code];
            }

            $( '#tax-country-addon' ).text( code );
        }
    };

    self.getCountry = function() {
        return self.country.getCountry();
    };

    self.setCountry = function( country ) {
        return self.country.setCountry( country );
    };

    self.getCountryObject = function() {
        return self.country.getThis();
    };

    self.stateChanged = function( state ) {
        self.country.stateChanged( state );
    };

    self.getState = function() {
        return self.country.getState();
    };

    self.setState = function( state ) {
        return self.country.setState( state);
    };

    self.country = new CountryManager( type, self );

    self.checkShippingSameAsBilling = function() {
        var billingSameAsShipping = self.BillingSameAsShippingElem.is( ":checked" );

        if( billingSameAsShipping ) {
            // Hide billing address
            $( "#shipping-address" ).hide();

            ShippingManager.setCountry( self.country.getCountry() );
        } else {
            // Show billing address
            $( "#shipping-address" ).show();
        }

        try {
            resizeIframeEmbedForm('shipping same as billing');
        } catch(e){
        }
    };

    self.BillingSameAsShippingElem = $( "#shipping-same-as-billing" );
    self.BillingSameAsShippingElem.on( "change", self.checkShippingSameAsBilling );
}
