<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Scheme_Color;
use Elementor\Group_Control_Typography;
use Elementor\Scheme_Typography;
use Elementor\Group_Control_Border;
use Elementor\Utils;
use Elementor\Group_Control_Box_Shadow;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

/**
 * Elementor Tutorque course
 *
 * Elementor widget for tutorque course
 *
 * @since 1.0.0
 */
class Widgetkit_Pro_Tutor_Course_List extends Widget_Base {
    public function get_name() {
        return 'tutor-course-list';
    }

    public function get_title() {
        return __('Tutor Course List', 'tutorque');
    }

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

    public function get_categories() {
        return array('widgetkit_pro');
    }
    /**
	 * A list of style that the widgets is depended in
	 **/
	public function get_style_depends() {
        return [
            'widgetkit_bs',
            'widgetkit_pro_default',
        ];
    }
    /**
	 * A list of scripts that the widgets is depended in
	 **/
	public function get_script_depends() {
		return [ 
			// 'animate-text',
			// 'layout',
		 ];
	}

    protected function register_controls() {

        $cat_names = array();

        if( function_exists('tutor')):
            $terms = get_terms(array(
                'post_type' => 'courses',
                'taxonomy' => 'course-category',
                'hide_empty' => true,
            ));
            foreach ($terms as $t):
                $cat_names[$t->term_id] = $t->name;
            endforeach;
        endif;

        #   region Query         
        /**
         * Query
         */
		$this->start_controls_section(
			'section_query',
			[
				'label' => __( 'Query', 'widgetkit-pro' ),
			]
		);
            $this->add_control(
                'cat_dynamic_multiple_id',
                [
                    'label' => __('Select Category', 'widgetkit-pro'),
                    'type' => Controls_Manager::SELECT2,
                    'options' => $cat_names,
                    'multiple' => true,
                ]
            );
            $this->add_control(
                'order',
                [
                    'label' => __('Order', 'widgetkit-pro'),
                    'type' => Controls_Manager::SELECT,
                    'default' => 'ASC',
                    'options' => [
                        'ASC' => __('Ascending', 'widgetkit-pro'),
                        'DESC' => __('Descending', 'widgetkit-pro'),
                    ],
                ]
            );
            $this->add_control(
                'orderby',
                [
                    'label' => __('Order By', 'widgetkit-pro'),
                    'type' => Controls_Manager::SELECT,
                    'default' => 'date',
                    'options' => [
                        'title' => __('Title', 'widgetkit-pro'),
                        'name' => __('Name', 'widgetkit-pro'),
                        'date' => __('Date', 'widgetkit-pro'),
                        'rand' => __('Random', 'widgetkit-pro'),
                    ],
                ]
            );  
            $this->add_control(
                'post_num_to_show',
                [
                    'label' => __('Course to Show', 'widgetkit-pro'),
                    'type' => Controls_Manager::NUMBER,
                    'default' => 3,
                    'min' => 1,
                    'max' => 50,
                    'step' => 1,
                ]
            );
        $this->end_controls_section();
#   endregion         

#   region Layout
        /**
         * Layout
         */
        $this->start_controls_section(
            'section_layout',
            [
                'label' => __( 'Layout', 'widgetkit-pro' ),
            ]
        );
            $this->add_control(
                'posts_column',
                [
                    'label' => __('Columns', 'widgetkit-pro'),
                    'type' => Controls_Manager::SELECT,
                    'default' => '4',
                    'options' => [
                        '2' => __('6 Columns', 'widgetkit-pro'),
                        '3' => __('4 Columns', 'widgetkit-pro'),
                        '4' => __('3 Columns', 'widgetkit-pro'),
                        '6' => __('2 Columns', 'widgetkit-pro'),
                        '12' => __('1 Columns', 'widgetkit-pro'),
                    ],
                ]
            );
        $this->end_controls_section(); 
#   endregion 

        
#   region title & description style

        $this->start_controls_section(
            'section_wapper_style',
            [
                'label' => __('Title', 'widgetkit-pro'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            /**
             * Title
             */
            $this->add_group_control(
                Group_Control_Typography::get_type(),
                [
                    'label' => __('Typography', 'widgetkit-pro'),
                    'name' => 'title_typography',
                    'selector' => '{{WRAPPER}} .tutor-course-loop .tutor-course-loop-title h2',
                ]
            );

            $this->start_controls_tabs('title_style_tabs');
                /**
                 * Normal
                 */
                $this->start_controls_tab(
                    'title_style_normal_tab',
                    [
                        'label' => __('Normal', 'widgetkit-pro'),
                    ]
                );
                    $this->add_control(
                        'title_color',
                        [
                            'label' => __('Color', 'widgetkit-pro'),
                            'type' => Controls_Manager::COLOR,
                            'default' => '',
                            'selectors' => [
                                '{{WRAPPER}} .tutor-course-loop .tutor-course-loop-title h2 a' => 'color: {{VALUE}}',
                            ],
                        ]
                    );
                $this->end_controls_tab(); 
                /**
                 * hover
                 */
                $this->start_controls_tab(
                    'title_style_hover_tab',
                    [
                        'label' => __('Hover', 'widgetkit-pro'),
                    ]
                );
                    $this->add_control(
                        'title_hover_color',
                        [
                            'label' => __('Color', 'widgetkit-pro'),
                            'type' => Controls_Manager::COLOR,
                            'default' => '',
                            'selectors' => [
                                '{{WRAPPER}} .tutor-course-loop .tutor-course-loop-title h2:hover a' => 'color: {{VALUE}}',
                            ],
                        ]
                    );
                $this->end_controls_tab(); // Hover Tab end
            $this->end_controls_tabs();
            $this->add_responsive_control(
                'title_spacing_bottom',
                [
                    'label' => __( 'Spacing Bottom', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SLIDER,
                    'range' => [
                        'px' => [
                            'min' => 0,
                            'max' => 100,
                        ],
                    ],
                    'selectors' => [
                        '{{WRAPPER}} .tutor-course-loop .tutor-course-loop-title h2' => 'margin-bottom: {{SIZE}}{{UNIT}};',
                    ],
                ]
            );
                
        $this->end_controls_section();
#   endregion         

#   region course level style
$this->start_controls_section(
    'section_course_level_style',
    [
        'label' => __( 'Course level', 'widgetkit-pro' ),
        'tab' => Controls_Manager::TAB_STYLE,
    ]
);
    $this->add_control(
        'course_level_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop-level' => 'color: {{VALUE}};',
            ],
        ]
    );
    $this->add_group_control(
        Group_Control_Typography::get_type(),
        [
            'label' => __('Typography', 'widgetkit-pro'),
            'name' => 'course_level_typography',
            'selector' => '{{WRAPPER}} .tutor-course-loop-level'
        ]
    );
    $this->add_control(
        'course_level_bg_color',
        [
            'label' => __('Background', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop-level' => 'background-color: {{VALUE}};'
            ],
        ]
    );
$this->end_controls_section();
#   endregion 

#   region wishlist style
$this->start_controls_section(
    'section_style_wishlist',
    [
        'label' => __( 'Wishlist Button', 'widgetkit-pro' ),
        'tab' => Controls_Manager::TAB_STYLE,
    ]
);

    $this->start_controls_tabs('wishlist_style_tabs');
        /**
         * Normal
         */
        $this->start_controls_tab(
            'wishlist_style_normal_tab',
            [
                'label' => __('Normal', 'widgetkit-pro'),
            ]
        );

            $this->add_control(
                'wishlist_color',
                [
                    'label' => __('Color', 'widgetkit-pro'),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .tutor-course-loop-header-meta .tutor-course-wishlist a' => 'color: {{VALUE}};',
                    ],
                ]
            );
            $this->add_control(
                'wishlist_bg_color',
                [
                    'label' => __('Background', 'widgetkit-pro'),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .tutor-course-loop-header-meta .tutor-course-wishlist' => 'background-color: {{VALUE}};',
                    ],
                ]
            );
        $this->end_controls_tab();

         /**
         * Hover
         */
        $this->start_controls_tab(
            'wishlist_style_hover_tab',
            [
                'label' => __('Hover', 'widgetkit-pro'),
            ]
        );

            $this->add_control(
                'wishlist_hover_color',
                [
                    'label' => __('Color', 'widgetkit-pro'),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .tutor-course-loop-header-meta .tutor-course-wishlist a:hover' => 'color: {{VALUE}};',
                    ],
                ]
            );
            $this->add_control(
                'wishlist_hover_bg_color',
                [
                    'label' => __('Background', 'widgetkit-pro'),
                    'type' => Controls_Manager::COLOR,
                    'selectors' => [
                        '{{WRAPPER}} .tutor-course-loop-header-meta .tutor-course-wishlist:hover' => 'background-color: {{VALUE}};',
                    ],
                ]
            );
        $this->end_controls_tab();

    $this->end_controls_tabs();
$this->end_controls_section();
#   endregion

#   region rating style
$this->start_controls_section(
    'section_course_star_rating_style',
    [
        'label' => __( 'Star & Rating', 'widgetkit-pro' ),
        'tab' => Controls_Manager::TAB_STYLE,
    ]
);

    $this->add_responsive_control(
        'course_star_rating_spacing_bottom',
        [
            'label' => __( 'Spacing Bottom', 'widgetkit-pro' ),
            'type' => Controls_Manager::SLIDER,
            'range' => [
                'px' => [
                    'min' => 0,
                    'max' => 100,
                ],
            ],
            'selectors' => [
                '{{WRAPPER}} .tutor-loop-rating-wrap' => 'margin-bottom: {{SIZE}}{{UNIT}};',
            ],
        ]
    );

    $this->add_control(
        'style_heading_star',
        [
        'label' => __( 'Star', 'widgetkit-pro' ),
        'type' => Controls_Manager::HEADING,
        'separator' => 'before',
        ]
    );
    $this->add_control(
        'course_star_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-star-rating-group' => 'color: {{VALUE}};',
            ],
        ]
    );

    $this->add_control(
        'style_heading_rating',
        [
        'label' => __( 'Rating', 'widgetkit-pro' ),
        'type' => Controls_Manager::HEADING,
        ]
    );

    $this->add_group_control(
        Group_Control_Typography::get_type(),
        [
            'label' => __('Typography', 'widgetkit-pro'),
            'name' => 'course_rating_typography',
            'selector' => '{{WRAPPER}} .tutor-rating-count'
        ]
    );
    $this->add_control(
        'course_rating_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-rating-count' => 'color: {{VALUE}};',
            ],
        ]
    );
$this->end_controls_section();
#   endregion 

#   region course meta style
$this->start_controls_section(
    'section_course_meta_style',
    [
        'label' => __( 'Meta', 'widgetkit-pro' ),
        'tab' => Controls_Manager::TAB_STYLE,
    ]
);
    $this->add_control(
        'course_meta_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop-meta' => 'color: {{VALUE}};',
            ],
        ]
    );
    $this->add_group_control(
        Group_Control_Typography::get_type(),
        [
            'label' => __('Typography', 'widgetkit-pro'),
            'name' => 'course_meta_typography',
            'selector' => '{{WRAPPER}} .tutor-course-loop-meta'
        ]
    );

    $this->add_responsive_control(
        'course_meta_spacing_bottom',
        [
            'label' => __( 'Spacing Bottom', 'widgetkit-pro' ),
            'type' => Controls_Manager::SLIDER,
            'range' => [
                'px' => [
                    'min' => 0,
                    'max' => 100,
                ],
            ],
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop-meta' => 'margin-bottom: {{SIZE}}{{UNIT}};',
            ],
        ]
    );
    
$this->end_controls_section();
#   endregion

#   region course meta style
$this->start_controls_section(
    'section_course_author_category_style',
    [
        'label' => __( 'Author & Category', 'widgetkit-pro' ),
        'tab' => Controls_Manager::TAB_STYLE,
    ]
);
    $this->add_control(
        'style_heading_author',
        [
        'label' => __( 'Author', 'widgetkit-pro' ),
        'type' => Controls_Manager::HEADING,
        'separator' => 'before',
        ]
    );

    $this->add_control(
        'course_author_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-single-course-author-name a' => 'color: {{VALUE}};',
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-single-course-author-name span' => 'color: {{VALUE}};',
            ],
        ]
    );
    $this->add_group_control(
        Group_Control_Typography::get_type(),
        [
            'label' => __('Typography', 'widgetkit-pro'),
            'name' => 'course_author_typography',
            'selector' => '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-single-course-author-name'
        ]
    );

    $this->add_responsive_control(
        'course_meta_spacing_right',
        [
            'label' => __( 'Spacing Right', 'widgetkit-pro' ),
            'type' => Controls_Manager::SLIDER,
            'range' => [
                'px' => [
                    'min' => 0,
                    'max' => 100,
                ],
            ],
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-single-course-author-name' => 'margin-bottom: {{SIZE}}{{UNIT}};',
            ],
        ]
    );

    $this->add_control(
        'style_heading_category',
        [
        'label' => __( 'Category', 'widgetkit-pro' ),
        'type' => Controls_Manager::HEADING,
        'separator' => 'before',
        ]
    );

    $this->add_control(
        'course_category_color',
        [
            'label' => __('Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-course-lising-category a' => 'color: {{VALUE}};',
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-course-lising-category span' => 'color: {{VALUE}};',
            ],
        ]
    );

    $this->add_control(
        'course_category_hover_color',
        [
            'label' => __('Hover Color', 'widgetkit-pro'),
            'type' => Controls_Manager::COLOR,
            'selectors' => [
                '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-course-lising-category a:hover' => 'color: {{VALUE}};',
            ],
        ]
    );

    $this->add_group_control(
        Group_Control_Typography::get_type(),
        [
            'label' => __('Typography', 'widgetkit-pro'),
            'name' => 'course_category_typography',
            'selector' => '{{WRAPPER}} .tutor-course-loop .tutor-loop-author .tutor-course-lising-category'
        ]
    );
    
$this->end_controls_section();
#   endregion 

#   region price style
    $this->start_controls_section(
        'section_style_price',
        [
            'label' => __( 'Price ', 'widgetkit-pro' ),
            'tab' => Controls_Manager::TAB_STYLE,
        ]
    );
        $this->add_control(
            'price_color',
            [
                'label' => __('Color', 'widgetkit-pro'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .tutor-course-loop-price' => 'color: {{VALUE}};',
                ],
            ]
        );
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __('Typography', 'widgetkit-pro'),
                'name' => 'price_typography',
                'selector' => '{{WRAPPER}} .tutor-course-loop-price',
            ]
        );
    $this->end_controls_section();
#   endregion 

#   region Button style
        $this->start_controls_section(
            'section_button_style',
            [
                'label' => __( 'Enroll Button', 'widgetkit-pro' ),
                 'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
        /**
         * Button
         */
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [
                'label' => __('Button Typography', 'widgetkit-pro'),
                'name' => 'button_typography',
                'selector' => '{{WRAPPER}} .tutor-course-loop-price>.price .tutor-loop-cart-btn-wrap a'
            ]
        );

        $this->start_controls_tabs('button_style_tabs');

        $this->start_controls_tab(
            'button_style_normal_tab',
            [
                'label' => __('Normal', 'widgetkit-pro'),
            ]
        );

        $this->add_control(
            'button_text_color',
            [
                'label' => __('Color', 'widgetkit-pro'),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .tutor-course-loop-price>.price .tutor-loop-cart-btn-wrap a' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .tutor-course-loop-price>.price .tutor-loop-cart-btn-wrap a:before' => 'color: {{VALUE}};',
                ],
            ]
        );


        $this->end_controls_tab(); // Normal Tab end

        $this->start_controls_tab(
            'button_style_hover_tab',
            [
                'label' => __('Hover', 'widgetkit-pro'),
            ]
        );
        $this->add_control(
            'button_hover_text_color',
            [
                'label' => __('Color', 'widgetkit-pro'),
                'type' => Controls_Manager::COLOR,
                'default' => '',
                'selectors' => [
                    '{{WRAPPER}} .tutor-course-loop-price>.price .tutor-loop-cart-btn-wrap a:hover' => 'color: {{VALUE}};',
                    '{{WRAPPER}} .tutor-course-loop-price>.price .tutor-loop-cart-btn-wrap a:hover:before' => 'color: {{VALUE}};',
                ],
            ]
        );

        $this->end_controls_tab(); // Hover Tab end

        $this->end_controls_tabs();

        $this->end_controls_section();
#   endregion         

#   region global option style
        
        $this->start_controls_section(
            'section_single_course_style',
            [
                'label' => __( 'Global option', 'widgetkit-pro' ),
                 'tab' => Controls_Manager::TAB_STYLE,
            ]
        );
            $this->add_responsive_control(
                'single_course_align',
                [
                    'label' => esc_html__( 'Alignment', 'widgetkit-for-elementor' ),
                    'type'  => Controls_Manager::CHOOSE,
                    'default'   =>'left' ,
                    'options'   => [
                        'left'    => [
                            'title' => esc_html__( 'Left', 'widgetkit-for-elementor' ),
                            'icon'  => 'eicon-text-align-left',
                        ],
                        'center' => [
                            'title' => esc_html__( 'Center', 'widgetkit-for-elementor' ),
                            'icon'  => 'eicon-text-align-center',
                        ],
                        'right' => [
                            'title' => esc_html__( 'Right', 'widgetkit-for-elementor' ),
                            'icon'  => 'eicon-text-align-left',
                        ],
                    ],
                    'selectors' => [
                        '{{WRAPPER}} .tutor-loop-course-container' => 'text-align: {{VALUE}};',
                    ],
                ]
            );
            
            $this->add_control(
                'single_course_background',
                [
                    'label' => __('Background', 'widgetkit-pro'),
                    'type' => Controls_Manager::COLOR,
                    'default' => '',
                    'selectors' => [
                        '{{WRAPPER}} .tutor-loop-course-container' => 'Background: {{VALUE}};',
                    ],
                ]
            );
            
            $this->add_group_control(
                Group_Control_Border::get_type(), 
                [
                'name'          => 'Border',
                'selector'      => '{{WRAPPER}} .tutor-course-loop',
                ]
            );
            $this->add_control(
                'enable_box_shadow',
                [
                    'label' => __( 'Enable Box Shadow', 'widgetkit-pro' ),
                    'type' => Controls_Manager::SWITCHER,
                    'default' => '',
                    'label_on' => __( 'Yes', 'widgetkit-pro' ),
                    'label_off' => __( 'No', 'widgetkit-pro' ),
                    'return_value' => 'yes',
                    
                ]
            );
            $this->add_group_control(
                Group_Control_Box_Shadow::get_type(),
                    [
                        'name'    => 'item_box_shadow',
                        'label'     => esc_html__( 'Normal Box Shadow', 'widgetkit-pro' ),
                        'exclude' => [
                            'box_shadow_position',
                        ],
                        'selector' => '{{WRAPPER}} .tutor-course-loop',
                        'condition' => [
                            'enable_box_shadow' => 'yes',
                        ],
                    ]
            );
            $this->add_group_control(
                Group_Control_Box_Shadow::get_type(),
                    [
                        'name'    => 'item_hover_box_shadow',
                        'label'     => esc_html__( 'Hover Box Shadow', 'widgetkit-pro' ),
                        'exclude' => [
                            'box_shadow_position',
                        ],
                        'selector' => '{{WRAPPER}} .tutor-course-loop:hover',
                        'condition' => [
                            'enable_box_shadow' => 'yes',
                        ],
                    ]
            );
            $this->add_responsive_control(
                'single_course_padding',
                [
                    'label' => esc_html__( 'Padding', 'widgetkit-pro' ),
                    'type'  => Controls_Manager::DIMENSIONS,
                    'size_units' => [ 'px'],
                    'selectors'  => [
                        '{{WRAPPER}} .tutor-loop-course-container' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                    ]
                ]
            );
            $this->add_responsive_control(
                'single_course_border_radius',
                [
                    'label' => esc_html__( 'Border Radius', 'widgetkit-pro' ),
                    'type'  => Controls_Manager::DIMENSIONS,
                    'size_units' => [ 'px', '%' ],
                    'selectors'  => [
                        '{{WRAPPER}} .tutor-course-loop' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}}; overflow:hidden;',
                    ],
                ]
            );
        $this->end_controls_section();
#   endregion 


    }

    protected function render() {

        // require TUTORQUE_CORE_ROOT . '/elements/tutor-course/template/view.php';
        require( plugin_dir_path( __FILE__ ) . '../layout/layout-tutor-course-list.php' );
    }
}