<?php
/**
 * Template Name: Jobs Page Template
 * Template Post Type: page
 *
 * @package thehoot
 */

get_header(); ?>

  <div id="primary">
    <div class="row">
      <div class="col-12 col-md-8">

    <?php
  $jobs_page_title = get_field('job_page_title');
    $jobs_page_content = get_field('job_page_content');
    if ($jobs_page_title) : ?>

      <h1><?php echo esc_html($jobs_page_title); ?></h1>

      <?php endif; ?>
        <?php
        if ($jobs_page_content) : ?>
        <div class="mt-4">

          <?php echo wp_kses_post($jobs_page_content); ?>

          </div>

            <?php endif; ?>



                        <?php
                  $featured_posts = get_field('showcase_a_job');
                  if ($featured_posts): ?>

                          <?php foreach ($featured_posts as $post):

                        $showcase_employer_name = get_field('employer_name');
                          $showcase_job_rate = get_field('job_rate');
                            $showcase_job_description = get_field('job_description');
                            $showcase_job_location = get_field('job_location');
                            $showcase_job_link = get_field('job_apply_link');
                            $showcase_job_logo = get_field('job_logo');

                            setup_postdata($post); ?>

                              <div class="showcase mt-4 relative">

                            <?php if ( $showcase_job_logo ) : ?>

                              <img class="job-logo" src="<?php echo esc_url($showcase_job_logo['url']); ?>" alt="<?php echo esc_attr($showcase_job_logo['alt']); ?>">

                              <?php endif; ?>

                            <h3><?php the_title(); ?></h3>

                            <p>
                              <?php echo esc_html($showcase_employer_name);?>
                            </p>

                            <p>
                              <?php echo esc_html($showcase_job_location);?>
                            </p>

                            <p><strong><?php echo esc_html($showcase_job_rate);?></strong></p>

                            <?php echo wp_kses_post($showcase_job_description);?>

                              <?php if ($showcase_job_link) : ?>

                                <a style="text-decoration:underline" class="btn btn-black w-100 text-black" href="<?php echo $showcase_job_link['url']; ?>" target="<?php echo $showcase_job_link['target']; ?>">

                                  <?php echo $showcase_job_link['title']; ?>

                                </a>

                                <?php endif ; ?>

                                  </div>

                                  <?php endforeach; ?>

                                    <?php

                      wp_reset_postdata(); ?>
                                      <?php endif; ?>


                </div>

                <div class="col-12 col-md-4">
                  <?php

  $args = array(
    'post_type'=>'job-listing',
    'posts_per_page' => -1,
  );

  $loop = new WP_Query($args);
  if ($loop->have_posts()) {
      while ($loop->have_posts()) : $loop->the_post();
      $employer_name = get_field('employer_name');
      $job_rate = get_field('job_rate');
      $job_description = get_field('job_description');
      $job_location = get_field('job_location');
      $job_link = get_field('job_apply_link'); ?>

                  <div class="job-listing">

                        <h2><?php echo(get_the_title()); ?></h2>

                        <p class="cs-entry__title-line"><span><?php echo esc_html($employer_name); ?></span></p>

                        <p>
                          <?php echo esc_html($job_location); ?>
                        </p>

                        <p><strong><?php echo esc_html($job_rate); ?></strong></p>

                        <?php echo wp_kses_post(mb_strimwidth($job_description, 0, 100, )); ?>...



                          <!-- Modal -->
                          <div class="modal fade" id="ex<?php the_ID(); ?>" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
                            <div class="modal-dialog modal-xl">
                              <div class="modal-content">
                                <div class="modal-header">
                                  <h5 class="modal-title" id="exampleModalLabel"><?php echo  esc_html(get_the_title()); ?></h5>
                                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                                </div>
                                <div class="modal-body">
                                  <h2><?php echo  esc_html(get_the_title()); ?></h2>

                                  <p>
                                    <?php echo esc_html($employer_name); ?>
                                  </p>

                                  <p>
                                    <?php echo esc_html($job_location); ?>
                                  </p>

                                  <p><strong><?php echo esc_html($job_rate); ?></strong></p>

                                  <?php echo wp_kses_post($job_description); ?>

                                    <?php if ($job_link) : ?>

                                      <a class="apply-link" href="<?php echo $job_link['url']; ?>" target="<?php echo $job_link['target']; ?>">

                                        <?php echo $job_link['title']; ?>

                                      </a>
                                      <?php endif ; ?>
                                </div>
                                <div class="modal-footer">
                                  <button type="button" class="btn btn-yellow" data-bs-dismiss="modal">Close</button>
                                </div>
                              </div>
                            </div>
                          </div>

                          <!-- Button trigger modal -->
                            <button type="button" class="btn btn-yellow my-3" data-bs-toggle="modal" data-bs-target="#ex<?php the_ID(); ?>">
                              Find Out More
                            </button>

                          <p class="small">Posted -

                            <?php echo get_the_date('H:i - d/m/Y'); ?>

                          </p>
                      </div>

                    <?php  endwhile;
  }
       wp_reset_postdata();
       ?>
                </div>

              </div>
  </div>



  <?php get_footer(); ?>
