jQuery( document ).ready( function () {

	var states  = JSON.parse( wc_users_params.countries.replace( /&quot;/g, '"' ) );
	var country = jQuery( '#elex-multi-vendor-for-woocommerce-country-vendor' ).val();

	jQuery( '#elex-multi-vendor-for-woocommerce-state-vendor' ).select2( {
		data: states[ country ]
	} );

	jQuery( document ).on( 'change', '#elex-multi-vendor-for-woocommerce-country-vendor', function () {
		var selected = jQuery( '#elex-multi-vendor-for-woocommerce-country-vendor' ).val();
		jQuery( '#elex-multi-vendor-for-woocommerce-state-vendor' ).select2( {
			data: states[ selected ]
		} );
	} );

	var selectedState = elexMvChecklistParams.selected_state;
	var newOption     = new Option( '', selectedState, true, true );
	jQuery( '#elex-multi-vendor-for-woocommerce-state-vendor' ).append( newOption ).trigger( 'change' );

} );
