<?php

$id = 'advantages-block-' . $block['id'];
if ( ! empty($block['anchor'] ) ) {
    $id = $block['anchor'];
}

$classes = 'block-advantages-block';
if ( ! empty( $block['className'] ) ) {
    $classes .= ' ' . $block['className'];
}
if ( ! empty( $block['align'] ) ) {
    $classes .= ' align' . $block['align'];
}

$heading = get_field('heading');

?>

<section id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
    <div class="container mx-auto mt-[24px]">

        <?php if ($heading) : ?>
            <h2 class="text-[48px] max-[768px]:text-[36px] font-bold text-center text-[#1f2937] mb-[40px]">
                <?php echo esc_html($heading); ?>
            </h2>
        <?php endif; ?>

        <?php if ( have_rows( 'advantages_repeater' ) ) : ?>
            <div class="mt-[24px] grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-[30px] max-[768px]:gap-[20px]">
                <?php while ( have_rows( 'advantages_repeater' ) ) : the_row(); ?>
                    <div class="bg-[#ffffff] border-[1px] border-[#e5e7eb] rounded-[16px] p-[30px] max-[768px]:p-[20px] shadow-lg hover:shadow-xl transition-shadow ">

                        <?php $advantage_heading = get_sub_field('heading'); ?>
                        <?php if (!empty($advantage_heading)) : ?>
                            <h3 class="text-[48px] max-[768px]:text-[34px] font-semibold text-[#1f2937] mb-[16px] text-center leading-[120%]">
                                <?php echo esc_html($advantage_heading); ?>
                            </h3>
                        <?php endif; ?>

                        <?php $advantage_text = get_sub_field('text'); ?>
                        <?php if (!empty($advantage_text)) : ?>
                            <div class="text-[16px] max-[768px]:text-[14px] text-[#6b7280] leading-[150%] text-center">
                                <?php echo wp_kses_post($advantage_text); ?>
                            </div>
                        <?php endif; ?>

                    </div>
                <?php endwhile; ?>
            </div>
        <?php else : ?>
            <!-- No advantages found -->
        <?php endif; ?>

    </div>
</section>