<?php

/*
Widget Name: Tab Slider
Description: Display tabbed content as a touch enabled responsive slider.
Author: ThemesFlat
Author URI: https://www.themesflatthemes.com
*/
namespace ThemesflatAddons\Widgets;

use  Elementor\Repeater ;
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_Tab_Slider_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-tab-slider';
    }
    
    public function get_title()
    {
        return __( 'Tab Slider', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-tab-slider1';
    }
    
    public function get_categories()
    {
        return array( 'themesflat-addons' );
    }
    
    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/';
    }
    
    public function get_script_depends()
    {
        return [ 'tfl-jquery-slick', 'tfl-frontend-scripts', 'tfl-tab-slider-scripts' ];
    }
    
    public function get_style_depends()
    {
        return [
            'tfl-icomoon-styles',
            'tfl-slick-carousel-styles',
            'tfl-frontend-styles',
            'tfl-slick-carousel-custom-styles',
            'tfl-tabs-slider-styles'
        ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_tabs', [
            'label' => __( 'Tabs', 'themesflat' ),
        ] );
        $this->add_control( 'style', [
            'type'    => Controls_Manager::SELECT,
            'label'   => __( 'Choose Style', 'themesflat' ),
            'default' => 'style1',
            'options' => [
            'style1' => __( 'Tab Style 1', 'themesflat' ),
            'style2' => __( 'Tab Style 2', 'themesflat' ),
            'style3' => __( 'Tab Style 3', 'themesflat' ),
        ],
        ] );
        $repeater = new Repeater();
        $repeater->add_control( 'icon_type', [
            'label'   => __( 'Tab Icon Type', 'themesflat' ),
            'type'    => Controls_Manager::SELECT,
            'default' => 'none',
            'options' => [
            'none'       => __( 'None', 'themesflat' ),
            'icon'       => __( 'Icon', 'themesflat' ),
            'icon_image' => __( 'Icon Image', 'themesflat' ),
        ],
        ] );
        $repeater->add_control( 'icon_image', [
            'label'       => __( 'Tab Image', 'themesflat' ),
            'type'        => Controls_Manager::MEDIA,
            'default'     => [
            'url' => Utils::get_placeholder_image_src(),
        ],
            'label_block' => true,
            'condition'   => [
            'icon_type' => 'icon_image',
        ],
        ] );
        $repeater->add_control( 'selected_icon', [
            'label'            => __( 'Tab Icon', 'themesflat' ),
            'type'             => Controls_Manager::ICONS,
            'label_block'      => true,
            'default'          => [
            'value'   => 'fas fa-home',
            'library' => 'fa-solid',
        ],
            'condition'        => [
            'icon_type' => 'icon',
        ],
            'fa4compatibility' => 'icon',
        ] );
        $repeater->add_control( 'tab_title', [
            'label'       => __( 'Tab Title & Content', 'themesflat' ),
            'type'        => Controls_Manager::TEXT,
            'default'     => __( 'Tab Title', 'themesflat' ),
            'label_block' => true,
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'tab_content', [
            'label'      => __( 'Tab Content', 'themesflat' ),
            'type'       => Controls_Manager::WYSIWYG,
            'default'    => __( 'Tab Content', 'themesflat' ),
            'show_label' => false,
            'dynamic'    => [
            'active' => true,
        ],
        ] );
        $this->add_control( 'tabs', [
            'label'       => __( 'Tab Panes', 'themesflat' ),
            'type'        => Controls_Manager::REPEATER,
            'separator'   => 'before',
            'default'     => [ [
            'tab_title'   => __( 'Tab #1', 'themesflat' ),
            'tab_content' => __( 'I am tabbed content 1. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ], [
            'tab_title'   => __( 'Tab #2', 'themesflat' ),
            'tab_content' => __( 'I am tabbed content 2. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ], [
            'tab_title'   => __( 'Tab #3', 'themesflat' ),
            'tab_content' => __( 'I am tabbed content 3. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat' ),
        ] ],
            'fields'      => $repeater->get_controls(),
            'title_field' => '{{{ tab_title }}}',
        ] );
        $this->add_control( 'upgrade_notice', [
            'type'      => Controls_Manager::RAW_HTML,
            'separator' => 'before',
            'raw'       => '<div style="text-align:center;line-height:1.6;"><p>' . __( 'Unlock new possibilities with premium widgets and styles of <strong>Themesflat Addons for Elementor <i>Premium</i></strong>. ', 'themesflat' ) . '</p><p style="padding-top:15px;"><a class="elementor-button elementor-button-default elementor-button-go-pro" href="https://themesflatelementor.com/pricing/#pricing-plans" target="_blank"><i class="fa fa-hand-o-right" aria-hidden="true"></i>' . __( 'Go Pro', 'themesflat' ) . '</a></p></div>',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_slider_settings', [
            'label' => __( 'Slider Settings', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_SETTINGS,
        ] );
        $this->add_control( 'autoplay', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'no',
            'label'        => __( 'Autoplay?', 'themesflat' ),
            'description'  => __( 'Should the tabs autoplay as in a slideshow.', 'themesflat' ),
        ] );
        $this->add_control( 'pause_on_hover', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'yes',
            'label'        => __( 'Pause on Hover?', 'themesflat' ),
            'condition'    => [
            'autoplay' => 'yes',
        ],
        ] );
        $this->add_control( 'pause_on_focus', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'yes',
            'label'        => __( 'Pause on Focus?', 'themesflat' ),
            'condition'    => [
            'autoplay' => 'yes',
        ],
        ] );
        $this->add_control( 'autoplay_speed', [
            'label'     => __( 'Autoplay speed in ms', 'themesflat' ),
            'type'      => Controls_Manager::NUMBER,
            'default'   => 3000,
            'condition' => [
            'autoplay' => 'yes',
        ],
        ] );
        $this->add_control( 'animation_speed', [
            'label'   => __( 'Autoplay animation speed in ms', 'themesflat' ),
            'type'    => Controls_Manager::NUMBER,
            'default' => 300,
        ] );
        $this->add_control( 'infinite_looping', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'yes',
            'label'        => __( 'Infinite Looping?', 'themesflat' ),
        ] );
        $this->add_control( 'adaptive_height', [
            'type'         => Controls_Manager::SWITCHER,
            'label_off'    => __( 'No', 'themesflat' ),
            'label_on'     => __( 'Yes', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'no',
            'label'        => __( 'Adaptive Height?', 'themesflat' ),
            'description'  => __( 'Enables adaptive height when tabs are of different heights.', 'themesflat' ),
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_tab_title', [
            'label' => __( 'Tab Title', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'title_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav .tfl-tab-title' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'active_title_color', [
            'label'     => __( 'Active Tab Title Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li.slick-active .tfl-tab-slide-nav .tfl-tab-title' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'hover_title_color', [
            'label'     => __( 'Tab Title Hover Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav:hover .tfl-tab-title' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'highlight_color', [
            'label'     => __( 'Tab highlight Border color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '#f94213',
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider.tfl-style1 .slick-dots li.slick-active .tfl-tab-slide-nav:before' => 'background: {{VALUE}};',
            '{{WRAPPER}} .tfl-tab-slider.tfl-style3 .slick-dots li.slick-active .tfl-tab-slide-nav'        => 'border-color: {{VALUE}};',
        ],
            'condition' => [
            'style' => [ 'style1', 'style3' ],
        ],
        ] );
        $this->add_control( 'title_spacing', [
            'label'      => __( 'Tab Title Padding', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', '%', 'em' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
            'isLinked'   => false,
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'title_typography',
            'selector' => '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav .tfl-tab-title',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_tab_content', [
            'label' => __( 'Tab Content', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'content_spacing', [
            'label'      => __( 'Tab Content Padding', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', '%', 'em' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-tab-slider .slick-list .tfl-tab-slide .tfl-tab-slide-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
            'isLinked'   => false,
        ] );
        $this->add_control( 'content_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-list .tfl-tab-slide .tfl-tab-slide-content' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'content_typography',
            'selector' => '{{WRAPPER}} .tfl-tab-slider .slick-list .tfl-tab-slide .tfl-tab-slide-content',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_icon_styling', [
            'label'     => __( 'Icons', 'themesflat' ),
            'tab'       => Controls_Manager::TAB_STYLE,
            'condition' => [
            'style' => [ 'style2', 'style3' ],
        ],
        ] );
        $this->add_control( 'icon_size', [
            'label'      => __( 'Icon or Icon Image size in pixels', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px', '%', 'em' ],
            'range'      => [
            'px' => [
            'min' => 10,
            'max' => 256,
        ],
        ],
            'devices'    => [ 'desktop', 'tablet', 'mobile' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav span.tfl-image-wrapper img' => 'width: {{SIZE}}{{UNIT}};',
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav span.tfl-icon-wrapper i'    => 'font-size: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'icon_color', [
            'label'     => __( 'Icon Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav span.tfl-icon-wrapper i' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'active_icon_color', [
            'label'     => __( 'Active Tab Icon Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li.slick-active .tfl-tab-slide-nav span.tfl-icon-wrapper i' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'hover_icon_color', [
            'label'     => __( 'Hover Tab Icon Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
            '{{WRAPPER}} .tfl-tab-slider .slick-dots li .tfl-tab-slide-nav:hover span.tfl-icon-wrapper i' => 'color: {{VALUE}};',
        ],
        ] );
    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters( 'tfl_tab_slider_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( 'addons/tab-slider/loop', $args );
    }
    
    protected function content_template()
    {
    }

}