var Wick = Wick || {};
Wick.Basket = (function() {
  var $page = $('.page_basket');

  function toggleDeliveryType(radio) {
    $(radio).parents('.order-line').find('[data-collect]').toggleClass('data-collect-hidden', radio.value !== 'collect');
  }

  function init() {
    $('.order-line__update').on('click', function(){
      Wick.Notification.show({
        text: 'Product quantity has been updated.',
        container: '.notification-area',
        type: 'success',
        closeBtn: true
      });
      return false;
    });

    $('.order-line__delete').on('click', function(){
      Wick.Notification.show({
        text: 'Product has been removed from your basket.',
        container: '.notification-area',
        type: 'success',
        closeBtn: true
      });
      return false;
    });

    $('.order-line__delivery-rbn input[type=radio]')
    .on('change', function(){
      toggleDeliveryType(this);
    })
    .each(function(index, radio){
      radio.checked && toggleDeliveryType(radio);
    });

    $('.order-line__delivery-action').on('click', function(){
      $(this).parents('.order-line').find('[data-collect-action]').toggle();
    });
  }

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

  init();
})();
