<?php
// Page: Podcast
// ID: 125

get_header();

$args = array(
    'post_type'      => 'podcasty',
    'posts_per_page' => 6,
    'orderby'        => 'date',
    'order'          => 'DESC',
);

$podcasty_query = new WP_Query( $args );

$blog_args = array(
    'post_type'      => 'post',
    'posts_per_page' => 5,
	'orderby'        => 'date',
	'order'          => 'DESC',
);

$blog_posts = new WP_Query( $blog_args );

$box_1 = get_field('box_1');
$box_2 = get_field('box_2');

$box_form_home_page = get_field('box_3', 7);
?>
<main id="primary" class="site-main">
    <section class="box-1">
        <div class="container">
            <div class="row">
                <div class="col-1">
                    <div id="box-page-name">
                        <?php echo get_the_title(); ?>
                    </div>
                    <div class="box-title">
                        <?php echo $box_1['title']; ?>
                    </div>
                    <div class="box-text">
                        <?php echo $box_1['text']; ?>
                    </div>
                </div>
                <div class="col-2">
                    <div class="box-img">
                        <img src="<?php echo $box_1['img']; ?>" alt="">
                    </div>
                </div>
            </div>
        </div>
    </section>

    <section class="box-2">
        <div class="container">
            <div class="box-wrapper">
                <div class="row row-1">
                    <div id="podcasty-list" class="podcasty-list">
                    <?php
                        if ($podcasty_query->have_posts()) :
                            while ($podcasty_query->have_posts()) : $podcasty_query->the_post();

                                get_template_part('inc/template-podcast-card', null, [
                                    'image' => get_the_post_thumbnail_url(get_the_ID(), 'medium_large'),
                                    'title' => get_the_title(),
                                    'link'  => get_the_permalink(),
                                    'acf'   => get_field('time')
                                ]);
                            endwhile;
                        endif;
                        wp_reset_postdata();
                    ?>
                    </div>
                </div>

                <?php if ($podcasty_query->found_posts > 6) : ?>
                    <div class="row row-2">
                        <button class="btn-3" id="load-more-podcasts">
                            Wczytaj więcej
                        </button>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    </section>

    <section class="box-3">
        <div class="box-bg">
            <img src="/wp-content/uploads/2025/10/artilce-bg-1.svg" alt="">
        </div>
        <div class="container">
            <div class="row">
                <div class="box-title">
                    <h2><?php echo $box_2['title']; ?></h2>
                </div>

                <div class="box-list">
                    <?php foreach ($box_form_home_page['posts'] as $item) : ?>
                        <?php
                            get_template_part('inc/template-article-card', null, [
                                'post_id'  => $item['post']->ID,
                                'image' => get_the_post_thumbnail_url($item['post']->ID),
                                'title' => $item['post']->post_title,
                                'link'  => get_the_permalink($item['post']->ID),
								// 'category' => get_the_category($item->ID)
                            ]);
                        ?>
                    <?php endforeach; ?>

                    <?php
                        get_template_part('inc/template-article-more-card', null, [
                            'image' => $box_form_home_page['img'],
                            'title' => $box_form_home_page['text'],
                            'link_text' => 'Zobacz wszystkie artykuły',
                            'link'  => get_permalink(94),
                        ]);
                    ?>
                </div>
            </div>
        </div>
    </section>
</main>
<?php get_footer(); ?>