<?php
$prato_store_options = prato_store_theme_options();

$category_item_show = $prato_store_options['category_item_show'];
$category_layout = $prato_store_options['category_layout'];


if($category_item_show) { 

    if($category_layout=="layout1"){ ?>
    <div class="product-categories-section section">
    <?php } 

    else{ ?>
        <div class="product-categories-section section layout2">
    <?php } ?>
        <div class="container-fluid">
            <div class="row">

        <?php
        if (class_exists('WooCommerce')) { 
        $taxs1 = ( get_theme_mod( 'prato_store_category_dropdown1' ) );

        $taxs2 = ( get_theme_mod( 'prato_store_category_dropdown2' ) );

                

        if($taxs1){
            $category = get_term_by( 'id', $taxs1 , 'product_cat' );

        

            // Get the URL of this category
            $category_link = get_category_link( $taxs1 );


            // Get the thumbnail Id
            $thumbnail_id  = get_term_meta( $taxs1, 'thumbnail_id', true );

            if( $thumbnail_id > 0 ) {
                // Get the attchement image Url
                $term_img  = wp_get_attachment_url( $thumbnail_id );



            }

            if (!empty($thumbnail_id)) {
                $image_style = "style='background-image:url(" . esc_url($term_img) . ")'";
            } else {
                $image_style = '';
            }
            ?>
            <div class="card-wrap" <?php echo $image_style; ?>>
                <div class="card__image">
                <?php if($category) { ?>    
                <div class="card-arc-content">
                   <h2><a href="<?php echo esc_url( $category_link ); ?>" class="card__title"><?php echo esc_html($category->name ); ?></a></h2>
                    <a href="<?php echo esc_url( $category_link ); ?>" class="category-shop-now"><?php esc_html_e(' Shop Now ', 'prato-store') ?></a>
                    </div>
                    <?php } ?>
                </div>
            </div>
        <?php } 


        
        if($taxs2){
            $category = get_term_by( 'id', $taxs2 , 'product_cat' );

        

            // Get the URL of this category
            $category_link = get_category_link( $taxs2 );


            // Get the thumbnail Id
            $thumbnail_id  = get_term_meta( $taxs2, 'thumbnail_id', true );

            if( $thumbnail_id > 0 ) {
                // Get the attchement image Url
                $term_img  = wp_get_attachment_url( $thumbnail_id );



            }

            if (!empty($thumbnail_id)) {
                $image_style = "style='background-image:url(" . esc_url($term_img) . ")'";
            } else {
                $image_style = '';
            }
            ?>
            <div class="card-wrap" <?php echo $image_style; ?>>
                <div class="card__image">
                <?php if($category) { ?>    
                    <div class="card-arc-content">
                    <h2><a href="<?php echo esc_url( $category_link ); ?>" class="card__title"><?php echo esc_html($category->name ); ?></a></h2>
                    <a href="<?php echo esc_url( $category_link ); ?>" class="category-shop-now"><?php esc_html_e(' Shop Now ', 'prato-store') ?></a>
                    </div>
                    <?php } ?>
                </div>
            </div>
        <?php } 
        } ?>
    </div>
    </div>
    </div>
<?php 

    
}