<?php 
$class = isset($args['class']) ? $args['class'] : '';
?>

<section class="section portal-benefits-3pl <?php echo $class; ?>">
    <div class="container">
        <div class="row mb-3">
            <div class="col-lg-12 col-xl-8">
                <?php if (get_field('3pl_cpb_section_title')) : ?>
                    <h2 class="section-title text-center text-xl-start">
                        <?php echo get_field('3pl_cpb_section_title'); ?>
                    </h2>
                <?php endif; ?>
            </div>

            <div class="col-lg-12 col-xl-4">
                <?php if (get_field('3pl_cpb_section_text')) : ?>
                    <p class="section-content text-center text-xl-start">
                        <?php echo get_field('3pl_cpb_section_text'); ?>
                    </p>
                <?php endif; ?>
            </div>
        </div>

        <div class="row gy-4">
            <div class="col-lg-8">
                <div class="row gy-4">

                    <?php if (have_rows('3pl_cpb_cards_repeater')) : 
                        $count = 1;
                        while (have_rows('3pl_cpb_cards_repeater')) : the_row(); ?>

                            <div class="col-md-6 col-lg-6">
                                <div class="card">
                                    <div class="numeric-wrapper">
                                        <?php echo str_pad($count, 2, '0', STR_PAD_LEFT); ?>
                                    </div>

                                    <div class="d-flex gap-4 align-items-center title-box">
                                        <h3><?php echo get_sub_field('3pl_cpb_card_title'); ?></h3>
                                    </div>

                                    <p class="text">
                                        <?php echo get_sub_field('3pl_cpb_card_text'); ?>
                                    </p>
                                </div>
                            </div>

                    <?php 
                        $count++;
                        endwhile;
                    endif; ?>

                </div>
            </div>

            <div class="col-lg-4">
                <?php 
                $image = get_field('3pl_cpb_section_image');
                if ($image) : ?>
                    <div class="img-wrapper">
                        <img src="<?php echo $image; ?>" alt="<?php echo wp_strip_all_tags(get_field('3pl_cpb_section_title'))?>" class="img-fluid h-100">
                    </div>
                <?php endif; ?>
            </div>
        </div>

        <?php $button = get_field('3pl_cpb_section_button');
        if ($button) : ?>
            <div class="text-center mt-4">
                <a href="<?php echo esc_url($button['url']); ?>" class="primary animated-cta-btn">
                    <?php echo $button['title']; ?>
                </a>
            </div>
        <?php endif; ?>

    </div>
</section>
