<?php

/*
Widget Name: Team Members
Description: Display a list of your team members optionally 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\Scheme_Color;
use  Elementor\Group_Control_Typography;
use  Elementor\Group_Control_Image_Size;
use  Elementor\Scheme_Typography;
use  Elementor\Modules\DynamicTags\Module as TagsModule;

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

// Exit if accessed directly
class TFL_Team_Widget extends TFL_Widget_Base
{
    public function get_name()
    {
        return 'tfl-team-members';
    }

    public function get_title()
    {
        return __('Team Members', 'themesflat');
    }

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

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

    public function get_custom_help_url()
    {
        return 'https://themesflatelementor.com/docs/themesflat-addons/core-addons/team-members/';
    }

    public function get_script_depends()
    {
        return ['tfl-waypoints', 'tfl-frontend-scripts'];
    }

    public function get_style_depends()
    {
        return [
            'tfl-icomoon-styles',
            'tfl-animate-styles',
            'tfl-frontend-styles',
            'tfl-team-members-styles'
        ];
    }

    protected function register_controls()
    {
        $this->start_controls_section('section_team', [
            'label' => __('Team', 'themesflat'),
        ]);
        $repeater = new Repeater();
        $repeater->add_control('member_name', [
            'label' => __('Member Name', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'default' => __('My team member name', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('member_position', [
            'label' => __('Position', 'themesflat'),
            'type' => Controls_Manager::TEXT,
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('member_image', [
            'label' => __('Team Member Image', 'themesflat'),
            'type' => Controls_Manager::MEDIA,
            'default' => [
                'url' => Utils::get_placeholder_image_src(),
            ],
            'label_block' => true,
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('member_link', [
            'label' => __('Team Member URL', 'themesflat'),
            'description' => __('The link for the page describing the team member.', 'themesflat'),
            'type' => Controls_Manager::URL,
            'label_block' => true,
            'default' => [
                'url' => '',
                'is_external' => 'true',
            ],
            'placeholder' => __('http://member-link.com', 'themesflat'),
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('member_details', [
            'label' => __('Team Member details', 'themesflat'),
            'type' => Controls_Manager::TEXTAREA,
            'default' => __('Details about team member', 'themesflat'),
            'description' => __('Provide a short writeup for the team member', 'themesflat'),
            'label_block' => true,
            'dynamic' => [
                'active' => true,
            ],
        ]);
        $repeater->add_control('social_profile', [
            'label' => __('Social Profile', 'themesflat'),
            'type' => Controls_Manager::HEADING,
            'separator' => 'before',
        ]);
        $repeater->add_control('member_email', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Email Address', 'themesflat'),
            'description' => __('Enter the email address of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('facebook_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Facebook Page URL', 'themesflat'),
            'description' => __('URL of the Facebook page of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('twitter_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Twitter Profile URL', 'themesflat'),
            'description' => __('URL of the Twitter page of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('linkedin_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('LinkedIn Page URL', 'themesflat'),
            'description' => __('URL of the LinkedIn profile of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('pinterest_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Pinterest Page URL', 'themesflat'),
            'description' => __('URL of the Pinterest page for the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('dribbble_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Dribbble Profile URL', 'themesflat'),
            'description' => __('URL of the Dribbble profile of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('google_plus_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('GooglePlus Page URL', 'themesflat'),
            'description' => __('URL of the Google Plus page of the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control('instagram_url', [
            'type' => Controls_Manager::TEXT,
            'label' => __('Instagram Page URL', 'themesflat'),
            'description' => __('URL of the Instagram feed for the team member.', 'themesflat'),
            'dynamic' => [
                'active' => true,
                'categories' => [TagsModule::POST_META_CATEGORY],
            ],
        ]);
        $repeater->add_control("widget_animation", [
            "type" => Controls_Manager::SELECT,
            "label" => __("Animation Type", "themesflat"),
            'options' => tfl_get_animation_options(),
            'default' => 'none',
            'separator' => 'before',
        ]);
        $this->add_control('team_members', [
            'label' => __('Team Members', 'themesflat'),
            'type' => Controls_Manager::REPEATER,
            'separator' => 'before',
            'default' => [[
                'member_name' => __('Team Member #1', 'themesflat'),
                'member_position' => __('CEO', 'themesflat'),
                'member_details' => __('I am member details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ], [
                'member_name' => __('Team Member #2', 'themesflat'),
                'member_position' => __('Lead Developer', 'themesflat'),
                'member_details' => __('I am member details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ], [
                'member_name' => __('Team Member #3', 'themesflat'),
                'member_position' => __('Finance Manager', 'themesflat'),
                'member_details' => __('I am member details. Click edit button to change this text. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.', 'themesflat'),
            ]],
            'fields' => $repeater->get_controls(),
            'title_field' => '{{{ member_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_general_settings', [
            'label' => __('General Settings', 'themesflat'),
            'tab' => Controls_Manager::TAB_SETTINGS,
        ]);
        $this->add_control('style', [
            'type' => Controls_Manager::SELECT,
            'label' => __('Choose Team Style', 'themesflat'),
            'default' => 'style1',
            'options' => [
                'style1' => __('Style 1', 'themesflat'),
                'style2' => __('Style 2', 'themesflat'),
            ],
        ]);
        $this->add_group_control(Group_Control_Image_Size::get_type(), [
            'name' => 'thumbnail_size',
            'label' => __('Team Member Image Size', 'themesflat'),
            'default' => 'full',
        ]);
        $this->end_controls_section();

        $this->start_controls_section('section_team_profiles_style', [
            'label' => __('General', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
            'show_label' => false,
        ]);

        $this->add_control( 'team_member_bg_color', [
            'label'     => __( 'Background Color', 'themesflat' ),
            'type'      => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members.tfl-team-members-style1 .tfl-team-member, .tfl-team-members.tfl-team-members-style2 .tfl-team-member' => 'background: {{VALUE}};',
            ],
        ] );

        $this->add_responsive_control('team_member_spacing', [
            'label' => __('Team Member Spacing', 'themesflat'),
            'type' => Controls_Manager::DIMENSIONS,
            'size_units' => ['px', 'em'],
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members .tfl-team-member-wrapper' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
            ],
            'isLinked' => false,
            'condition' => [
                'style' => ['style2'],
            ],
        ]);

        $this->add_control('thumbnail_border_radius', [
            'label' => __('Thumbnail Border Radius', 'themesflat'),
            'type' => Controls_Manager::DIMENSIONS,
            'size_units' => ['px', '%'],
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members .tfl-team-member-wrapper .tfl-team-member .tfl-image-wrapper' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
            ],
        ]);
        $this->end_controls_section();
        $this->start_controls_section('section_team_member_title', [
            'label' => __('Member 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('title_color', [
            'label' => __('Color', 'themesflat'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-text .tfl-title' => 'color: {{VALUE}};',
            ],
        ]);
        $this->add_control('title_hover_color', [
            'label' => __('Hover Color for Link', 'themesflat'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members.tfl-team-members-style2 .tfl-team-member-wrapper .tfl-team-member .tfl-team-member-text .tfl-title:hover' => 'color: {{VALUE}};',
            ],
        ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [
            'name' => 'title_typography',
            'selector' => '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-text .tfl-title',
        ]);
        $this->end_controls_section();
        $this->start_controls_section('section_team_member_position', [
            'label' => __('Member Position', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
        $this->add_control('position_color', [
            'label' => __('Color', 'themesflat'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-text .tfl-team-member-position' => 'color: {{VALUE}};',
            ],
        ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [
            'name' => 'position_typography',
            'selector' => '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-text .tfl-team-member-position',
        ]);
        $this->end_controls_section();
        $this->start_controls_section('section_team_member_details', [
            'label' => __('Member Details', 'themesflat'),
            'tab' => Controls_Manager::TAB_STYLE,
        ]);
        $this->add_control('text_color', [
            'label' => __('Color', 'themesflat'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-details' => 'color: {{VALUE}};',
            ],
        ]);
        $this->add_group_control(Group_Control_Typography::get_type(), [
            'name' => 'text_typography',
            'selector' => '{{WRAPPER}} .tfl-team-members .tfl-team-member .tfl-team-member-details',
        ]);
        $this->end_controls_section();

    }

    protected function render()
    {
        $settings = $this->get_settings_for_display();
        $settings['per_line'] = 3;
        $settings['per_line_tablet'] = 2;
        $settings['per_line_mobile'] = 1;
        $settings = apply_filters('tfl_team_members_' . $this->get_id() . '_settings', $settings);
        $args['settings'] = $settings;

        $args['widget_instance'] = $this;
        tfl_get_template_part('addons/team-members/loop', $args);
    }

    protected function content_template()
    {
    }

}