<?
if ( is_array( $this -> transports_methods ) )
{
  $transport_found  = false;
  $default_transport_id = false;

  foreach ( $this -> transports_methods as $transport_method )
  {
    if ( $transport_method['id'] == $this -> transport_id )
      $transport_found = true;

    if ( $transport_method['default'] )
      $default_transport_id = $transport_method['id'];
  }

  if ( !$transport_found )
  {
    $this -> transport_id = $default_transport_id;
    \Shared\Helpers\Helpers::set_session( 'basket-transport-method-id', $default_transport_id );
  }
}
?>
<? if ( is_array( $this -> transports_methods ) ): foreach ( $this -> transports_methods as $transport_method ):?>
  <div class="options">
    <div class="check">
      <input type="radio" class="icheck" name="transport_method" value="<?= $transport_method['id'];?>" <? if ( $transport_method['id'] == $this -> transport_id ):?>checked="checked"<? endif;?>>
    </div>
    <div class="description">
      <div><?= $transport_method['name_visible'] != '' ? $transport_method['name_visible'] : $transport_method['name'];?></div>
      <div class="small"><?= $transport_method['description'];?></div>
    </div>
    <div class="price">
      <?= \Shared\Helpers\Helpers::decimal( $transport_method['cost'], 2 );?> zł
    </div>
  </div>
  <? if ( $transport_method['id'] == 1 or $transport_method['id'] == 2 ):?>
    <div class="inpost-info inpost-info-<?= $transport_method['id'];?>">
      <? if ( $transport_method['id'] == $this -> transport_id ):?><?= \Shared\Helpers\Helpers::get_session( 'basket-inpost-info' );?>
        <a href="#" onclick="inpost_map( <?= $transport_method['id'];?> ); return false;"><?= \Shared\Helpers\Helpers::lang( 'wybierz' );?></a>
      <? endif;?>
    </div>
  <? endif;?>
  <? if ( $transport_method['id'] == 9 ):?>
    <div class="orlen-info orlen-info-<?= $transport_method['id'];?>">
      <input type="hidden" name="orlen_point_id" id="orlen_point_id" value="<?= \Shared\Helpers\Helpers::get_session( 'basket_orlen_point_id' );?>">
      <?
        if ( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) != 9 )
          $class = 'hidden';
      ?>
      <span id="orlen_point_info" class="<?= $class;?>"><?= \Shared\Helpers\Helpers::get_session( 'basket_orlen_point_info' );?></span>
      <a href="#" class="orlen-widget <?= $class;?>" data-target="#orlen_point_id"  data-label="#orlen_point_info" data-type="all" data-layout="tabs" onclick="return false;"><?= \Shared\Helpers\Helpers::lang( 'wybierz' );?></a>
    </div>
  <? endif;?>
<? endforeach; endif;?>
<script class="footer" type="text/javascript">
  $( function() {

    <? if ( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ):?>
      transport_checked( <?= \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' );?>, <?= \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) != '' ? \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) : 0;?>, false );
    <? endif;?>

    $( '#transport-methods .icheck' ).iCheck({
      checkboxClass: 'icheckbox_square-blue',
      radioClass: 'iradio_square-blue'
    });

    $( '#transport-methods .icheck' ).on( 'ifChecked', function( event )
    {
      var transport_method_id = $( this ).val();
      transport_checked( transport_method_id, 0, true );
    });
  });
</script>