<script type="text/javascript">
$(function() {
  function toggleInpostField() {
    if ($('#transport_id').val() != '2') {
      $('#inpost_paczkomat').closest('.row').hide();
    } else {
      $('#inpost_paczkomat').closest('.row').show();
    }
  }

  toggleInpostField();

  $('body').on('change', '#transport_id', function() {
    toggleInpostField();
  });

  $('body').on('click', '.btn-paczkomat', function() {
    window.easyPackAsyncInit = function () {
      easyPack.init({
        mapType: 'osm',
        searchType: 'osm',
      });

      easyPack.mapWidget('inpost-map', function(point) {
        $('#inpost_paczkomat').val(point.name + ' | ' + point.address.line1 + ', ' + point.address.line2);
        $('.inpost-map-container').hide();
      });
    };

    $('.inpost-map-container').show();
  });

  $('body').on('click', '#order-save', function(e) {
    e.preventDefault();
    $('#fg-order-details').attr('method', 'POST').attr('action', '/admin/shop_order/order_save/').submit();
  });
});
</script>
