<?php

namespace ThemesflatAddons\Widgets;

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

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

// Exit if accessed directly
class TFL_Service_V2_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-service-v2';
    }

    public function get_title()
    {
        return __('Service V2', 'themesflat');
    }

    public function get_icon()
    {
        return 'tfl-icon-briefcase';
    }

    public function get_categories()
    {
        return array('themesflat-addons');
    }

    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/service-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-service-styles','tfl-services-styles'];
    }

    protected function register_controls()
    {
        $this->start_controls_section('section_service', [
            'label' => __('Service V2', 'themesflat'),
        ]);

        $this->add_control('style', [
            'type' => Controls_Manager::SELECT,
            'label' => __('Choose Style', 'themesflat'),
            'default' => 'style1',
            'options' => [
                'style1' => __('Style 1', 'themesflat'),
                'style2' => __('Style 2', 'themesflat'),
//                'style3' => __('Style 3', 'themesflat'),
            ],
        ]);

        $this->add_control('items', [
            'label' => __('Items', 'themesflat'),
            'type' => Controls_Manager::NUMBER,
            'min' => 1,
            'max' => 4,
            'step' => 1,
            'default' => 4,
        ]);

        $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_general_styling', [
            'label' => __('General', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);

        $this->add_control( 'icon_bg_color', [
            'label'     => __( 'Icon BG Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .top-content .wrap-icon' => 'background: {{VALUE}};',
            ],
            'condition'  => [
                'style' => 'style1',
            ],
        ] );

        $this->add_control( 'icon_color', [
            'label'     => __( 'Icon Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .top-content .wrap-icon i' => 'color: {{VALUE}};',
            ],
            'condition'  => [
                'style' => 'style1',
            ],
        ] );

        $this->add_control( 'icon_size', [
            'label'      => __( 'Icon Size', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
                'size' => 60,
            ],
            'range'      => [
                'px' => [
                    'min' => 10,
                    'max' => 80,
                ],
            ],
            'selectors'  => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .top-content .wrap-icon i' => 'font-size: {{SIZE}}{{UNIT}};',
            ],
            'condition'  => [
                'style' => 'style1',
            ],
        ] );

        $this->add_control( 'icon_border_radius', [
            'label'      => __( 'Icon Border Radius', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', '%' ],
            'selectors'  => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .top-content .wrap-icon' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
            ],
            'condition'  => [
                'style' => 'style1',
            ],
        ] );

        $this->add_control('rm_text', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Readmore Text', 'themesflat'),
            'label_block' => true,
            'separator' => 'before',
            'default' => 'Read More',
            'dynamic' => [
                'active' => true,
            ],
        ]);


        // Icon
        $this->add_control(
            'rm_icon',
            [
                'name' => 'icon_name',
                'label' => esc_html__('Icon', 'themesflat-addons'),
                'type' => \Elementor\Controls_Manager::ICONS,
                'default' => [
                    'value' => 'fas fa-arrow-right',
                    'library' => 'fa-solid',
                ],
            ]
        );

        //start - all tabs
        $type = 'box';
        $this->start_controls_tabs($type . '_tabs');
        //start - nomal tab
        $this->start_controls_tab($type . '_normal_tab',['label' => esc_html__('Normal', 'themesflat-elementor'),]);
        $this->add_control( 'bg_color', [
            'label'     => __( 'BG Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner,
                {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content,
                {{WRAPPER}} .service-v2-shortcode.style3 article .service2-inner' => 'background: {{VALUE}};',
            ],
        ] );
        $this->end_controls_tab();
        //end - nomal tab

        //start - hover tab
        $this->start_controls_tab($type . '_hover_tab', ['label' => esc_html__('Hover', 'themesflat-elementor'),]);
        $this->add_control( 'bg_hover_color', [
            'label'     => __( 'BG hover Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner:hover,
                {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content:hover,
                {{WRAPPER}} .service-v2-shortcode.style3 article .service2-inner:hover' => 'background: {{VALUE}};',
            ],
        ] );
        $this->end_controls_tab();
        //end - hover tab
        $this->end_controls_tabs();
        //end - all tabs

        $this->end_controls_section();


        $this->start_controls_section('section_title_styling', [
            'label' => __('Title', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
            $this->add_group_control( Group_Control_Typography::get_type(), [
                'name'     => 'title_typography',
                'selector' => '
                {{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .bottom-content .title h5 a,
                {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content .title h5 a,
                {{WRAPPER}} .service-v2-shortcode.style3 article .service2-inner a',
            ] );

            //start - all tabs
            $type = 'title';
            $this->start_controls_tabs($type . '_tabs');
                //start - nomal tab
                $this->start_controls_tab($type . '_normal_tab',['label' => esc_html__('Normal', 'themesflat-elementor'),]);
                    $this->add_control( 'title_color', [
                        'label'     => __( 'Color', 'themesflat' ),
                        'type'      => Controls_Manager::COLOR,
                        'selectors' => [
                            '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .bottom-content .title h5 a,
                            {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content .title h5 a,
                            {{WRAPPER}} .service-v2-shortcode.style3 article .service2-inner a' => 'color: {{VALUE}};',
                        ],
                    ] );
                $this->end_controls_tab();
                //end - nomal tab

                //start - hover tab
                $this->start_controls_tab($type . '_hover_tab', ['label' => esc_html__('Hover', 'themesflat-elementor'),]);
                    $this->add_control( 'title_hover_color', [
                        'label'     => __( 'Color', 'themesflat' ),
                        'type'      => Controls_Manager::COLOR,
                        'selectors' => [
                            '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .bottom-content .title h5 a:hover,
                            {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content .title h5 a:hover,
                            {{WRAPPER}} .service-v2-shortcode.style3 article .service2-inner a:hover' => 'color: {{VALUE}};',
                        ],
                    ] );
                $this->end_controls_tab();
                //end - hover tab
            $this->end_controls_tabs();
            //end - all tabs
        $this->end_controls_section();

        $this->start_controls_section('section_subtitle_styling', [
            'label' => __('Sub-Title', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
            $this->add_group_control(Group_Control_Typography::get_type(), [
                'name' => 'subtitle_typography',
                'selector' => '
                {{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .bottom-content .sub-content,
                {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content .sub-content',
            ]);
            $this->add_control('subtitle_color', [
                'label' => __('Color', 'themesflat'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .bottom-content .sub-content,
                    {{WRAPPER}} .service-v2-shortcode.style2 .service2-inner .box-content .sub-content' => 'color: {{VALUE}};',
                ],
            ]);
        $this->end_controls_section();


        $this->start_controls_section('section_readmore_styling', [
            'label' => __('Readmore', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
            $this->add_group_control( Group_Control_Typography::get_type(), [
                'name'     => 'readmore_typography',
                'selector' => '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .readmore',
            ] );

            //start - all tabs
            $type = 'readmore';
            $this->start_controls_tabs($type . '_tabs');
                //start - nomal tab
                $this->start_controls_tab($type . '_normal_tab',['label' => esc_html__('Normal', 'themesflat-elementor'),]);
                $this->add_control( 'readmore_color', [
                    'label'     => __( 'Color', 'themesflat' ),
                    'type'      => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .readmore' => 'color: {{VALUE}};',
                    ],
                ] );
                $this->end_controls_tab();
                //end - nomal tab

                //start - hover tab
                $this->start_controls_tab($type . '_hover_tab', ['label' => esc_html__('Hover', 'themesflat-elementor'),]);
                $this->add_control( 'readmore_hover_color', [
                    'label'     => __( 'Color', 'themesflat' ),
                    'type'      => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .service-v2-shortcode.style1 .service2-inner .readmore:hover' => 'color: {{VALUE}};',
                    ],
                ] );
                $this->end_controls_tab();
                //end - hover tab
            $this->end_controls_tabs();
            //end - all tabs
        $this->end_controls_section();

    }

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

    protected function content_template()
    {
    }

}