<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
use Sifency\Traits\Sifency_Addons_Master_Typography;
use Sifency\Traits\Sifency_Addons_Flex_Controls;
use Elementor\Controls_Manager;
trait Sifency_Addons_Get_The_Title {
	use Sifency_Addons_Master_Typography;

	protected function add_sifency_addons_title_controls() {
		$this->add_control(
			'show_title',
			array(
				'label'        => esc_html__( 'Show Title', 'sifency-addons' ),
				'type'         => Controls_Manager::SWITCHER,
				'return_value' => 'yes',
				'default'      => 'yes',
			)
		);

		$this->add_control(
			'title_tag',
			array(
				'label'     => esc_html__( 'Title HTML Tag', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'h3',
				'options'   => array(
					'h1'   => 'H1',
					'h2'   => 'H2',
					'h3'   => 'H3',
					'h4'   => 'H4',
					'h5'   => 'H5',
					'h6'   => 'H6',
					'div'  => 'DIV',
					'span' => 'SPAN',
				),
				'condition' => array( 'show_title' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'heading_justify',
			array(
				'label'     => esc_html__( 'Justify Content', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'flex-start'    => array(
						'title' => 'Start',
						'icon'  => 'eicon-flex eicon-justify-start-h',
					),
					'center'        => array(
						'title' => 'Center',
						'icon'  => 'eicon-flex eicon-justify-center-h',
					),
					'flex-end'      => array(
						'title' => 'End',
						'icon'  => 'eicon-flex eicon-justify-end-h',
					),
					'space-between' => array(
						'title' => 'Space Between',
						'icon'  => 'eicon-flex eicon-justify-space-between-h',
					),
					'space-around'  => array(
						'title' => 'Space Around',
						'icon'  => 'eicon-flex eicon-justify-space-around-h',
					),
				),
				'selectors' => array( '.sifency-banner-image' => 'justify-content: {{VALUE}};' ),
				'condition' => array( 'show_title' => 'yes' ),
			)
		);

		$this->add_responsive_control(
			'heading_align',
			array(
				'label'     => esc_html__( 'Align Items', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'flex-start' => array(
						'title' => 'Top',
						'icon'  => 'eicon-flex eicon-align-start-v',
					),
					'center'     => array(
						'title' => 'Middle',
						'icon'  => 'eicon-flex eicon-align-center-v',
					),
					'flex-end'   => array(
						'title' => 'Bottom',
						'icon'  => 'eicon-flex eicon-align-end-v',
					),
					'stretch'    => array(
						'title' => 'Stretch',
						'icon'  => 'eicon-flex eicon-align-stretch-v',
					),
				),
				'selectors' => array( '.sifency-banner-image' => 'align-items: {{VALUE}};' ),
				'condition' => array( 'show_title' => 'yes' ),
			)
		);
	}
	protected function sifency_addons_post_title_style_controller() {
		$this->add_sifency_addons_master_typography_controls(
			array(
				'prefix'    => 'the_title_style_',
				'label'     => esc_html__( 'The TItle', 'sifency-addons' ),
				'selector'  => '.sifency-heading-style',
				'exclude'   => array( 'alignment' ),
				'condition' => array( 'show_title' => 'yes' ),
			)
		);
	}
	protected function render_sifency_addons_post_title() {
		$settings   = $this->get_settings_for_display();
		$tag        = ! empty( $settings['title_tag'] ) ? $settings['title_tag'] : 'h3';
		$post_id    = get_the_ID();
		$post_title = $post_id ? get_the_title( $post_id ) : '';

		if ( 'yes' === $settings['show_title'] && ! empty( $post_title ) ) {
			printf(
				'<%1$s class="sifency-heading-style">%2$s</%1$s>',
				tag_escape( $tag ),
				esc_html( $post_title )
			);
		}
	}
}
