<?php
/**
 * Template Name: Home Page
 */

get_header();
?>

<main id="primary">

    <?php 
        $rev_orphanage_main_slider_wrap = absint(get_theme_mod('rev_orphanage_enable_slider', 0));

        if ($rev_orphanage_main_slider_wrap == 1): 
    ?>
        <section id="main-slider-wrap">
            <div class="slider-main">
                <div class="owl-carousel">
                    <?php for ($rev_orphanage_main_i = 1; $rev_orphanage_main_i <= 3; $rev_orphanage_main_i++): ?>
                        <?php 
                        $rev_orphanage_slider_image = get_theme_mod('rev_orphanage_slider_image' . $rev_orphanage_main_i);
                        if ($rev_orphanage_slider_image): 
                        ?>
                            <div class="main-slider-inner-box">
                                <div class="container">
                                    <div class="flex-row">
                                        <div class="slider-left">
                                            <div class="main-slider-content-box">
                                                <?php if ($rev_orphanage_top_text = get_theme_mod('rev_orphanage_slider_top_text' . $rev_orphanage_main_i)): ?>
                                                    <p class="slider-top"><?php echo esc_html($rev_orphanage_top_text); ?></p>
                                                <?php endif; ?>

                                                <?php if ($rev_orphanage_heading = get_theme_mod('rev_orphanage_slider_heading' . $rev_orphanage_main_i)): ?>
                                                    <h1><?php echo esc_html($rev_orphanage_heading); ?></h1>
                                                <?php endif; ?>

                                                <?php if ($rev_orphanage_slider_subheading = get_theme_mod('rev_orphanage_slider_subheading' . $rev_orphanage_main_i)): ?>
                                                    <h2><?php echo esc_html($rev_orphanage_slider_subheading); ?></h2>
                                                <?php endif; ?>

                                                <?php if ($rev_orphanage_text = get_theme_mod('rev_orphanage_slider_text' . $rev_orphanage_main_i)): ?>
                                                    <p class="slider-para"><?php echo wp_kses_post($rev_orphanage_text); ?></p>
                                                <?php endif; ?>

                                                <div class="main-slider-button">
                                                    <?php 
                                                    $rev_orphanage_button1_link = get_theme_mod('rev_orphanage_slider_button1_link' . $rev_orphanage_main_i);
                                                    $rev_orphanage_button1_text = get_theme_mod('rev_orphanage_slider_button1_text' . $rev_orphanage_main_i);
                                                    if ($rev_orphanage_button1_link || $rev_orphanage_button1_text): 
                                                    ?>
                                                        <a class="slide-btn-1" href="<?php echo esc_url($rev_orphanage_button1_link); ?>">
                                                            <?php echo esc_html($rev_orphanage_button1_text); ?>
                                                        </a>
                                                    <?php endif; ?>

                                                    <?php 
                                                    $rev_orphanage_button2_link = get_theme_mod('rev_orphanage_slider_button2_link' . $rev_orphanage_main_i);
                                                    $rev_orphanage_button2_text = get_theme_mod('rev_orphanage_slider_button2_text' . $rev_orphanage_main_i);
                                                    if ($rev_orphanage_button2_link || $rev_orphanage_button2_text): 
                                                    ?>
                                                        <a class="slide-btn-2" href="<?php echo esc_url($rev_orphanage_button2_link); ?>">
                                                            <?php echo esc_html($rev_orphanage_button2_text); ?>
                                                        </a>
                                                    <?php endif; ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="slider-right">
                                            <img src="<?php echo esc_url($rev_orphanage_slider_image); ?>" alt="<?php echo esc_attr($rev_orphanage_heading); ?>">
                                        </div>
                                    </div>
                                </div>
                            </div>
                        <?php endif; ?>
                    <?php endfor; ?>
                </div>
            </div>
        </section>
    <?php endif; ?>


    <?php
    if (get_theme_mod('rev_orphanage_service_enable', 0) != '') : ?>
        <section id="service">
            <div class="container">
                <?php
                $rev_orphanage_default_about_page = get_page_id_by_slug('about');
                $rev_orphanage_about_page_id = absint(get_theme_mod('rev_orphanage_about_page',$rev_orphanage_default_about_page));
                if ($rev_orphanage_about_page_id != 0) : 
                    $rev_orphanage_args = array(
                        'post_type' => 'page',
                        'p' => $rev_orphanage_about_page_id
                    );
                    $rev_orphanage_query = new WP_Query($rev_orphanage_args);
                    if ($rev_orphanage_query->have_posts()) :
                        while ($rev_orphanage_query->have_posts()) : $rev_orphanage_query->the_post(); ?>
                        <div class="flex-row">
                            <div class="about-block">
                                <div class="flex-row">
                                    <div class="exp-btn">
                                        <div class="experience_btn">
                                            <?php
                                            $rev_orphanage_charity_experience = get_theme_mod('rev_orphanage_charity_experience');
                                            if (!empty($rev_orphanage_charity_experience)) : ?>
                                                <p class="designer-experi">
                                                    <span class="experience-year">
                                                        <?php echo esc_html($rev_orphanage_charity_experience); ?> 
                                                        <?php echo esc_html__('YEARS OF EXPERIENCE', 'rev-orphanage'); ?>
                                                    </span>
                                                </p>
                                            <?php endif; ?>
                                        </div>
                                    </div>

                                    <div class="main-img">
                                        <div class="about-image1">
                                            <?php if (has_post_thumbnail()) { ?>
                                                <img src="<?php echo esc_url(get_the_post_thumbnail_url(null, 'full')); ?>" alt="<?php the_title_attribute(); ?>" />
                                            <?php } else { ?>
                                                <img src="<?php echo esc_url( get_template_directory_uri() ); ?>/revolution/assets/images/about-bg.png" alt="<?php the_title_attribute(); ?>" />
                                            <?php } ?>
                                        </div>
                                        <div class="about-image2 text-start">
                                            <?php
                                            $rev_orphanage_about_bg = get_theme_mod('rev_orphanage_about_bg');
                                            if (!empty($rev_orphanage_about_bg)) { ?>
                                                <img src="<?php echo esc_url($rev_orphanage_about_bg); ?>" alt="<?php esc_attr_e('Background Image', 'rev-orphanage'); ?>" />
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="main-abt-content">
                                <?php if (
                                    get_theme_mod('rev_orphanage_service_about_us') != '' ||
                                    get_theme_mod('rev_orphanage_service_sub_heading') != ''
                                ) : ?>
                                    <div class="match-heading">
                                        <?php if (!empty(get_theme_mod('rev_orphanage_service_about_us'))) : ?>
                                            <p class="bold-text text-capitalize">
                                                <?php echo esc_html(get_theme_mod('rev_orphanage_service_about_us')); ?>
                                            </p>
                                        <?php endif; ?>
                                        <?php if (!empty(get_theme_mod('rev_orphanage_service_sub_heading'))) : ?>
                                            <h2 class="about-h2"><?php echo esc_html(get_theme_mod('rev_orphanage_service_sub_heading')); ?></h2>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>

                                <h3>
                                    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
                                </h3>
                                <p class="main-abt-para">
                                    <?php 
                                        // Check if the post has content
                                        $rev_orphanage_content = get_the_content();
                                        if (!empty($rev_orphanage_content)) {
                                            // If content exists, trim it and escape it properly
                                            echo esc_html(wp_trim_words($rev_orphanage_content, 60));
                                        } else {
                                            // If content does not exist, display the escaped Lorem ipsum text
                                            echo esc_html('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit','rev-orphanage');
                                        }
                                    ?>
                                </p>

                                <?php if (
                                    get_theme_mod('rev_orphanage_tab_heading1') != '' ||
                                    get_theme_mod('rev_orphanage_tab_heading2') != '' ||
                                    get_theme_mod('rev_orphanage_tab_heading3') != ''
                                ) : ?>
                                    <div class="flex-row content-main">
                                        <?php for ($rev_orphanage_i = 1; $rev_orphanage_i <= 4; $rev_orphanage_i++) : ?>
                                            <?php if (get_theme_mod('rev_orphanage_tab_heading' . $rev_orphanage_i) != '') : ?>
                                                <div class="abt-sentences">
                                                    <div class="tab-details d-flex align-items-center">
                                                        <?php
                                                        $rev_orphanage_icon_class = get_theme_mod('rev_orphanage_tab_icon' . $rev_orphanage_i);
                                                        if (empty($rev_orphanage_icon_class)) {
                                                            $rev_orphanage_icon_class = 'fas fa-hand-holding-heart'; // Default icon
                                                        }
                                                        ?>
                                                        <i class="<?php echo esc_attr($rev_orphanage_icon_class); ?>"></i>
                                                        <div class="abt-content">
                                                            <h4><?php echo esc_html(get_theme_mod('rev_orphanage_tab_heading' . $rev_orphanage_i)); ?></h4>
                                                            <p><?php echo esc_html(get_theme_mod('rev_orphanage_tab_para' . $rev_orphanage_i)); ?></p>
                                                        </div>
                                                    </div>
                                                </div>
                                            <?php endif; ?>
                                        <?php endfor; ?>
                                    </div>
                                <?php endif; ?>

                                <div class="abt-buttonmain">
                                    <?php if (!empty(get_theme_mod('rev_orphanage_abt_link')) || !empty(get_theme_mod('rev_orphanage_abt_button', 'MORE ABOUT'))) : ?>
                                        <div class="more-btn">
                                            <a href="<?php echo esc_url(get_theme_mod('rev_orphanage_abt_link', '')); ?>" class="abt-btn">
                                                <?php echo esc_html(get_theme_mod('rev_orphanage_abt_button', 'MORE ABOUT')); ?>
                                            </a>
                                            <span class="more-icon"><i class="fas fa-play"></i></span>
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                        <?php endwhile;
                        wp_reset_postdata();
                    endif;
                endif; ?>
            </div>
        </section>
    <?php endif; ?>

</main>

<?php
get_footer();
?>