<?php
/**
 * The template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site may use a
 * different template.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package Glowify WP
 */

get_header();

while ( have_posts() ) : the_post();

   
    $page_meta = get_post_meta($post->ID, 'glowify_wp_breadcrumb_options', true) ?: [];

    $enable_breadcrumb = $page_meta['enable_breadcrumb'] ?? true;
    $bc_custom_title = $page_meta['bc_custom_title'] ?? '';

    // Breadcrumb Background
    $bc_page_background = $page_meta['bc_page_background'] ?? false;
    if ($bc_page_background) {
        $bc_page_background_src = wp_get_attachment_image_src($bc_page_background['id'], 'full', false);
    }

    $is_my_account_page = function_exists('is_account_page') && is_account_page();
    $is_logged_in = is_user_logged_in();

?>
  
    <?php if ($enable_breadcrumb == true && !($is_logged_in && $is_my_account_page ) ) : ?>
    <div class="cs_bc_main">
      <div class="cs_height_40 cs_height_lg_30"></div>
      <div class="container">
        <div class="cs_breadcamp_wrap cs_style_1 cs_accent_light_bg cs_bg_filed cs_radius_8" 
          <?php if (!empty($bc_page_background_src) && is_array($bc_page_background_src) && !empty($bc_page_background_src[0])) : ?>
          data-src="<?php echo esc_url($bc_page_background_src[0]); ?>"
          <?php endif; ?>>
        
          <div>
            <h1 class="cs_breadcamp_title cs_fs_54 cs_semibold">
              <?php if (!empty($bc_custom_title)) { 
                  echo wp_kses_post($bc_custom_title); 
              } else { 
                  the_title(); 
              } ?>
            </h1>
            <ol class="breadcrumb cs_fs_18 mb-0">
              <li class="breadcrumb-item"><a href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('Home','glowify-wp');?></a></li>
              <li class="breadcrumb-item active"><?php the_title(); ?></li>
            </ol>
          </div>
        </div>
      </div>
    </div>
    <?php elseif ($enable_breadcrumb == true && ($is_logged_in && $is_my_account_page ) ) : ?>
      <div class="container">
        <div class="cs_height_45 cs_height_lg_45"></div>
        <ol class="breadcrumb cs_fs_18 mb-0">
          <li class="breadcrumb-item"><a href="<?php echo esc_url(home_url('/')); ?>"><?php esc_html_e('Home','glowify-wp');?></a></li>
          <li class="breadcrumb-item"><a href="<?php echo esc_url( get_permalink( get_option('woocommerce_myaccount_page_id') ) ); ?>"><?php esc_html_e('Account', 'glowify-wp');?></a></li>
          <li class="breadcrumb-item active"><?php the_title(); ?></li>
        </ol>
      </div>
    <?php endif; ?>
    
    <div class="glowify-internal-area glowify-entry-page">
        <div class="container-elementor">
            <div class="row">
                <div class="col-12">
                    <?php
                        get_template_part('template-parts/content', 'page');
                    ?>
                </div>
            </div>
        </div>
    </div>

<?php endwhile; 

get_footer();
?>
