<?php

namespace Elementor;

if ( ! defined( 'ABSPATH' ) ) exit;


class Deliciko_Title_Widget extends Widget_Base {


    public $base;

    public function get_name() {
        return 'delicios-title';
    }

    public function get_title() {
        return esc_html__( 'Title', 'deliciko' );
    }

    public function get_icon() { 
        return 'eicon-type-tool';
    }

    public function get_categories() {
        return [ 'deliciko-elements' ];
    }

    protected function _register_controls() {

        $this->start_controls_section(
            'section_tab',
            [
                'label' => esc_html__('Title settings', 'deliciko'),
            ]
        );

        $this->add_control(
         'title_style',
         [
            'label' => esc_html__( 'Title style', 'deliciko' ),
            'type' => Custom_Controls_Manager::IMAGECHOOSE,
            'default' => 'style1',
            'options' => [
               'style1'  => [
                  'title' => esc_html__( 'Style 1', 'deliciko' ),
                        'imagelarge' => DELICIKO_IMG. '/admin/title/style1.png',
                        'imagesmall' => DELICIKO_IMG. '/admin/title/style1.png',
                        'width' => '30%',
               ],
               'style2'  => [
                  'title' => esc_html__( 'Style 2', 'deliciko' ),
                        'imagelarge' => DELICIKO_IMG. '/admin/title/style2.png',
                        'imagesmall' => DELICIKO_IMG. '/admin/title/style2.png',
                        'width' => '30%',
               ],
               'style3'  => [
                  'title' => esc_html__( 'Style 3', 'deliciko' ),
                        'imagelarge' => DELICIKO_IMG. '/admin/title/style3.png',
                        'imagesmall' => DELICIKO_IMG. '/admin/title/style3.png',
                        'width' => '30%',
               ],
             
           
            ],
         ]
       );
   
      $this->add_control(
			'title', [
				'label'			=> esc_html__( 'Heading Title', 'deliciko' ),
				'type'			=> Controls_Manager::TEXTAREA,
				'label_block'	=> true,
				'placeholder'	=> esc_html__( 'Breakfast', 'deliciko' ),
				'default'	     => esc_html__( 'why {choose} us', 'deliciko' ),
			]
      );
      
      $this->add_control(
			'title_icon',
			[
				'label' => esc_html__( 'Icon', 'deliciko' ),
				'type' => \Elementor\Controls_Manager::ICON,
            'default' => 'icon icon-title',
            'condition' => [
               'title_style' => ['style1']
              ]
			]
		);
        
      $this->add_control('show_title_border',
      [
      'label'       => esc_html__('Show title border', 'deliciko'),
      'type'        => Controls_Manager::SWITCHER,
      'label_on'    => esc_html__('Yes', 'deliciko'),
      'label_off'   => esc_html__('No', 'deliciko'),
      'default'     => 'yes',
      'condition' => [
         'title_style' => ['style2']
        ]
       
      ]
      );
        
      $this->add_responsive_control(
			'title_align', [
				'label'			 => esc_html__( 'Alignment', 'deliciko' ),
				'type'			 => Controls_Manager::CHOOSE,
				'options'		 => [

					'left'		 => [
						'title'	 => esc_html__( 'Left', 'deliciko' ),
						'icon'	 => 'fa fa-align-left',
					],
					'center'	 => [
						'title'	 => esc_html__( 'Center', 'deliciko' ),
						'icon'	 => 'fa fa-align-center',
					],
					'right'		 => [
						'title'	 => esc_html__( 'Right', 'deliciko' ),
						'icon'	 => 'fa fa-align-right',
					],
					'justify'	 => [
						'title'	 => esc_html__( 'Justified', 'deliciko' ),
						'icon'	 => 'fa fa-align-justify',
					],
				],
				'default'		 => 'center',
                'selectors' => [
                    '{{WRAPPER}} .ts-section-title' => 'text-align: {{VALUE}};',
                    '{{WRAPPER}} .section-title' => 'text-align: {{VALUE}};',
                    
				],
			]
        );

      $this->end_controls_section();
   
		$this->start_controls_section(
			'section_title_style', [
				'label'	 => esc_html__( 'Title', 'deliciko' ),
				'tab'	 => Controls_Manager::TAB_STYLE,
			]
      );

      $this->add_control(
			'title_color', [
				'label'		 => esc_html__( 'Title color', 'deliciko' ),
				'type'		 => Controls_Manager::COLOR,
				'selectors'	 => [
					'{{WRAPPER}} .section-title' => 'color: {{VALUE}};',
					'{{WRAPPER}} .ts-section-title i' => 'color: {{VALUE}};',
				],
			]
      );

       
      $this->add_group_control(
			Group_Control_Typography::get_type(), [
			'name'		 => 'title_typography',
			'selector'	 => '{{WRAPPER}} .section-title',
			]
			);
			
			$this->add_responsive_control(
				'title_margin',
				[
					'label' => esc_html__( 'Tilte Margin', 'deliciko' ),
					'type' => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%', 'em' ],
					'condition' => [
						'title_style' => ['style3']
					],
					'selectors' => [
						'{{WRAPPER}} .ts-section-title .section-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					],
				]
				);

      $this->end_controls_section();  

      $this->start_controls_section(
			'section_title_border_style', [
				'label'	 => esc_html__( 'Title border', 'deliciko' ),
            'tab'	 => Controls_Manager::TAB_STYLE,
            'condition' => [
               'title_style' => ['style2', 'style3']
              ]
			]
      );

      $this->add_responsive_control(
			'title_border_color', [

				'label'		 => esc_html__( 'Title border color', 'deliciko' ),
				'type'		 => Controls_Manager::COLOR,
				'selectors'	 => [

               '{{WRAPPER}} .title-border:after' => 'background: {{VALUE}};',
               '{{WRAPPER}} .title-bar span.title-left-bar, .title-bar span' => 'background: {{VALUE}};',
				],
			]
        );

      $this->add_responsive_control(
			'title_boder_width',
			[
				'label' => __( 'Border width', 'deliciko' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 600,
						'step' => 1,
					],
					
				],
				'default' => [
					'unit' => 'px',
					'size' => 50,
				],
				'selectors' => [
					'{{WRAPPER}} .title-border:after' => 'width: {{SIZE}}{{UNIT}};',
					'{{WRAPPER}} .title-bar span.title-left-bar, .title-bar span.title-right-bar' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
      );

      $this->add_control(
			'title_boder_height',
			[
				'label' => __( 'Border height', 'deliciko' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 600,
						'step' => 1,
					],
					
				],
				'default' => [
					'unit' => 'px',
					'size' => 3,
				],
				'selectors' => [
					'{{WRAPPER}} .title-border:after' => 'height: {{SIZE}}{{UNIT}};',
					'{{WRAPPER}} .title-bar span.title-left-bar, .title-bar span.title-right-bar' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
      );
      $this->add_responsive_control(
			'title_margin_bottom',
			[
				'label' => __( 'Border bottom', 'deliciko' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ '%','px' ],
				'range' => [
					'%' => [
						'min' => -100,
						'max' => 600,
						'step' => 1,
					],
					
				],
				'default' => [
					'unit' => '%',
					'size' => -26,
				],
			
				'selectors' => [
					'{{WRAPPER}} .title-border:after' => 'bottom: {{SIZE}}{{UNIT}};',
					
				],
			]
      );
    
      $this->end_controls_section();  

      $this->start_controls_section(
			'section_title_highlight_style', [
				'label'	 => esc_html__( 'Title highlight', 'deliciko' ),
				'tab'	 => Controls_Manager::TAB_STYLE,
			]
      );

      $this->add_control(
			'title_highlight_color', [
				'label'		 => esc_html__( 'Highlight color', 'deliciko' ),
				'type'		 => Controls_Manager::COLOR,
				'selectors'	 => [
					'{{WRAPPER}} .section-title span' => 'color: {{VALUE}};',
			   ],
			]
        );


      $this->end_controls_section(); 

      $this->start_controls_section(
			'section_title_icon_style', [
				'label'	 => esc_html__( 'Icon', 'deliciko' ),
            'tab'	 => Controls_Manager::TAB_STYLE,
            'condition' => [
               'title_style' => ['style1']
              ]
			]
      );

      
      $this->add_control(
			'content_title_icon_headingl',
			[
				'label' => esc_html__( 'Icon typhography', 'deliciko' ),
				'type' => \Elementor\Controls_Manager::HEADING,
            'separator' => 'before',
            'condition' => [
               'title_style' => ['style1']
              ]
            
			]
      );
 
      $this->add_group_control(
			Group_Control_Typography::get_type(), [
			'name'		 => 'title_icon_typography',
         'selector'	 => '{{WRAPPER}} .ts-section-title i',
         'condition' => [
            'title_style' => ['style1']
           ]
			]
      );

      $this->add_control(
			'title_icon_color', [
				'label'		 => esc_html__( 'Icon color', 'deliciko' ),
				'type'		 => Controls_Manager::COLOR,
				'selectors'	 => [
					'{{WRAPPER}} .ts-section-title i' => 'color: {{VALUE}};',
					
				],
			]
      );
      
      $this->add_responsive_control(
			'icon_margin',
			[
				'label' => esc_html__( 'Margin', 'deliciko' ),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'selectors' => [
					'{{WRAPPER}} .ts-section-title i' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
      );
     

      $this->end_controls_section();  

   } 

   protected function render( ) { 
      $settings       = $this->get_settings();
      $title_style    = $settings['title_style']; 
      $title          = $settings['title']; 
      $title_icon     = $settings['title_icon']; 
      $title_align     = $settings['title_align']; 
      $show_title_border          = $settings['show_title_border']; 
      $title_1        = str_replace(['{', '}'], ['<span>', '</span>'], $title); 
      $title_border = '';
      if($title_style=='style2' && $show_title_border=='yes'): 
         $title_border = 'title-border';
      endif;   
     
   ?>

   <div class="ts-section-title title-<?php echo esc_attr( $title_align); ?>">
      <h2 class="section-title <?php echo esc_attr($title_border); ?>">
        <?php echo wp_kses_post($title_1); ?>
     </h2>
      <?php if($title_style=='style1'): ?>
         <i class="<?php echo esc_attr($title_icon); ?>"></i>
			<?php endif; ?>
      <?php if($title_style=='style3'): ?>
         <div class="title-bar">
					 <span class="title-left-bar"></span>
					 <span class="title-middle-bar"></span>
					 <span class="title-right-bar"></span>
				 </div>
			<?php endif; ?>
			
   </div>
    
    <?php  
    }
    protected function _content_template() { }
}