<?php get_header(); ?>
<main class="corporate">
    <?php include('template/bottom-corporate.php'); ?>
    <?php include('template/breadcrumb.php'); ?>
    <section class="p-company">
        <div class="p-company__heading">
            <div class="p-company__inner l-inner">
                <?php if(have_rows('company-block')) : ?>
                        <div class="p-company__headingBlocks">
                            <?php while (have_rows('company-block')) : the_row(); ?>
                                <?php if (get_sub_field('company-item')) : ?>
                                    <?php
                                    $group = get_sub_field('company-item');
                                    if ($group) :
                                    ?>
                                        <div class="p-company__headingBlock">
                                            <?php
                                            $acf_row_image = $group['company-img'];
                                            $url = $acf_row_image['url'];
                                            $alt = $acf_row_image['alt'];
                                            if ($url) :
                                            ?>
                                                <div class="p-company__headingBlockImg">
                                                    <img src="<?php echo $url; ?>" alt="<?php echo $alt; ?>">
                                                </div>
                                            <?php endif; ?>
                                            <div class="p-company__headingBlockWrap">
                                                <p class="p-company__headingBlockTitle"><?php echo $group['company-title']; ?></p>
                                                <p class="p-company__headingBlockText c-text"><?php echo $group['company-text']; ?></p>
                                                <a href="<?php echo $group['company-link']['url']; ?>" class="p-company__headingBlockLink">詳細を見る</a>
                                            </div>
                                        </div>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endwhile; ?>
                        </div>
                <?php endif; ?>
                <?php if(have_rows('youtube')) : ?>
                    <div class="p-company__youtube">
                        <?php while (have_rows('youtube')) : the_row(); ?>
                            <?php if (get_sub_field('youtube-block')) : ?>
                                <?php
                                $group = get_sub_field('youtube-block');
                                if ($group) :
                                ?>
                                    <div class="p-company__youtubeBlock">
                                        <div class="p-company__youtubeScene">
                                            <?php echo $group['youtube-iframe']; ?>
                                        </div>
                                        <p class="p-company__blockTitle"><?php echo $group['youtube-title']; ?></p>
                                    </div>
                                <?php endif; ?>
                            <?php endif; ?>
                        <?php endwhile; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
        <div class="p-company__information">
            <div class="p-company__inner l-inner">
                <div class="p-company__informationWrap">
                    <p class="p-company__entitle c-entitle">information</p>
                    <h2 class="p-company__title c-title">お知らせ・ニュース</h2>
                    <?php if(have_rows('news-blocks')) : ?>
                        <div class="p-company__contents">
                            <?php while (have_rows('news-blocks')) : the_row(); ?>
                                <?php if (get_sub_field('news-block')) : ?>
                                    <?php
                                    $group = get_sub_field('news-block');
                                    if ($group) :
                                    ?>
                                        <a href="<?php echo get_permalink($group['news-id']); ?>" class="p-company__block">
                                            <div class="p-company__blockImg c-img">
                                                <?php echo get_the_post_thumbnail($group['news-id']); ?>
                                            </div>
                                            <p class="p-company__blockTitle"><?php echo $group['news-title']; ?></p>
                                            <p class="p-company__blockText c-text"><?php echo $group['news-text']; ?></p>
                                        </a>
                                    <?php endif; ?>
                                <?php endif; ?>
                            <?php endwhile; ?>
                        </div>
                    <?php endif; ?>
                    <?php
                    $the_query = new WP_Query();
                    $param = array(
                        'post_type'      => 'news',
                        'posts_per_page' => '10',
                        'post_status'    => 'publish',
                    );
                    $the_query->query($param);
                    if ($the_query->have_posts()) :
                    ?>
                        <div class="p-company__items">
                            <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
                                <a href="<?php the_permalink(); ?>" class="p-company__item p-news">
                                    <div class="p-news__info">
                                        <time class="p-news__time" datetime="<?php the_time('c'); ?>"><?php the_time( 'Y/m/d' ); ?></time>
                                        <?php
                                        $terms = get_the_terms($post->ID, 'news-cat');
                                        if ( $terms ) {
                                            echo '<p class="p-news__category">'.$terms[0]->name.'</p>';
                                        }
                                        ?>
                                    </div>
                                    <p class="p-news__title"><?php the_title(); ?></p>
                                </a>
                            <?php endwhile; ?>
                        </div>
                    <?php
                    endif;
                    wp_reset_postdata();
                    ?>
                    <div class="p-topInformation__link">
                        <a href="<?php echo esc_url(home_url('/news/')); ?>" class="c-link">一覧を見る</a>
                    </div>
                </div>
            </div>
        </div>
    </section>
</main>
<?php get_footer();