<?php
/**
 * Template part for displaying the about section
 *
 * @package SEO Enterprise
 * @subpackage seo_enterprise
 */

$seo_enterprise_static_image = get_template_directory_uri() . '/assets/images/sliderimage.png';

// Check if the about section is enabled
if ( get_theme_mod( 'seo_enterprise_about_enable', true)) : ?>
    <section id="about" class="my-5 px-md-0 px-3">
        <div class="container">
            <?php
            // Fetch about page ID from customizer
            $seo_enterprise_about_page_id = absint( get_theme_mod( 'seo_enterprise_about_page' ) );
            // Check if a valid page is set for the about section
            if ( $seo_enterprise_about_page_id ) :
                $seo_enterprise_args = array(
                    'post_type' => 'page',
                    'p'         => $seo_enterprise_about_page_id,
                );
                $seo_enterprise_query = new WP_Query( $seo_enterprise_args );
                // Check if the query has posts
                if ( $seo_enterprise_query->have_posts() ) :
                    while ( $seo_enterprise_query->have_posts() ) : $seo_enterprise_query->the_post(); ?>
                        <div class="row">
                            <div class="col-lg-6 col-md-6 align-self-center pe-lg-5">
                                <div class="match-heading text-end">
                                    <?php 
                                    $seo_enterprise_sub_heading = get_theme_mod( 'seo_enterprise_service_sub_heading' );
                                    if ( $seo_enterprise_sub_heading ) : ?>
                                        <p class="mb-md-3 mb-2 abt-title text-uppercase"><?php echo esc_html( $seo_enterprise_sub_heading ); ?></p>
                                    <?php endif; ?>
                                    
                                    <h2 class="mb-3 text-capitalize">
                                        <?php 
                                            $seo_enterprise_title = explode(' ', get_the_title()); // Split title into words
                                            if (count($seo_enterprise_title) >= 3) {
                                                $seo_enterprise_title[2] = '<span class="title-highlight">' . esc_html($seo_enterprise_title[2]) . '</span>'; // Highlight 3rd word
                                            }
                                            $seo_enterprise_final_title = implode(' ', $seo_enterprise_title); // Rebuild title
                                        ?>
                                        <a href="<?php echo esc_url( get_permalink() ); ?>"><?php echo wp_kses_post($seo_enterprise_final_title); ?></a>
                                    </h2>
                                </div>
                                <?php for ($seo_enterprise_i = 1; $seo_enterprise_i <= 2; $seo_enterprise_i++) : ?>
                                    <div class="tab-item mb-3">
                                        <div class="tab-title">
                                            <?php 
                                            $seo_enterprise_tab_title = get_theme_mod('seo_enterprise_tab_heading' . $seo_enterprise_i);
                                            if (!empty($seo_enterprise_tab_title)) : ?>
                                                <p class="mb-2"><?php echo esc_html($seo_enterprise_tab_title); ?></p>
                                                <i class="fa-solid fa-arrow-right ms-2 mt-md-1 mt-2"></i>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                <?php endfor; ?>
                            </div>
                            <div class="col-lg-6 col-md-6 align-self-center image-abt mb-3">
                                <div class="about-block">
                                    <div class="about-image1">
                                        <div class="thumbnail">
                                            <?php if ( has_post_thumbnail() ) : ?>
                                                <?php the_post_thumbnail( 'full', array( 'alt' => esc_attr( get_the_title() ) ) ); ?>
                                            <?php else : ?>
                                                <img src="<?php echo esc_url( $seo_enterprise_static_image ); ?>" alt="<?php esc_attr_e( 'Placeholder', 'seo-enterprise' ); ?>" />
                                            <?php endif; ?>
                                        </div>

                                        <!-- Stats Boxes -->
                                        <div class="abt-bg-img">
                                            <?php 
                                            $seo_enterprise_website_improved_numbers = get_theme_mod( 'seo_enterprise_website_improved_numbers', '' );
                                            if ( $seo_enterprise_website_improved_numbers ) : ?>
                                                <div class="website-improved-box one">
                                                    <div class="start-yr-content">
                                                        <i class="fas fa-signal"></i><div class="start-yr"><?php echo esc_html( $seo_enterprise_website_improved_numbers ); ?></div>
                                                        <div class="year-text"><?php esc_html_e( 'Websites Improved', 'seo-enterprise' ); ?></div>
                                                    </div>
                                                </div>
                                            <?php endif; ?>

                                            <?php 
                                            $seo_enterprise_website_improved_percentage = get_theme_mod( 'seo_enterprise_website_improved_percentage', '' );
                                            if ( $seo_enterprise_website_improved_percentage ) : ?>
                                                <div class="website-improved-box two">
                                                    <div class="start-yr-content">
                                                        <i class="fas fa-thumbs-up"></i><div class="start-yr"><?php echo esc_html( $seo_enterprise_website_improved_percentage ); ?></div>
                                                        <div class="year-text"><?php esc_html_e( 'Websites Improved', 'seo-enterprise' ); ?></div>
                                                    </div>
                                                </div>
                                            <?php endif; ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php endwhile;
                    wp_reset_postdata();
                endif;
            endif; ?>
        </div>
    </section>
<?php endif; ?>