function ceskaPostaWidget(deliveryId, type = 'balikovna') {

   function selectPickupPoint(event) {
      if (event.data.message === 'pickerResult' && event.origin === 'https://b2c.cpost.cz') {

         if (!(event.data.point.type === 'BALIKOVNY' && type === 'baliknapostu')) {
            $(`#${type}-${deliveryId}-data`).val(JSON.stringify(event.data.point)).trigger('change');
         }


         $(`#${type}-name`).text(event.data.point.name);
         hideFocus();
      }
   }

   window.addEventListener('message', selectPickupPoint);

   $(`[data-${type}-wrapper]`).on('click', `[data-btn="open-${type}-widget"]`, function() {

      showFocus();

      return false;
   });

   function showFocus() {
      const $modal = $('#ceskaPostaModal');
      const $iframe = $modal.find('iframe').first();
      $iframe.attr('src', $iframe.data('src'));
      $modal.modal('show');
   }

   function hideFocus() {
      $('#ceskaPostaModal').modal('hide');
   }
}
