<?php 
    $class    = isset($args['class']) ? $args['class'] : '';
    $category = isset($args['category']) ? $args['category'] : 'home';
    $show_cta = isset($args['show-cta']) ? $args['show-cta'] : false;

    $args = array(
        'post_type'           => 'industry',
        'post_status'         => 'publish',
        'ignore_sticky_posts' => 1,
        'posts_per_page'      => -1,
        'orderby'             => 'menu_order',
        'order'               => 'ASC',
        'tax_query'           => array(array(
            'taxonomy'        => 'industry_categories',
            'field'           => 'slug',
            'terms'           => $category,
            'operator'        => 'IN'
        ))
    );

    $industries = new WP_Query( $args );
?>

<?php if ($industries->have_posts()) : ?>

<section class="section more-industries <?php echo $class;?>">
    <div class="container-fluid">
        <div class="more-industries-slider-wrapper">
            <div class="row gy-4 gy-lg-0">
                <div class="col-lg-6">
                    <div class="text-cont slide-right">
                        <div class="d-flex align-items-center gap-3">
                            <svg width="36" height="4" viewBox="0 0 36 4" fill="none" xmlns="http://www.w3.org/2000/svg">
                                <path d="M34.0273 0.445312H2.02734C1.19892 0.445312 0.527344 1.11689 0.527344 1.94531C0.527344 2.77374 1.19892 3.44531 2.02734 3.44531H34.0273C34.8558 3.44531 35.5273 2.77374 35.5273 1.94531C35.5273 1.11689 34.8558 0.445312 34.0273 0.445312Z" fill="#5558a6"/>
                            </svg>
                            <?php $top_heading = get_field('more_industries_top_heading'); ?>
                            <h2 class="mb-0 why-choose"><?php echo !empty($top_heading) ? $top_heading : 'More Industries'; ?></h2>
                        </div>
                        <h2 class="section-innertitle why-choose-title mb-0 mt-2 mt-lg-4"><?php echo get_field('more_industries_section_heading'); ?></h2>
                        <p class="why-choose-text mt-md-1 mt-3 mt-lg-4"><?php echo get_field('more_industries_section_text'); ?></p>

                        <div class="buttons-wrapper">
                            <a href="<?php echo get_field('more_industries_section_button_link'); ?>" class="purple-outline-btn animated-btn mt-4">
                                <?php
                                    $button_text = get_field('more_industries_section_button_text');
                                    echo isset($button_text) && !empty($button_text) ? $button_text : 'Let’s Discover';
                                ?>     
                                <svg class="ms-2" width="16" height="17" viewBox="0 0 16 17" fill="none" xmlns="http://www.w3.org/2000/svg">
                                    <path d="M8.75 5.16406L11.75 7.88281C11.9062 8.00781 11.9688 8.19531 12 8.44531C12 8.63281 11.9062 8.85156 11.75 8.94531L8.75 11.7266C8.53125 11.9453 8.21875 11.9766 7.9375 11.8828C7.65625 11.7578 7.5 11.4766 7.5 11.1953V9.44531H4.75C4.3125 9.44531 4 9.13281 4 8.69531V8.19531C4 7.78906 4.3125 7.44531 4.75 7.44531H7.46875V5.69531C7.46875 5.41406 7.6875 5.13281 7.9375 5.03906C8.1875 4.91406 8.53125 4.94531 8.75 5.16406ZM8 0.445312C12.4062 0.445312 16 4.03906 16 8.44531C16 12.8828 12.4062 16.4453 8 16.4453C3.5625 16.4453 0 12.8828 0 8.44531C0 4.03906 3.5625 0.445312 8 0.445312ZM8 14.9453C11.5625 14.9453 14.5 12.0391 14.5 8.44531C14.5 4.88281 11.5625 1.94531 8 1.94531C4.40625 1.94531 1.5 4.88281 1.5 8.44531C1.5 12.0391 4.40625 14.9453 8 14.9453Z" fill="white"/>
                                </svg>                                                                                             
                            </a>
                        </div>
                        <div class="slide-owl-nav d-none d-lg-flex">
                            <button class="slide-prev-button" aria-label="slide prev">
                                <img src="<?php echo get_template_directory_uri();?>/assets/img/left-arrow.webp" alt="slide arrow prev">
                            </button>
                            <button class="slide-next-button" aria-label="slide next">
                                <img src="<?php echo get_template_directory_uri();?>/assets/img/right-arrow.webp" alt="slide arrow next">
                            </button>
                        </div>

                    </div>
                </div>
                <div class="col-lg-6 pr-md-0">
                    <div class="owl-carousel owl-theme more-industries-slider">

                        <?php while ($industries->have_posts()) : $industries->the_post(); ?>
                            <div class="item">
                                <div class="card">
                                    <div class="card-header p-0">
                                        <div class="img-content">
                                            <img src="<?php echo get_field('industry_image'); ?>" alt="<?php echo get_the_title(); ?>" loading="lazy" class="img-fluid">
                                            <div class="svg-wrapper">
                                                <?php echo get_field('svgicon'); ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card-body pt-0">
                                        <h2><?php echo get_the_title(); ?></h2>
                                        <?php echo wpautop( get_the_content() ); ?>
                                        <?php if ($show_cta) : ?>
                                            <a href="<?php echo get_field('industry_link'); ?>" class="read-more d-inline-block"  aria-label="Know more about <?php echo get_the_title(); ?>"> 
                                                <svg class="me-2" width="15" height="13" viewBox="0 0 15 13" fill="none" xmlns="http://www.w3.org/2000/svg">
                                                    <path d="M14.2148 7.66406L9.21484 12.6641C9.02734 12.8516 8.77734 12.9453 8.52734 12.9453C8.24609 12.9453 7.99609 12.8516 7.80859 12.6641C7.40234 12.2891 7.40234 11.6328 7.80859 11.2578L11.0898 7.94531H1.52734C0.964844 7.94531 0.527344 7.50781 0.527344 6.94531C0.527344 6.41406 0.964844 5.94531 1.52734 5.94531H11.0898L7.80859 2.66406C7.40234 2.28906 7.40234 1.63281 7.80859 1.25781C8.18359 0.851562 8.83984 0.851562 9.21484 1.25781L14.2148 6.25781C14.6211 6.63281 14.6211 7.28906 14.2148 7.66406Z" fill="#5956E9"/>
                                                </svg>
                                            </a>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        <?php endwhile; ?>
                        <?php wp_reset_postdata(); ?>
                    </div>
                    <div class="slide-owl-nav d-lg-none d-flex">
                        <button class="slide-prev-button" aria-label="slide prev">
                            <img src="<?php echo get_template_directory_uri();?>/assets/img/left-arrow.webp" alt="slide arrow prev">
                        </button>
                        <button class="slide-next-button" aria-label="slide next">
                            <img src="<?php echo get_template_directory_uri();?>/assets/img/right-arrow.webp" alt="slide arrow next">
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<?php endif; ?>