<?php
	$html_id = pxl_get_element_id($settings);
	$title = $widget->parse_text_editor( $settings['title'] ?? ''); 

	$sg_post_title = solarva()->get_theme_opt('sg_post_title', 'default');
	$sg_post_title_text = solarva()->get_theme_opt('sg_post_title_text');

	$sg_product_ptitle = solarva()->get_theme_opt('sg_product_ptitle', 'default');
	$sg_product_ptitle_text = solarva()->get_theme_opt('sg_product_ptitle_text');

	$sg_service_title = solarva()->get_theme_opt('sg_service_title', 'default');
	$sg_service_title_text = solarva()->get_theme_opt('sg_service_title_text');

	$sg_portfolio_title = solarva()->get_theme_opt('sg_portfolio_title', 'default');
	$sg_portfolio_title_text = solarva()->get_theme_opt('sg_portfolio_title_text');

	$sg_team_title = solarva()->get_theme_opt('sg_team_title', 'default');
	$sg_team_title_text = solarva()->get_theme_opt('sg_team_title_text');

	$is_singular = false;
	$title_text = ($settings['source_type'] == 'text' && !empty($title)) ? $title : '';
	$is_editor_title = !empty($title_text) ? true : false;

	$is_custom_title = (bool)$settings['is_custom_text'];
	if($is_custom_title) {
		if(is_singular('post') && $sg_post_title == 'custom_text' && !empty($sg_post_title_text) && $settings['source_type'] == 'title') {
			$title_text = $sg_post_title_text;
			$is_singular = true;
			$is_editor_title = false;
		}elseif(is_singular('portfolio') && $sg_portfolio_title == 'custom_text' && !empty($sg_portfolio_title_text) && $settings['source_type'] == 'title') {
			$title_text = $sg_portfolio_title_text;
			$is_singular = true;
			$is_editor_title = false;
		}elseif(is_singular('service') && $sg_service_title == 'custom_text' && !empty($sg_service_title_text) && $settings['source_type'] == 'title') {
			$title_text = $sg_service_title_text;
			$is_singular = true;
			$is_editor_title = false;
		}elseif(is_singular('product') && $sg_product_ptitle == 'custom_text' && !empty($sg_product_ptitle_text) && $settings['source_type'] == 'title') {
			$title_text = $sg_product_ptitle_text;
			$is_singular = true;
			$is_editor_title = false;
		}elseif(is_singular('team') && $sg_team_title == 'custom_text' && !empty($sg_team_title_text) && $settings['source_type'] == 'title') {
			$title_text = $sg_team_title_text;
			$is_singular = true;
			$is_editor_title = false;
		}
	}else {
		if(is_single() && $settings['source_type'] == 'title') {
			$title_text = get_the_title();
			$is_singular = true;
			$is_editor_title = false;
		}
	}

	$title_tag = $settings['title_tag'];
	$title_animate = $settings['title_animate'] ?? '';
	$title_animate_delay = $settings['title_animate_delay'].'ms' ?? '0ms';

	$title_line_style = $settings['title_line_style'] ?? '';

	$title_classes = $settings['title_style'].' '.$title_tag.' '.$title_animate;

	$subtitle_animate_delay = $settings['subtitle_animate_delay'].'ms' ?? '0ms';
	$subtitle_classes = $settings['subtitle_style'].' '.$settings['subtext_style'].' '.$settings['subtitle_animate'];
	$subtitle_text = (!empty($settings['subtitle'])) ? $settings['subtitle'] : 'Add subheading here';
	$is_show_title = true;
	$show_title = (!empty($settings['show_title'])) || false;
	$show_subtitle = (!empty($settings['show_subtitle'])) || false;
	wp_enqueue_script('gsap');
?>
<div id="pxl-<?php echo esc_attr($html_id) ?>" class="pxl-heading">
	<div class="pxl-item--container">
		<div class="pxl-item--inner">
			<?php if($settings['source_type'] === 'text' && $show_subtitle): ?>
				<div class="pxl-item--subtitle <?php echo esc_attr($subtitle_classes); ?>" data-wow-delay="<?php echo esc_attr($subtitle_animate_delay); ?>">
					<?php if($settings['subtitle_style'] === 'pxl-subtitle-default'): ?>
						<svg width="52" height="20" viewBox="0 0 52 20" fill="none" xmlns="http://www.w3.org/2000/svg">
							<rect y="11" width="50" height="1" fill="#86BB46"/>
							<rect class="pxl-move-rect <?php echo esc_attr($settings['subtitle_marker_effect'] ?? ''); ?>" x="44.7782" y="4" width="10" height="10" transform="rotate(45 44.7782 4)" fill="#86BB46"/>
						</svg>
					<?php endif; ?>
					<span class="pxl-item--subtext">
						<?php echo esc_attr(pxl_print_html($subtitle_text)); ?>
					</span>
				</div>
			<?php endif; ?>
			<?php if($show_title): ?>
				<<?php echo esc_attr($title_tag); ?> class="pxl-item--title <?php echo esc_attr($title_classes); ?>" 
				data-wow-delay="<?php echo esc_attr($title_animate_delay); ?>">
					<?php if($is_singular || $is_editor_title) : ?>
						<?php pxl_print_html($title_text); ?>
					<?php elseif(!$is_singular && $settings['source_type'] == 'title'): ?>
						<?php 
							$titles = solarva()->page->get_title();
							if(!empty($_GET['blog_title'])) {
								$blog_title = $_GET['blog_title'];
								$custom_title = explode('_', $blog_title);
								foreach ($custom_title as $index => $value) {
									$arr_str_b[$index] = $value;
								}
								$str = implode(' ', $arr_str_b);
								echo wp_kses_post($str);
							} else {
								pxl_print_html($titles['title']);
							}
						?>
					<?php else : ?>
						<?php echo esc_html__('Add heading here.', 'solarva'); ?>
					<?php endif; ?>
				</<?php echo esc_attr($title_tag); ?>>
			<?php endif; ?>
		</div>
	</div>
</div>