<?php

/*
Widget Name: IconBox
Description: Display one or more iconbox 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\Utils ;
use  Elementor\Scheme_Color ;
use  Elementor\Group_Control_Typography ;
use  Elementor\Scheme_Typography ;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Exit if accessed directly
class TFL_IconBox_V2_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-iconbox-v2';
    }

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

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

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

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

    protected function register_controls()
    {
        $this->start_controls_section( 'section_iconbox', [
            'label' => __( 'IconBox 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' )
            ],
        ] );

        // Icon
        $this->add_control(
            'icon',
            [
                'name' => 'icon_name',
                'label' => esc_html__('Icon', 'themesflat-addons'),
                'type' => \Elementor\Controls_Manager::ICONS,
                'default' => [
                    'value' => 'services-growth-1',
                    'library' => 'services',
                ],
            ]
        );


        $this->add_control( 'bg_color', [
            'label'     => __( 'BG Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
                '{{WRAPPER}} .tfl-iconbox-v2' => 'background: {{VALUE}};',
            ],
        ] );

        $this->add_control( 'dark_mode', [
            'label'        => __( 'Dark Mode', 'themesflat' ),
            'type'         => Controls_Manager::SWITCHER,
            'label_on'     => __( 'Yes', 'themesflat' ),
            'label_off'    => __( 'No', 'themesflat' ),
            'return_value' => 'yes',
            'default'      => 'no',
        ] );


//        $this->add_control(
//            'icon',
//            [
//                'name' => 'icon_name_iconbox',
//                'label' => esc_html__('Icon', 'themesflat'),
//                'type' => \Elementor\Controls_Manager::ICONS,
//                'default' => [
//                    'value' => 'flaticon-growth-1',
//                    'library' => 'fa-solid',
//                ]
//            ]
//        );

        $this->add_control( 'iconbox', [
            'type'        => Controls_Manager::TEXT,
            'label'       => __( 'IconBox Title', 'themesflat' ),
            'label_block' => true,
            'separator'   => 'before',
            'default'     => __( 'Professional Landscaping', 'themesflat' ),
            'dynamic'     => [
                'active' => true,
            ],
        ] );

//        $this->add_control( 'button_text', [
//            'type'        => Controls_Manager::TEXT,
//            'label'       => __( 'Button Text', 'themesflat' ),
//            'label_block' => true,
//            'separator'   => 'before',
//            'default'     => __( 'Button Text', 'themesflat' ),
//            'condition'   => [
//                'style' => array('style2','style3'),
//            ],
//            'dynamic'     => [
//                'active' => true,
//            ],
//        ] );

        $this->add_control('link', [
            'label' => __('Link', 'elementor'),
            'type' => Controls_Manager::URL,
            'dynamic' => [
                'active' => true,
            ],
            'placeholder' => __('https://your-link.com', 'elementor'),
            'default' => [
                'url' => '#',
            ],
        ]);

//        $this->add_control( 'bg_image', [
//            'label'       => __( 'BG Image', 'themesflat' ),
//            'type'        => Controls_Manager::MEDIA,
//            'default'     => [
//                'url' => Utils::get_placeholder_image_src(),
//            ],
//            'label_block' => true,
//            'condition'   => [
//                'style' => array('style2','style3'),
//            ],
//            'dynamic'     => [
//                'active' => true,
//            ],
//        ] );


        $this->add_control( 'short_text', [
            'type'        => 'textarea',
            'label'       => __( 'Short Text', 'themesflat' ),
            'description' => __( 'Short text generally displayed below the iconbox title.', 'themesflat' ),
            'default'     => __( 'Sed ut perspiciatis unde omnis iste natus error voluptatem accusantium dolore ', 'themesflat' ),
            'dynamic'     => [
                'active' => true,
            ],
        ] );

        $this->add_control( 'iconbox_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',
                ],
                'center'  => [
                    'title' => __( 'Center', 'themesflat' ),
                    'icon'  => 'fa fa-align-center',
                ],
                'right'   => [
                    'title' => __( 'Right', 'themesflat' ),
                    'icon'  => 'fa fa-align-right',
                ],
                'justify' => [
                    'title' => __( 'Justified', 'themesflat' ),
                    'icon'  => 'fa fa-align-justify',
                ],
            ],
            'default' => 'left',
        ] );
        $this->add_control( 'widget_animation', [
            "type"    => Controls_Manager::SELECT,
            "label"   => __( "Animation Type", "themesflat" ),
            'options' => tfl_get_animation_options(),
            'default' => 'none',
        ] );

        $this->end_controls_section();

        // New section icon style
        $this->start_controls_section( 'section_icon_styling', [
            'label' => __( 'Icon', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );

        $this->add_control( 'svg_color', [
            'label'     => __( 'SVG Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
                '{{WRAPPER}} .tfl-iconbox-v2 .tfl-image-wrapper svg' => 'fill: {{VALUE}};',
            ],
        ] );

        $this->add_control( 'fonticon_color', [
            'label'     => __( 'Font Icon Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
                '{{WRAPPER}} .tfl-iconbox-v2 .tfl-image-wrapper i:before' => 'color: {{VALUE}};',
            ],
        ] );

        $this->add_control(
            'icon_svg_size',
            [
                'label' => __( 'Icon SVG Font Size', 'plugin-name' ),
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => [ 'px', 'em', 'rem' ],
                'range' => [
                    'px' => [
                        'min' => 1,
                        'max' => 200,
                    ],
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 55,
                ],
                'selectors' => [
                    '{{WRAPPER}} .tfl-iconbox-v2 .tfl-image-wrapper svg' => 'width: {{SIZE}}{{UNIT}};'
                ],
                'selectors' => [
                    '{{WRAPPER}} .tfl-iconbox-v2 .tfl-image-wrapper i' => 'font-size: {{SIZE}}{{UNIT}};'
                ],

            ]
        );


        $this->end_controls_section();
        // End 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( 'iconbox_color', [
            'label'     => __( 'IconBox Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'default'   => '',
            'selectors' => [
                '{{WRAPPER}} .tfl-iconbox-v2 .tfl-title,
            {{WRAPPER}} .tfl-iconbox-v2.tfl-style1 .tfl-content-wrapper .tfl-title a,
            {{WRAPPER}} .tfl-iconbox-v2.tfl-style2 .tfl-content-wrapper .tfl-title a,
            {{WRAPPER}} .tfl-iconbox-v2.tfl-style4 .tfl-content-wrapper .tfl-title a,
            {{WRAPPER}} .tfl-iconbox-v2.tfl-style3 .tfl-content-wrapper .tfl-title a' => 'color: {{VALUE}};',
            ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'iconbox_typography',
            'label'    => __( 'Typography', 'themesflat' ),
            'selector' => '{{WRAPPER}} .tfl-iconbox-v2 .tfl-content-wrapper .tfl-title a',
        ] );
        $this->end_controls_section();



        $this->start_controls_section( 'section_short_text', [
            'label' => __( 'Short Text', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'text_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-iconbox-v2 .tfl-text' => 'color: {{VALUE}};',
            ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'text_typography',
            'selector' => '{{WRAPPER}} .tfl-iconbox-v2 .tfl-text',
        ] );
        $this->end_controls_section();
    }

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

    protected function content_template()
    {
    }

}