<?php
/**
 * The template to display the page title and breadcrumbs
 *
 * @package HYGIA
 * @since HYGIA 1.0
 */

// Page (category, tag, archive, author) title

if ( hygia_need_page_title() ) {
	hygia_sc_layouts_showed( 'title', true );
	hygia_sc_layouts_showed( 'postmeta', true );
	?>
	<div class="top_panel_title sc_layouts_row sc_layouts_row_type_normal">
		<div class="content_wrap">
			<div class="sc_layouts_column sc_layouts_column_align_center">
				<div class="sc_layouts_item">
					<div class="sc_layouts_title sc_align_center">
						<?php
						// Post meta on the single post
						if ( is_single() ) {
							?>
							<div class="sc_layouts_title_meta">
							<?php
								hygia_show_post_meta(
									apply_filters(
										'hygia_filter_post_meta_args', array(
											'components' => join( ',', hygia_array_get_keys_by_value( hygia_get_theme_option( 'meta_parts' ) ) ),
											'counters'   => join( ',', hygia_array_get_keys_by_value( hygia_get_theme_option( 'counters' ) ) ),
											'seo'        => hygia_is_on( hygia_get_theme_option( 'seo_snippets' ) ),
										), 'header', 1
									)
								);
							?>
							</div>
							<?php
						}

						// Blog/Post title
						?>
						<div class="sc_layouts_title_title">
							<?php
							$hygia_blog_title           = hygia_get_blog_title();
							$hygia_blog_title_text      = '';
							$hygia_blog_title_class     = '';
							$hygia_blog_title_link      = '';
							$hygia_blog_title_link_text = '';
							if ( is_array( $hygia_blog_title ) ) {
								$hygia_blog_title_text      = $hygia_blog_title['text'];
								$hygia_blog_title_class     = ! empty( $hygia_blog_title['class'] ) ? ' ' . $hygia_blog_title['class'] : '';
								$hygia_blog_title_link      = ! empty( $hygia_blog_title['link'] ) ? $hygia_blog_title['link'] : '';
								$hygia_blog_title_link_text = ! empty( $hygia_blog_title['link_text'] ) ? $hygia_blog_title['link_text'] : '';
							} else {
								$hygia_blog_title_text = $hygia_blog_title;
							}
							?>
							<h1 class="sc_layouts_title_caption<?php echo esc_attr( $hygia_blog_title_class ); ?>"<?php
								if ( hygia_is_on( hygia_get_theme_option( 'seo_snippets' ) ) ) {
									?> itemprop="headline"<?php
								}
							?>>
								<?php
								$hygia_top_icon = hygia_get_term_image_small();
								if ( ! empty( $hygia_top_icon ) ) {
									$hygia_attr = hygia_getimagesize( $hygia_top_icon );
									?>
									<img src="<?php echo esc_url( $hygia_top_icon ); ?>" alt="<?php esc_attr_e( 'Site icon', 'hygia' ); ?>"
										<?php
										if ( ! empty( $hygia_attr[3] ) ) {
											hygia_show_layout( $hygia_attr[3] );
										}
										?>
									>
									<?php
								}
								echo wp_kses_data( $hygia_blog_title_text );
								?>
							</h1>
							<?php
							if ( ! empty( $hygia_blog_title_link ) && ! empty( $hygia_blog_title_link_text ) ) {
								?>
								<a href="<?php echo esc_url( $hygia_blog_title_link ); ?>" class="theme_button theme_button_small sc_layouts_title_link"><?php echo esc_html( $hygia_blog_title_link_text ); ?></a>
								<?php
							}

							// Category/Tag description
							if ( ! is_paged() && ( is_category() || is_tag() || is_tax() ) ) {
								the_archive_description( '<div class="sc_layouts_title_description">', '</div>' );
							}

							?>
						</div>
						<?php

						// Breadcrumbs
						ob_start();
						do_action( 'hygia_action_breadcrumbs' );
						$hygia_breadcrumbs = ob_get_contents();
						ob_end_clean();
						hygia_show_layout( $hygia_breadcrumbs, '<div class="sc_layouts_title_breadcrumbs">', '</div>' );
						?>
					</div>
				</div>
			</div>
		</div>
	</div>
	<?php
}
