<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
Use Elementor\Core\Schemes\Typography;
use Elementor\Group_Control_Border;

if (!defined('ABSPATH')) exit; // Exit if accessed directly
if(!function_exists('widgetkit_pro_array_get')) {
    function widgetkit_pro_array_get($array, $key, $default=null){
        if(!is_array($array)) return $default;
        return array_key_exists($key, $array) ? $array[$key] : $default;
    }
}

/**
 * magmax Layout_Single
 * =============
 */
class Widgetkit_Pro_Social_Icon extends Widget_Base
{

    public function get_name()
    {
        return 'magmax-social';
    }

    public function get_title()
    {
        return __('Meteor Social', 'widgetkit-pro');
    }

    public function get_icon()
    {
        return 'eicon-social-icons';
    }

    public function get_categories()
    {
        return ['widgetkit_pro'];
    }

    /**
     * A list of scripts that the widgets is depended in
     *
     * @since 1.3.0
     **/
    /*
        public function get_script_depends() {
            return [ 'imagesloaded' ];
        }
    */

    protected function register_controls()
    {


        /* slides content title subtitle button and button link */
        $this->start_controls_section(
            'section_tab',
            [
                'label' => __('Layout_Single', 'widgetkit-pro'),
            ]
        );
        $this->add_control(
            'social_list',
            [
                'label' => __( 'Repeater List', 'plugin-domain' ),
                'type' => Controls_Manager::REPEATER,
                'fields' => [
                    [
                        'name' => 'social_icon',
                        'label' => __( 'Social Icon', 'plugin-domain' ),
                        'type' => Controls_Manager::ICON,
                        'default' => __( 'fa fa-facebook' , 'plugin-domain' ),
                        'show_label' => true,
                    ],
                    [
                        'name' => 'social_count',
                        'label' => __( 'Count', 'plugin-domain' ),
                        'type' => Controls_Manager::TEXT,
                        'default' => __( '1k' , 'plugin-domain' ),
                        'label_block' => false,
                    ],
                    [
                        'name' => 'social_text',
                        'label' => __( 'Social Text', 'plugin-domain' ),
                        'type' => Controls_Manager::TEXT,
                        'default' => __( 'Follower' , 'plugin-domain' ),
                        'label_block' => false,
                    ],
                    [
                        'name' => 'social_link',
                        'label' => __( 'Social Link', 'plugin-domain' ),
                        'type' => Controls_Manager::TEXT,
                        'default' => __( '#' , 'plugin-domain' ),
                        'label_block' => false,
                    ],
                    [
                        'name' => 'social_bg_color',
                        'label' => __( 'Social Background Color', 'plugin-domain' ),
                        'type' => Controls_Manager::COLOR,
                        'label_block' => false,
                        'selectors' => [
                            '{{{WRAPPER}}} .meteor-social .social-single-item .social-single-item-wrapper' => 'background-color: {{VALUE}}',
                        ],
                    ],
//                    [
//                        'name' => 'socia_hover_bg_color',
//                        'label' => __( 'Social Background Hover Color', 'plugin-domain' ),
//                        'type' => Controls_Manager::COLOR,
//                        'label_block' => false,
//                        'selectors' => [
//                            '{{WRAPPER}} .meteor-social .social-single-item .social-single-item-wrapper:hover' => 'background-color: {{VALUE}}',
//                        ],
//                    ],
//                    [
//                        'name' => 'social_text_color',
//                        'label' => __( 'Social Text Color', 'plugin-domain' ),
//                        'type' => Controls_Manager::COLOR,
//                        'label_block' => false,
//                        'selectors' => [
//                            '{{WRAPPER}} .meteor-social .social-single-item-wrapper i' => 'color: {{VALUE}}',
//                            '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-counter' => 'color: {{VALUE}}',
//                            '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-text' => 'color: {{VALUE}}',
//                        ],
//                    ]
                ],
                'title_field' => '{{{ social_icon }}}',
            ]
        );


        $this->end_controls_section();

        /**
         * Style tab
         * =============
         */
        $this->start_controls_section(
            'section_style',
            [
                'label' => __( 'Typography', 'widgetkit-pro' ),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        /**
         * section title
         */
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Count Typography', 'widgetkit-pro' ),
                'name' => 'social_count_typography',
                'selector' => '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-counter',
            ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __( 'Followers Typography', 'widgetkit-pro' ),
                'name' => 'social_followers_typography',
                'selector' => '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-text',
            ]
        );
        $this->add_control(
            'icon_bg_color',
            [
                'label' => __( 'Icon Background Color', 'widgetkit-pro' ),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-icon-wrapper' => 'background-color: {{VALUE}}',
                ],
            ]
        );
        $this->add_control(
            'icon-box-width',
            [
                'label' => __( 'Icon Box Width', 'widgetkit-pro' ),
                'type' => Controls_Manager::SLIDER,
                'default' => [
                    'size' => 100,
                ],
                'range' => [
                    'px' => [
                        'min' => 100,
                        'max' => 500,
                        'step' => 1,
                    ],
                ],
                'size_units' => [ 'px' ],
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper' => 'width: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'icon-box-height',
            [
                'label' => __( 'Icon Box Height', 'widgetkit-pro' ),
                'type' => Controls_Manager::SLIDER,
                'default' => [
                    'size' => 100,
                ],
                'range' => [
                    'px' => [
                        'min' => 100,
                        'max' => 500,
                        'step' => 1,
                    ],
                ],
                'size_units' => [ 'px' ],
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper' => 'height: {{SIZE}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'icon_padding',
            [
                'label' => __( 'Icon Padding', 'widgetkit-pro' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-icon-wrapper' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'icon_margin',
            [
                'label' => __( 'Icon Margin', 'widgetkit-pro' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper .social-icon' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->add_control(
            'social_box_margin',
            [
                'label' => __( 'Social Box Margin', 'widgetkit-pro' ),
                'type' => Controls_Manager::DIMENSIONS,
                'size_units' => [ 'px', '%', 'em' ],
                'selectors' => [
                    '{{WRAPPER}} .meteor-social .social-single-item-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                ],
            ]
        );
        $this->end_controls_section();

    }

    protected function render()
    {
        $settings = $this->get_settings();
        $social_list = widgetkit_pro_array_get($settings, 'social_list');
    ?>
    <?php
        include( plugin_dir_path( __FILE__ ) . '../layout/social.php');
        ?>
    <?php
    }
    protected function _content_template()
    {
    }
}
