<?php

/*
Widget Name: Heading
Description: Display one or more heading depicting a percentage value in a multi-column grid.
Author: ThemesFlat
Author URI: https://www.themesflatthemes.com
*/
namespace ThemesflatAddons\Widgets;

use  Elementor\Widget_Base ;
use  Elementor\Controls_Manager ;
use  Elementor\Scheme_Color ;
use  Elementor\Group_Control_Typography ;
use  Elementor\Scheme_Typography ;
use  Elementor\Utils;

if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Exit if accessed directly
class TFL_Heading_V2_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-heading-v2';
    }
    
    public function get_title()
    {
        return __( 'TFL Heading V2', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-heading';
    }
    
    public function get_categories()
    {
        return array( 'themesflat-addons' );
    }
    
    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/heading-addon/';
    }
    
    public function get_script_depends()
    {
        return [ 'tfl-waypoints', 'tfl-frontend-scripts' ];
    }
    
    public function get_style_depends()
    {
        return [ 'tfl-animate-styles', 'tfl-frontend-styles', 'tfl-heading-styles' ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_heading', [
            'label' => __( 'Heading', 'themesflat' ),
        ] );

        $this->add_control( 'prefix_image', [
            'label'       => __( 'Prefix Image', 'themesflat' ),
            'type'        => Controls_Manager::MEDIA,
            'label_block' => true,
            'dynamic'     => [
                'active' => true,
            ],
        ] );

        $this->add_group_control(
            \Elementor\Group_Control_Image_Size::get_type(),
            [
                'name' => 'thumbnail', // Usage: `{name}_size` and `{name}_custom_dimension`, in this case `thumbnail_size` and `thumbnail_custom_dimension`.
                'exclude' => [ 'custom' ],
                'include' => [],
                'default' => 'large',
            ]
        );

        $this->add_control( 'subtitle', [
            'type'        => Controls_Manager::TEXT,
            'label'       => __( 'Subheading', 'themesflat' ),
            'label_block' => true,
            'description' => __( 'A subtitle displayed above the title heading.', 'themesflat' ),
            'default'     =>'About Company',
            'dynamic'     => [
                'active' => true,
            ],
        ] );

        $this->add_control( 'heading', [
            'type'        => Controls_Manager::TEXT,
            'label'       => __( 'Heading Title', 'themesflat' ),
            'label_block' => true,
            'separator'   => 'before',
            'default'     => 'Professional Service Company <br> For Landscaping',
            'dynamic'     => [
            'active' => true,
        ],
        ] );


        $this->add_control( 'heading_settings', [
            'label'     => __( 'Settings', 'themesflat' ),
            'type'      => Controls_Manager::HEADING,
            'separator' => 'before',
        ] );
        $this->add_control( 'align', [
            'label'   => __( 'Alignment', 'themesflat' ),
            'type'    => Controls_Manager::CHOOSE,
            'options' => [
            'left'    => [
            'title' => __( 'Left', 'themesflat' ),
            'icon'  => 'fa fa-align-left eicon-text-align-left',
        ],
            'center'  => [
            'title' => __( 'Center', 'themesflat' ),
            'icon'  => 'fa fa-align-center eicon-text-align-center',
        ],
            'right'   => [
            'title' => __( 'Right', 'themesflat' ),
            'icon'  => 'fa fa-align-right eicon-text-align-right',
        ],
        ],
            'default' => 'center',
        ] );
        $this->add_control( 'widget_animation', [
            "type"    => Controls_Manager::SELECT,
            "label"   => __( "Animation Type", "themesflat" ),
            'options' => tfl_get_animation_options(),
            'default' => 'none',
        ] );

        $this->end_controls_section();

        $this->start_controls_section( 'section_styling', [
            'label' => __( 'Title', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'title_tag', [
            'label'   => __( 'Title HTML Tag', 'themesflat' ),
            'type'    => Controls_Manager::SELECT,
            'options' => [
            'h1'  => __( 'H1', 'themesflat' ),
            'h2'  => __( 'H2', 'themesflat' ),
            'h3'  => __( 'H3', 'themesflat' ),
            'h4'  => __( 'H4', 'themesflat' ),
            'h5'  => __( 'H5', 'themesflat' ),
            'h6'  => __( 'H6', 'themesflat' ),
            'div' => __( 'div', 'themesflat' ),
        ],
            'default' => 'h3',
        ] );


        $this->add_control( 'spacing', [
            'label'       => __( 'Spacing', 'themesflat' ),
            'description' => __( 'spacing between 2 rows.', 'themesflat' ),
            'type'        => Controls_Manager::NUMBER,
//            'default'     => 13,
            'selectors'   => [
                '{{WRAPPER}} .tfl-heading-v2.tfl-style1 .tfl-subtitle' => '    margin-bottom: {{VALUE}}px;',
            ],
        ] );

        $this->add_control( 'heading_color', [
            'label'     => __( 'Heading Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
            '{{WRAPPER}} .tfl-heading-v2 .tfl-title' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'heading_typography',
            'label'    => __( 'Typography', 'themesflat' ),
            'selector' => '{{WRAPPER}} .tfl-heading-v2 .tfl-title',
        ] );
        $this->end_controls_section();

        $this->start_controls_section( 'section_subtitle', [
            'label' => __( 'Subtitle', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'subtitle_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-heading-v2 .tfl-subtitle' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'subtitle_typography',
            'selector' => '{{WRAPPER}} .tfl-heading-v2 .tfl-subtitle',
        ] );
        $this->end_controls_section();

         // Start Image Style       
        $this->start_controls_section( 
            'section_style_image',
            [
                'label' => esc_html__('Image', 'themesflat-elementor'),
                'tab' => \Elementor\Controls_Manager::TAB_STYLE,
            ]
        ); 

        $this->add_responsive_control( 
            'image_width',
            [
                'label' => esc_html__( 'Image Width', 'themesflat-elementor' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', '%' ],
                'range' => [
                    'px' => [
                        'min' => 0,
                        'max' => 2000,
                        'step' => 1,
                    ],
                    '%' => [
                        'min' => 0,
                        'max' => 100,
                        'step' => 1,
                    ],
                ],
                'devices' => [ 'desktop', 'tablet', 'mobile' ],
                'desktop_default' => [
                    'unit' => '%',
                ],
                'tablet_default' => [
                    'unit' => '%',
                ],
                'mobile_default' => [
                    'unit' => '%',
                ],
                'selectors' => [
                    '{{WRAPPER}} .tfl-subtitle img' => 'max-width: {{SIZE}}{{UNIT}};',
                    '{{WRAPPER}} .tfl-subtitle img' => 'width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );    

        $this->end_controls_section();

    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters( 'tfl_heading_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( "addons/heading-v2/style1", $args );
    }
    
    protected function content_template()
    {
    }

}