<?php get_header('employment'); ?>
<main>
    <?php include('template/bottom-internship.php'); ?>
    <?php include('template/breadcrumb.php'); ?>
    <section class="p-internship">
        <div class="p-internship__heading">
            <div class="p-internship__inner l-inner">
                <?php
                if(have_rows('section01', 23)) :
                while (have_rows('section01', 23)) : the_row();
                ?>
                    <p class="p-internship__entitle c-entitle"><?php the_sub_field('section01-entitle'); ?></p>
                    <h2 class="p-internship__title c-title"><?php the_sub_field('section01-title'); ?></h2>
                    <div class="p-internship__swiper swiper js-internshipSwiper">
                        <div class="swiper-wrapper">
                            <?php if (get_sub_field('section01-imgs')) : ?>
                                <?php
                                $group = get_sub_field('section01-imgs');
                                if ($group) :
                                    foreach ($group as $field) {
                                        $acf_row_image = $field['section01-img'];
                                        $url = $acf_row_image['url'];
                                        $alt = $acf_row_image['alt'];
                                        if ($url) :
                                        ?>
                                            <div class="swiper-slide">
                                                <div class="p-internship__img c-img">
                                                    <img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>">
                                                </div>
                                            </div>
                                        <?php
                                        endif;
                                    }
                                endif;
                                ?>
                            <?php endif; ?>
                        </div>
                        <div class="swiper-pagination internship-swiper-pagination"></div>
                    </div>
                    <p class="p-internship__description c-text"><?php the_sub_field('section01-text'); ?></p>
                <?php
                endwhile;
                endif;
                ?>
            </div>
        </div>
        <?php
        $the_query = new WP_Query();
        $param = array(
            'post_type'      => 'internship',
            'posts_per_page' => '-1',
            'post_status'    => 'publish',
        );
        $the_query->query($param);
        if ($the_query->have_posts()) :
        ?>
            <div class="p-internship__program">
                <div class="p-internship__inner l-inner">
                    <p class="p-internship__entitle c-entitle">program</p>
                    <h2 class="p-internship__title c-title">募集コース</h2>
                    <div class="p-internship__course">
                        <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
                            <a href="<?php the_permalink(); ?>" class="p-internship__item p-internshipItem">
                                <div class="p-internshipItem__img c-img">
                                    <?php
                                    if (has_post_thumbnail()) :
                                        the_post_thumbnail('post-thumbnail', array('alt' => the_title_attribute('echo=0')));
                                    else :
                                        echo '<img src="'.get_template_directory_uri().'/images/common/noimage.jpg" alt="'.esc_html(get_the_title()).'">';
                                    endif; ?>
                                </div>
                                <div class="p-internshipItem__body">
                                    <?php if (have_rows('internship-introduction')) : ?>
                                        <?php while (have_rows('internship-introduction')) : the_row(); ?>
                                            <p class="p-internshipItem__course"><?php the_title(); ?></p>
                                            <p class="p-internshipItem__theme"><?php the_sub_field('internship-introduction-title'); ?></p>
                                        <?php endwhile; ?>
                                    <?php endif; ?>
                                    <div class="p-internshipItem__lists">
                                        <?php if(get_field('course-text')) : ?>
                                            <div class="p-internshipItem__list">
                                                <p>■コース</p>
                                                <p><?php echo the_field('course-text'); ?></p>
                                            </div>
                                        <?php endif; ?>
                                        <?php if(get_field('target-text')) : ?>
                                            <div class="p-internshipItem__list">
                                                <p>■対象者</p>
                                                <p><?php echo the_field('target-text'); ?></p>
                                            </div>
                                        <?php endif; ?>
                                        <?php if(get_field('period-text')) : ?>
                                            <div class="p-internshipItem__list">
                                                <p>■開催日時</p>
                                                <p><?php echo the_field('period-text'); ?></p>
                                            </div>
                                        <?php endif; ?>
                                        <div class="p-internshipItem__arrow"></div>
                                    </div>
                                </div>
                            </a>
                        <?php endwhile; ?>
                    </div>
                </div>
            </div>
        <?php
        endif;
        wp_reset_postdata();
        ?>
        <div class="p-internship__recruiting">
            <div class="p-internship__inner l-inner">
                <p class="p-internship__entitle c-entitle">program</p>
                <h2 class="p-internship__title c-title">インターンシップ/<br class="u-mobile">オープンカンパニー実施要項</h2>
                <?php if(have_rows('internship', 23)) : ?>
                    <div class="p-internship__recruitingContents">
                        <?php while (have_rows('internship', 23)) : the_row(); ?>
                            <?php if (get_sub_field('internship-block')) : ?> <!-- フィールドタイプ:グループ -->
                                <?php
                                $group = get_sub_field('internship-block');
                                if ($group) :
                                ?>
                                    <div class="p-internship__recruitingList">
                                        <p class="p-internship__recruitingTitle"><?php echo $group['internship-theme']; ?></p>
                                        <p class="p-internship__recruitingText"><?php echo $group['internship-text']; ?></p>
                                    </div>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endwhile; ?>
                    </div>
                <?php endif; ?>
                <?php if(have_rows('internship-link', 23)) : ?>
                    <?php while (have_rows('internship-link', 23)) : the_row(); ?>
                        <a href="<?php echo get_permalink(the_sub_field('internship-url')); ?>" target="_blank" rel="noopener noreferrer" class="p-internship__contact"><?php the_sub_field('internship-urltext'); ?></a>
                    <?php endwhile; ?>
                <?php endif; ?>
            </div>
        </div>
    </section>
    <?php include('template/related-internship.php'); ?>
</main>
<?php get_footer('employment');