function spsWidget(deliveryId, admin = false) {
   $('#cart').on('cartdeliverychange', function(e, data) {
      const inputValue = JSON.parse($(`#sps-parcel-shop-${deliveryId}-data`).val());

      if (data.delivery_id === deliveryId && inputValue.id_point === undefined) {
         setTimeout(function() {
            initializeWidget();
         }, 100);
      }
   });

   $(`[data-sps-parcel-shop-wrapper-${deliveryId}]`).on('click', '[data-btn="open-sps-parcel-shop-widget"]', function() {
      initializeWidget();
      return false;
   });

   function initializeWidget() {
      window.FillBoxMachine3 = selectPoint;
      window.initializeWidget();
   }

   function selectPoint(point) {
      if (point) {
         $(`#sps-parcel-shop-${deliveryId}-data`).val(JSON.stringify(point)).trigger('change');
         if (admin) {
            $('#sps-parcel-shop-name').text(point.description);
         }
      }
   }
}
