<!--  -->

<?php get_header(); ?>

<?php require get_template_directory() . '/includes/subheader-asiapac.php'; ?>


<div class="container-fluid content-wrapper">
  <div class="row">
    <div class="col-12 page-head">
      <h4>Asia Pacific Events / Advisory</h4>
  </div>

  <div class="row">
    <div class="col-3 sidebar">
      <nav class="nav flex-column">
        <?php wp_nav_menu( array( 'theme_location' => 'asiapac-sidebar' ) ); ?>
      </nav>
    </div>



    <div class="col-9 main-content">





<!-- LOOP START -->
        <h3><?php the_title(); ?></h3>
        <div class="hstack stack-r1 my-3 py-2 border-top border-bottom">
          <div class="p-1">
            <span class="badge bg-warning me-1">Advisory</span>
            <strong>Event ID:</strong> AP-<?php the_ID(); ?>
          </div>
          <div class="p-1"> <strong>Type: </strong>
            <?php $term = get_field('event_type');
                if( $term ): ?>

            <?php echo esc_html( $term->name ); ?><?php endif; ?><strong> Date: </strong> <?php echo esc_html( get_field('event_date') ); ?> </div>

        </div>




            <?php
            $likelihood = get_the_terms( $post->ID , 'risk-likelihood-matrix' );

            foreach ( $likelihood as $term ) {


              echo  '

                <p class="h6">Risk Likelihood: ' . $term->name . ' | Score: ' . $term->description . ' of 5</p><div class="progress mb-3" role="progressbar" aria-label="Default striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
                  <div class="progress-bar progress-bar-striped likelihood-'.$term->term_id.'"></div>
                </div>

                      ';

                  }
            ?>



            <?php
            $consequence = get_the_terms( $post->ID , 'risk-consequence-matrix' );

            foreach ( $consequence as $term ) {


              echo  '

              <p class="h6">Risk Consequence: ' . $term->name . ' | Score: ' . $term->description . ' of 5</p><div class="progress mb-3" role="progressbar" aria-label="Default striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
                  <div class="progress-bar progress-bar-striped consequence-'.$term->term_id.'"></div>
                </div>

                      ';

                  }
            ?>



            <?php
            $consequencetl = get_the_terms( $post->ID , 'risk-consequence-matrix' );
             foreach ( $consequencetl as $term1 ) {

              echo  '';

                  }

                  $likelihoodtl = get_the_terms( $post->ID , 'risk-likelihood-matrix' );
                  foreach ( $likelihoodtl as $term2 ) {

                    echo  '';

                        }



                        function multiplyNums($num1, $num2) {
                            $result = 0;

                            for ($i = 0; $i < $num2; $i++) {
                                $result += $num1;
                            }

                            return $result;
                        }

                        // Driver code
                        $num1 = $term1->description;
                        $num2 = $term2->description;
                        $score = multiplyNums($num1, $num2);

                        echo  '
                        <p class="h6">Overall Risk Score: ' . $score . ' of 25</p><div class="progress mb-3" role="progressbar" aria-label="Default striped example" aria-valuenow="10" aria-valuemin="0" aria-valuemax="100">
                            <div class="progress-bar progress-bar-striped risk-'. $score . '"></div>
                          </div>
                        ';
                        ?>




        <h5>Details</h5>
        <p><?php the_content(); ?></p>

        <h5>Assessment</h5>
        <p><?php echo esc_html( get_field('assessment') ); ?></p>

        <h5>Advice</h5>
        <p><?php echo esc_html( get_field('advice') ); ?></p>


        <h5>Locations</h5>
        <table class="table">
          <thead>
            <tr>
              <th scope="col">Country</div>
              <th scope="col">Place</div>
              <th scope="col">GEO</div>
              <th scope="col">Notes</div>
          </tr>
        </thead>
        <tbody>
        <?php

// Check rows exists.
if( have_rows('ap_locations') ):

    // Loop through rows.
    while( have_rows('ap_locations') ) : the_row();

      $location = get_sub_field('map');
      $title = get_sub_field('title');
      $sub_value4 = get_sub_field('notes');
    ?>
<tr>
  <td>
          <?php
          $country = get_sub_field('country');
          if( $country ): ?>
              <?php echo esc_html( $country->name ); ?>
          <?php endif; ?>

        </td>
        <td><?php echo esc_html( $location['address'] ); ?></td>
        <td><?php echo esc_attr($location['lat']); ?>, <?php echo esc_attr($location['lng']); ?></td>
        <td><?php echo $sub_value4;?></td>
</tr>


<?php endwhile;
// No value.
else :
    echo "<p>Do Nothing</p></div>";
endif;

?>
</tbody>
</table>

<?php if( have_rows('ap_locations') ): ?>
    <div class="acf-map" data-zoom="12">
        <?php while ( have_rows('ap_locations') ) : the_row();

            // Load sub field values.
            $location = get_sub_field('map');
            $title = get_sub_field('title');
            $description = get_sub_field('description');
            ?>
            <div class="marker" data-lat="<?php echo esc_attr($location['lat']); ?>" data-lng="<?php echo esc_attr($location['lng']); ?>">
                <h3><?php echo esc_html( $title ); ?></h3>
                <p><em><?php echo esc_html( $location['address'] ); ?></em></p>
                <p><?php echo esc_html( $description ); ?></p>
            </div>
    <?php endwhile; ?>
    </div>
<?php endif; ?>


<h5 class="mt-3">Impacts</h5>
<table class="table">
  <thead>
    <tr>
      <th scope="col">Country</div>
      <th scope="col">Place</div>
      <th scope="col">GEO</div>
      <th scope="col">Notes</div>
  </tr>
</thead>
<tbody>

<?php

// Check rows exists.
if( have_rows('impacts') ):

// Loop through rows.
while( have_rows('impacts') ) : the_row();

$sub_value22 = get_sub_field('quantity');
$sub_value33 = get_sub_field('details');
?>

<tr>
  <td>
  <?php
  $impact = get_sub_field('type');
  if( $impact ): ?>
      <?php echo esc_html( $impact->name ); ?>
  <?php endif; ?>

</td>
<td>
  <?php echo $sub_value22;?>
</td>
<td>
  <?php echo $sub_value33;?>
</td>
</tr>
<?php endwhile;

// No value.
else :
echo '<tr>
  <td colspan="3">Do Nothing</td></tr>';
endif;

?>

</tbody>
</table>





</div>





      </div>
    </div>
  </div>
</div>





<?php get_footer(); ?>
