<?php

if (! function_exists( 'constructionarc_themes_recentwork_default' ) ):

    function constructionarc_themes_recentwork_default() {

        $portfolio_options = get_theme_mod('constructionarc_portfolio_disable','enable');
        if( !empty( $portfolio_options ) && $portfolio_options == 'enable' ){

            $service_class = array(
                'section',
                'recentwork-section',
            );
        ?>
            <section id="recentwork-section" class="<?php echo esc_attr(implode(' ', $service_class)) ?>">
                <div class="section-wrap">
                    <div class="container">
                        <div class="inner-section-wrap">
                            <?php 
                                $titlestyle = get_theme_mod('constructionarc_recentwork_title_align', 'text-center');
                                $super_title = get_theme_mod('constructionarc_recentwork_super_title');
                                $title = get_theme_mod('constructionarc_recentwork_title');
                                $designstyle = get_theme_mod('constructionarc_recentwork_title_style','style1');

                                constructionarc_themes_section_title( $super_title, $title, $titlestyle, $designstyle ); 

                                constructionarc_themes_recentwork_advance_sections();
                            ?>
                        </div>
                    </div>
                </div>
            </section>
    <?php } }
endif;
add_action('constructionarc_themes_action_recentwork', 'constructionarc_themes_recentwork_default', 55);


/****
 * Advance Portfolio 
 */
if( !function_exists('constructionarc_themes_recentwork_advance_sections')){

    function constructionarc_themes_recentwork_advance_sections(){ 

        $display_layout = get_theme_mod('constructionarc_gallery_display_layout','style6');
        $block_space = get_theme_mod('constructionarc_recentwork_block_space',1);

        $gallery_area = get_theme_mod('constructionarc_recentwork_gallery');
        if($gallery_area){
            $gallery_area_items = json_decode($gallery_area);
        ?> 
            <div class="constructionarc-gallery-block-wrap">
                <?php 
                    $tab_align = get_theme_mod('constructionarc_gallery_tab_align', 'stretch');
                    $tab_wrap_class = array("constructionarc-gallery-item-wrap", $tab_align);
                    $default_text = get_theme_mod('constructionarc_gallery_default_text');
                ?>
                <div class="<?php echo esc_attr(implode(' ', $tab_wrap_class)); ?>">
                    <div class="constructionarc-gallery-name-wrap" data-active="*">
                        <?php if( !empty( $default_text ) ){ ?>
                            <div class="constructionarc-gallery-item-name default-item-name active" data-filter="*">
                                <?php echo esc_html( $default_text ); ?>
                            </div>
                        <?php } ?>
                        <?php 
                            foreach ($gallery_area_items as $gallery_area_item) {
                            $category_slug = sanitize_title_with_dashes($gallery_area_item->title); 
                            if( !empty( $gallery_area_item->title ) ){
                        ?>
                            <div class="constructionarc-gallery-item-name" data-filter=".<?php echo esc_attr($category_slug); ?>">
                                <?php echo esc_html(($gallery_area_item->title)); ?>
                            </div>
                        <?php } } ?>
                    </div>
                </div>
                <div class="constructionarc-gallery-content-wrap <?php echo esc_attr( $display_layout ); ?>" data-gutter="<?php echo intval( $block_space ); ?>">
                    <div class="constructionarc-gallery-content">
                        <?php 
                            foreach ($gallery_area_items as $gallery_area_item) {
                                
                                $category_slug = sanitize_title_with_dashes($gallery_area_item->title);

                                $gallerys = explode(',', $gallery_area_item->gallery) ;

                                foreach($gallerys as $gallery){

                                $gallery_image_large = wp_get_attachment_image_src($gallery,'full');
                                $gallery_title = get_the_title($gallery);
                                $gallery_caption = wp_get_attachment_caption($gallery);

                                if($gallery_image_large) {
                            ?>
                                <div class="constructionarc-gallery-content-item <?php echo esc_attr( $category_slug ); ?>">
                                    <div class="constructionarc-gallery-wrap">
                                        <div class="constructionarc-gallery-name" style="background-image: url(<?php echo esc_url( $gallery_image_large[0] ) ?>);">
                                            <?php 
                                                $caption = get_theme_mod('constructionarc_gallery_caption_disable', 'enable');
                                                if( !empty( $caption ) && $caption == 'enable' ){
                                            ?>
                                                <div class="constructionarc-gallery-caption">
                                                    <?php if( !empty( $gallery_title ) ){ ?>
                                                        <h4><?php echo esc_html( $gallery_title ); ?></h4>
                                                    <?php } ?>
                                                    <?php if( !empty( $gallery_caption ) ){ ?>
                                                        <p><?php echo esc_html( $gallery_caption ); ?></p>
                                                    <?php } ?>
                                                </div>
                                            <?php } ?>
                                            <?php 
                                                $zoom_icon = get_theme_mod('constructionarc_gallery_zoom_icon_disable', 'enable');
                                                if( !empty( $zoom_icon ) && $zoom_icon == 'enable' ){
                                            ?>
                                                <a class="constructionarc-gallery-image-large" href="<?php echo esc_url( $gallery_image_large[0] ) ?>" rel="portfolio[work]">
                                                    <i class="fa-solid fa-magnifying-glass-plus"></i>
                                                </a>
                                            <?php } ?>
                                        </div>
                                    </div>
                                </div>
                            <?php } } } ?>
                    </div>
                </div>
            </div>
        <?php } 
    }
}

do_action('constructionarc_themes_action_recentwork');