<?php

/*
Widget Name: Clients
Description: Display one or more clients depicting a percentage value in a multi-column grid.
Author: ThemesFlat
Author URI: https://www.themesflatthemes.com
*/
namespace ThemesflatAddons\Widgets;

use  Elementor\Repeater ;
use  Elementor\Widget_Base ;
use  Elementor\Controls_Manager ;
use  Elementor\Utils ;
use  Elementor\Group_Control_Typography ;
use  Elementor\Scheme_Color ;
use  Elementor\Scheme_Typography ;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
// Exit if accessed directly
class TFL_Clients_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-clients';
    }
    
    public function get_title()
    {
        return __( 'Clients', 'themesflat' );
    }
    
    public function get_icon()
    {
        return 'tfl-icon-tfl';
    }
    
    public function get_categories()
    {
        return array( 'themesflat-addons' );
    }
    
    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/clients-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-clients-styles' ];
    }
    
    protected function register_controls()
    {
        $this->start_controls_section( 'section_clients', [
            'label' => __( 'Clients', 'themesflat' ),
        ] );
        $repeater = new Repeater();
        $repeater->add_control( 'client_name', [
            'type'        => Controls_Manager::TEXT,
            'label'       => __( 'Client Name', 'themesflat' ),
            'label_block' => true,
            'description' => __( 'The name of the client/customer.', 'themesflat' ),
            'default'     => __( 'My client name', 'themesflat' ),
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'client_link', [
            'label'       => __( 'Client URL', 'themesflat' ),
            'description' => __( 'The website of the client/customer.', 'themesflat' ),
            'type'        => Controls_Manager::URL,
            'label_block' => true,
            'default'     => [
            'url'         => '',
            'is_external' => 'true',
        ],
            'placeholder' => __( 'http://client-link.com', 'themesflat' ),
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $repeater->add_control( 'client_image', [
            'label'       => __( 'Client Logo/Image', 'themesflat' ),
            'description' => __( 'The logo image for the client/customer.', 'themesflat' ),
            'type'        => Controls_Manager::MEDIA,
            'default'     => [
            'url' => Utils::get_placeholder_image_src(),
        ],
            'label_block' => true,
            'dynamic'     => [
            'active' => true,
        ],
        ] );
        $this->add_control( 'clients', [
            'type'        => Controls_Manager::REPEATER,
            'fields'      => $repeater->get_controls(),
            'title_field' => '{{{ client_name }}}',
        ] );
        $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_animation_settings', [
            'label' => __( 'Widget Animation', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_SETTINGS,
        ] );
        $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_grid_settings', [
            'label' => __( 'Grid Settings', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_SETTINGS,
        ] );
        $this->add_control( 'column_layout', [
            'label'       => __( 'Column Layout', 'themesflat' ),
            'type'        => Controls_Manager::SELECT,
            'options'     => array(
            'auto'   => __( 'Auto', 'themesflat' ),
            'custom' => __( 'Custom', 'themesflat' ),
        ),
            'default'     => 'auto',
            'description' => __( 'Set column layout to be <strong>Auto</strong> to let the widget auto calculate number of columns based on minimum column size specified. The option <strong>Custom</strong> lets you explicitly control number of columns based on screen width.', 'themesflat' ),
        ] );
        $this->add_control( 'min_column_size', [
            'label'      => __( 'Minimum Column Size', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 240,
        ],
            'range'      => [
            'px' => [
            'min' => 50,
            'max' => 500,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container.tfl-grid-auto-column-layout' => 'grid-template-columns: repeat(auto-fit, minmax({{SIZE}}{{UNIT}}, 1fr));',
        ],
            'condition'  => [
            'column_layout' => 'auto',
        ],
        ] );
        $this->add_responsive_control( 'per_line', [
            'label'              => __( 'Columns per row', 'themesflat' ),
            'type'               => Controls_Manager::SELECT,
            'default'            => '4',
            'tablet_default'     => '3',
            'mobile_default'     => '2',
            'options'            => [
            '1' => '1',
            '2' => '2',
            '3' => '3',
            '4' => '4',
            '5' => '5',
            '6' => '6',
        ],
            'frontend_available' => true,
            'condition'          => [
            'column_layout' => 'custom',
        ],
        ] );
        $this->add_control( 'column_gap', [
            'label'      => __( 'Column Gap', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 0,
        ],
            'range'      => [
            'px' => [
            'min' => 0,
            'max' => 100,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container' => 'column-gap: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'row_gap', [
            'label'      => __( 'Row Gap', 'themesflat' ),
            'type'       => Controls_Manager::SLIDER,
            'size_units' => [ 'px' ],
            'default'    => [
            'size' => 0,
        ],
            'range'      => [
            'px' => [
            'min' => 0,
            'max' => 100,
        ],
        ],
            'selectors'  => [
            '{{WRAPPER}} .tfl-uber-grid-container' => 'row-gap: {{SIZE}}{{UNIT}};',
        ],
        ] );
        $this->end_controls_section();
        $this->start_controls_section( 'section_styling', [
            'label' => __( 'Clients', 'themesflat' ),
            'tab'   => Controls_Manager::TAB_STYLE,
        ] );
        $this->add_control( 'heading_client_image', [
            'label'     => __( 'Client Images', 'themesflat' ),
            'type'      => Controls_Manager::HEADING,
            'separator' => 'before',
        ] );
        $this->add_control( 'client_border_color', [
            'label'     => __( 'Client Border Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-clients .tfl-client' => 'border-color: {{VALUE}} !important;',
        ],
        ] );
        $this->add_control( 'client_hover_bg_color', [
            'label'     => __( 'Client Hover Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-clients .tfl-client .tfl-image-overlay' => 'background-color: {{VALUE}};',
        ],
        ] );
        $this->add_responsive_control( 'thumbnail_hover_opacity', [
            'label'     => __( 'Thumbnail Hover Opacity (%)', 'themesflat' ),
            'type'      => Controls_Manager::SLIDER,
            'default'   => [
            'size' => 0.7,
        ],
            'range'     => [
            'px' => [
            'max'  => 1,
            'min'  => 0.1,
            'step' => 0.01,
        ],
        ],
            'selectors' => [
            '{{WRAPPER}} .tfl-clients .tfl-client:hover .tfl-image-overlay' => 'opacity: {{SIZE}};',
        ],
        ] );
        $this->add_control( 'client_padding', [
            'label'       => __( 'Client Padding', 'themesflat' ),
            'description' => __( 'Padding for the client images.', 'themesflat' ),
            'type'        => Controls_Manager::DIMENSIONS,
            'size_units'  => [ 'px', '%', 'em' ],
            'selectors'   => [
            '{{WRAPPER}} .tfl-clients .tfl-client' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
        ],
        ] );
        $this->add_control( 'heading_client_name', [
            'label'     => __( 'Client Name', 'themesflat' ),
            'type'      => Controls_Manager::HEADING,
            'separator' => 'before',
        ] );
        $this->add_control( 'client_name_color', [
            'label'     => __( 'Client Name Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-clients .tfl-client .tfl-client-name a' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_control( 'client_name_hover_color', [
            'label'     => __( 'Client Name Hover Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
            '{{WRAPPER}} .tfl-clients .tfl-client .tfl-client-name a:hover' => 'color: {{VALUE}};',
        ],
        ] );
        $this->add_group_control( Group_Control_Typography::get_type(), [
            'name'     => 'client_name_typography',
            'selector' => '{{WRAPPER}} .tfl-clients .tfl-client .tfl-client-name a',
        ] );
        $this->end_controls_section();
    }
    
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings = apply_filters( 'tfl_clients_' . $this->get_id() . '_settings', $settings );
        $args['settings'] = $settings;
        $args['widget_instance'] = $this;
        tfl_get_template_part( 'addons/clients/loop', $args );
    }
    
    protected function content_template()
    {
    }

}