<?php 
/**
 * Template part for displaying Featured Courses Section
 *
 * @package Prime Charity Trust
 */
$prime_charity_trust_featured_services_section_title = prime_charity_trust_get_option( 'featured_services_section_title' );
$prime_charity_trust_number_of_featured_services_items = prime_charity_trust_get_option( 'number_of_featured_services_items' );

for ( $i = 1; $i <= $prime_charity_trust_number_of_featured_services_items; $i++ ) :
    $prime_charity_trust_featured_services_posts[] = prime_charity_trust_get_option( 'featured_services_post_'.$i );
endfor;
?>
<?php if ( ! empty( $prime_charity_trust_featured_services_section_title ) ) : ?>
    <div class="section-title">
        <h4><?php echo esc_html( $prime_charity_trust_featured_services_section_title ); ?></h4>
    </div>
<?php endif; ?>
<div id="service-section" class="section-content">
    <?php
    $args = array(
        'post_type'           => 'post',
        'posts_per_page'      => absint( $prime_charity_trust_number_of_featured_services_items ),
        'post__in'            => $prime_charity_trust_featured_services_posts,
        'orderby'             => 'post__in',
        'ignore_sticky_posts' => true,
    );
    ?>
    <div class="owl-carousel">
        <?php
        $loop = new WP_Query( $args );
        if ( $loop->have_posts() ) :
            while ( $loop->have_posts() ) : $loop->the_post(); ?>

                <article style="padding: 0 15px;">
                    <div class="featured-service-item">
                        <div class="entry-container">                        
                            <div class="content-image">
                                <?php if ( has_post_thumbnail( $post->ID ) ) : ?>
                                    <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                                    <div class="image-container" style="background-image: url(<?php echo esc_attr( $image[0] ); ?>);"></div>
                                <?php else : ?>
                                    <div class="image-container default-image" style="background-image: url('<?php echo esc_html(get_template_directory_uri() ) . '/assets/images/dontaion-default.png'; ?>');"></div>
                                <?php endif; ?>
                                <div class="cause-tags">
                                    <?php
                                    $tags = get_the_tags();
                                    if ( $tags ) {
                                        foreach ( $tags as $prime_charity_trust_content_tag ) {
                                            $sep = ( $prime_charity_trust_content_tag === end( $tags ) ) ? '' : ' ';
                                            echo '<a href="' . esc_url( get_term_link( $prime_charity_trust_content_tag, $prime_charity_trust_content_tag->taxonomy ) ) . '">' . esc_html( $prime_charity_trust_content_tag->name ) . '</a>' . esc_html( $sep );
                                        }
                                    }
                                    ?>
                                </div>
                            </div>
                            <div class="content-details">
                                <header class="entry-header">
                                    <h2 class="entry-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
                                </header>
                                <div class="entry-content">
                                    <?php
                                    $prime_charity_trust_excerpt = prime_charity_trust_the_excerpt( 20 );
                                    echo wp_kses_post( wpautop( $prime_charity_trust_excerpt ) );
                                    ?>
                                </div><!-- .entry-content -->
                                <?php if ( get_post_meta( $post->ID, 'prime_charity_trust_raised', true ) || get_post_meta( $post->ID, 'prime_charity_trust_goal', true ) ) : ?>
                                    <div class="fund-box">
                                        <?php if ( get_post_meta( $post->ID, 'prime_charity_trust_raised', true ) ) : ?>
                                            <div class="raised-box">
                                                <span class="first-word"><?php esc_html_e( 'Raised', 'prime-charity-trust' ); ?></span>
                                                <span> <?php echo esc_html( get_woocommerce_currency_symbol() ); ?><?php echo esc_html( get_post_meta( $post->ID, 'prime_charity_trust_raised', true ) ); ?></span>
                                            </div>
                                        <?php endif; ?>
                                        <?php if ( get_post_meta( $post->ID, 'prime_charity_trust_goal', true ) ) : ?>
                                            <div class="goal-box">
                                                <span class="first-word"><?php esc_html_e( 'Goal', 'prime-charity-trust' ); ?></span>
                                                <span> <?php echo esc_html( get_woocommerce_currency_symbol() ); ?><?php echo esc_html( get_post_meta( $post->ID, 'prime_charity_trust_goal', true ) ); ?></span>
                                            </div>
                                        <?php endif; ?>
                                        <?php
                                        $prime_charity_trust_raised_value = get_post_meta( $post->ID, 'prime_charity_trust_raised', true );
                                        $prime_charity_trust_goal_value = get_post_meta( $post->ID, 'prime_charity_trust_goal', true );
                                        if ( $prime_charity_trust_raised_value != '' && $prime_charity_trust_goal_value != '' ) {
                                            $prime_charity_trust_percent_value = round( ( $prime_charity_trust_raised_value / $prime_charity_trust_goal_value ) * 100 ); ?>
                                            <div class="donate-slider">
                                                <div class="slide-inner" style="width: <?php echo esc_attr( $prime_charity_trust_percent_value ); echo esc_html( '%', 'prime-charity-trust' ); ?>"></div>
                                            </div>
                                        <?php } ?>
                                    </div>
                                <?php endif; ?>
                                <div class="button-content">
                                    <a href="<?php the_permalink(); ?>" class="btn">
                                        <?php esc_html_e( 'Know More', 'prime-charity-trust' ); ?> <i class="<?php echo esc_attr( get_theme_mod( 'prime_charity_trust_service_icon', 'fas fa-arrow-right' ) ); ?>"></i>
                                    </a>
                                </div><!-- .button-content -->
                            </div>
                        </div><!-- .entry-container -->
                    </div><!-- .featured-service-item -->
                </article>

            <?php endwhile; ?>
        <?php endif; ?>
        <?php wp_reset_postdata(); ?>
    </div>
</div><!-- .section-content -->
