<?php

/*
Widget Name: Stats Bars
Description: Display multiple stats bars that talk about skills or other percentage stats.
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 ;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Exit if accessed directly
class TFL_Stats_Bars_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-stats-bars';
    }
    
    public function get_title()
    {
        return __( 'Stats Bars', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-stats-bars';
    }
    
    public function get_categories()
    {
        return array( 'themesflat-addons' );
    }
    
    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/statistics-addons/';
    }
    
    public function get_script_depends()
    {
        return [ 'tfl-waypoints', 'tfl-frontend-scripts', 'tfl-stats-bars-scripts' ];
    }
    
    public function get_style_depends()
    {
        return [ 'tfl-animate-styles', 'tfl-frontend-styles', 'tfl-stats-bars-styles' ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_stats_bars', [
            'label' => __( 'Stats Bars', 'themesflat' ),
        ] );
        $repeater = new Repeater();
        $repeater->add_control( 'stats_title', [
            'label'       => __( 'Stats Title', 'themesflat' ),
            'type'        => Controls_Manager::TEXT,
            'description' => __( 'The title for the stats bar', 'themesflat' ),
            'default'     => __( 'My stats title', 'themesflat' ),
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'percentage_value', [
            'label'       => __( 'Percentage Value', 'themesflat' ),
            'type'        => Controls_Manager::NUMBER,
            'min'         => 1,
            'max'         => 100,
            'step'        => 1,
            'default'     => 30,
            'description' => __( 'The percentage value for the stats.', 'themesflat' ),
        ] );
        $repeater->add_control( 'bar_color', [
            'label'   => __( 'Bar Color', 'themesflat' ),
            'type'    => Controls_Manager::COLOR,
            'default' => '#f94213',
        ] );
        $this->add_control( 'stats_bars', [
            'type'        => Controls_Manager::REPEATER,
            'default'     => [ [
            'stats_title'      => __( 'Web Design', 'themesflat' ),
            'percentage_value' => 87,
        ], [
            'stats_title'      => __( 'SEO Services', 'themesflat' ),
            'percentage_value' => 76,
        ], [
            'stats_title'      => __( 'Brand Marketing', 'themesflat' ),
            'percentage_value' => 40,
        ] ],
            'fields'      => $repeater->get_controls(),
            'title_field' => '{{{ stats_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_stats_bar_styling', [
            'label' => __( 'Stats Bar', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'stats_bar_bg_color', [
            'label'     => __( 'Stats Bar Background Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-bg' => 'background-color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'stats_bar_spacing', [
            'label'      => __( 'Stats Bar Spacing', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 18,
        ],
            'range'      => [
            'px' => [
            'min' => 5,
            'max' => 128,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar' => 'margin-bottom: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'stats_bar_height', [
            'label'      => __( 'Stats Bar Height', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 10,
        ],
            'range'      => [
            'px' => [
            'min' => 1,
            'max' => 96,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-bg, {{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-content' => 'height: {{SIZE}}{{UNIT}};',
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-bg'                                                                    => 'margin-top: -{{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'stats_bar_border_radius', [
            'label'      => __( 'Stats Bar Border Radius', 'themesflat' ),
            'type'       => Controls_Manager::DIMENSIONS,
            'size_units' => [ 'px', '%' ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-bg, {{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-bar-content' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_stats_title', [
            'label' => __( 'Stats Title', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'stats_title_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-title' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'stats_title_typography',
            'selector' => '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-title',
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_stats_percentage', [
            'label' => __( 'Stats Percentage', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'stats_percentage_color', [
            'label'     => __( 'Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-title span' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'stats_percentage_typography',
            'selector' => '{{WRAPPER}} .tfl-stats-bars .tfl-stats-bar .tfl-stats-title span',
        ] );
        $this->end_controls_section();
    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters( 'tfl_stats_bars_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( 'addons/stats-bars/loop', $args );
    }
    
    protected function content_template()
    {
    }

}