var Wick = Wick || {};
Wick.CheckoutDeliveryAddress = (function() {
  var $page = $('.page_checkout-delivery-address');

  function bindEvents(){
    $('.btn-new-address').on('click', function(){
      $('[data-new-address]').show();
      $('[data-addresses]').hide();
      $('.btn-new-address').hide();

      if (Wick.Responsive.getCurrentBreakpoint() === 'down-sm') {
        $('html, body').animate({
          scrollTop: $('[data-new-address]').offset().top - 15
        }, 700);
      }

      return false;
    });

    $('.btn-back-to-addresses').on('click', function(){
      $('[data-new-address]').hide();
      $('[data-addresses]').show();
      $('.btn-new-address').show();
      return false;
    });

    $('.btn-delivery-details').on('click', function(){
      var $form = $('#form-checkout-your-details');
      if ($form.is(':visible')){
        $form.submit();
        return false;
      }
    });
  }

  if(!$page.length){
    return;
  }

  bindEvents();
})();
