<?php
use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
Use Elementor\Core\Schemes\Typography;
use Elementor\Group_Control_Box_Shadow;
defined( 'ABSPATH' ) || exit; // Exit if accessed directly
/**
 *
 * Related Course widget.
 *
 * @since 1.0.0
 */
class Widgetkit_Pro_LearnDash_Related_Course extends Widget_Base {

	public function get_name() {
		return 'widgetkit-pro-learndash-related-course';
	}

	public function get_title() {
		return __( 'Learndash Related Course', 'widgetkit-pro' );
	}

	public function get_icon() {
		return 'eicon-instagram-nested-gallery';
	}

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

	public function get_style_depends() {
        return [
            'widgetkit_pro_default',
        ];
    }

	protected function register_controls() {

		$this->start_controls_section(
			'general_section',
			[
				'label' => __( 'General', 'widgetkit-pro' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$this->add_control(
			'posts_per_page',
			[
				'label' => __( 'Course Per Page', 'widgetkit-pro' ),
				'type' => Controls_Manager::NUMBER,
				'default' => 4,
				'range' => [
					'px' => [
						'max' => 20,
					],
				]
			]
		);

		$this->add_responsive_control(
			'columns',
			[
				'label' => __( 'Columns', 'widgetkit-pro' ),
				'type' => Controls_Manager::SELECT,
				'default' => '4',
				'options' => [
					'1' => __( '1 Column', 'widgetkit-pro' ),
					'6' => __( '2 Columns', 'widgetkit-pro' ),
					'4' => __( '3 Columns', 'widgetkit-pro' ),
					'3' => __( '4 Columns', 'widgetkit-pro' ),
					'2' => __( '6 Columns', 'widgetkit-pro' ),
				]
			]
		);

		$this->add_control(
			'orderby',
			[
				'label' => __( 'Order By', 'widgetkit-pro' ),
				'type' => Controls_Manager::SELECT,
				'default' => 'date',
				'options' => [
					'date' => __( 'Date', 'widgetkit-pro' ),
					'title' => __( 'Title', 'widgetkit-pro' ),
					'rand' => __( 'Random', 'widgetkit-pro' ),
					'menu_order' => __( 'Menu Order', 'widgetkit-pro' ),
				]
			]
		);

		$this->add_control(
			'order',
			[
				'label' => __( 'Order', 'widgetkit-pro' ),
				'type' => Controls_Manager::SELECT,
				'default' => 'desc',
				'options' => [
					'asc' => __( 'ASC', 'widgetkit-pro' ),
					'desc' => __( 'DESC', 'widgetkit-pro' ),
				]
			]
		);

		$this->end_controls_section();


		$this->start_controls_section(
            'section_style_image',
            [
                'label' => esc_html__( 'Image', 'widgetkit-pro' ),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );

	        $this->add_responsive_control(
	            'image_size',
	                [
	                    'label'   => esc_html__( 'Size(%)', 'widgetkit-pro' ),
	                    'type'    => Controls_Manager::SLIDER,
	                    'default' => [
	                    'size'    => 100,
	                    ],
	                    'range'   => [
	                        '%'   => [
	                            'min' => 10,
	                            'max' => 100,
	                        ],
	                    ],
	                    'selectors' => [
	                        '{{WRAPPER}} .ld-single-course-item figure.ld-course-post-thumbnail img' => 'width: {{SIZE}}%;',
	                    ]
	                ]
	            );


	            $this->add_responsive_control(
	                'image_height_custom',
	                    [
	                        'label'   => esc_html__( 'Height(px)', 'widgetkit-pro' ),
	                        'type'    => Controls_Manager::SLIDER,
	                        'default' => [
	                           'size' =>'',
	                        ],
	                        'range'  => [
	                            'px' => [
	                                'min' => 10,
	                                'max' => 1000,
	                            ],
	                        ],
	                        'selectors' => [
	                            '{{WRAPPER}} .ld-single-course-item figure.ld-course-post-thumbnail img' => 'max-height: {{SIZE}}{{UNIT}};',
	                        ]
	                    ]
	            );


		        $this->add_control(
		            'image_border_radius',
		            [
		                'label' => esc_html__( 'Border Radius', 'widgetkit-pro' ),
		                'type'  => Controls_Manager::DIMENSIONS,
		                'size_units' => [ 'px', '%' ],
		                'selectors'  => [
		                    '{{WRAPPER}} .ld-single-course-item figure.ld-course-post-thumbnail img' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
		                ]
		            ]
		        );


		$this->end_controls_section();


		// Title Style 
		$this->start_controls_section(
			'title_style',
			[
				'label' => esc_html__( 'Title', 'widgetkit-pro' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);

			$this->add_control(
				'title_color',
				[
					'label'     => esc_html__( 'Color', 'widgetkit-pro' ),
					'type'      => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-title a' => 'color: {{VALUE}};',
					]
				]
			);
			$this->add_group_control(
				Group_Control_Typography::get_type(),
					[
						'name'     => 'title_typography',
						'label'    => esc_html__( 'Typography', 'widgetkit-pro' ),
						'selector' => '{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-title',
					]
			);
			$this->add_control(
				'title_hover_color',
				[
					'label'     => esc_html__( 'Hover Color', 'widgetkit-pro' ),
					'type'      => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-title a:hover' => 'color: {{VALUE}};',
					]
				]
			);


			$this->add_responsive_control(
				'title_spacing',
					[
						'label'   => esc_html__( 'Spacing', 'widgetkit-pro' ),
						'type'    => Controls_Manager::SLIDER,
						'range'  => [
							'px' => [
								'min' => 0,
								'max' => 100,
							],
						],
						'selectors' => [
							'{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-title' => 'padding: {{SIZE}}{{UNIT}} 0 0;',
						]
					]
			);
		
		$this->end_controls_section();
		

		// Category Style 
		$this->start_controls_section(
			'category_style',
			[
				'label' => esc_html__( 'Category', 'widgetkit-pro' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);

		$this->add_control(
			'category_color',
			[
				'label'     => esc_html__( 'Color', 'widgetkit-pro' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '',
				'selectors' => [
					'{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-meta a' => 'color: {{VALUE}};',
				]
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
				[
					'name'     => 'category_typography',
					'label'    => esc_html__( 'Typography', 'widgetkit-pro' ),
					'selector' => '{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-meta a',
				]
		);

		$this->add_control(
			'category_hover_color',
			[
				'label'     => esc_html__( 'Hover Color', 'widgetkit-pro' ),
				'type'      => Controls_Manager::COLOR,
				'default'   => '#fff',
				'selectors' => [
					'{{WRAPPER}} .ld-single-course-item .ld-course-content .ld-course-meta a:hover' => 'color: {{VALUE}} !important;',
				]
			]
		);

		$this->end_controls_section();


		// Global Style 
		$this->start_controls_section(
			'global_style',
			[
				'label' => esc_html__( 'Global', 'widgetkit-pro' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			]
		);
				

			$this->add_group_control(
				Group_Control_Box_Shadow::get_type(),
				[
					'name' => 'content_box_shadow',
					'selector' => '{{WRAPPER}} .ld-single-course-item .ld-course-content',
				]
			);

			$this->add_responsive_control(
				'content_padding',
				[
					'label' => esc_html__( 'Padding', 'widgetkit-pro' ),
					'type'  => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%' ],
					'selectors'  => [
						'{{WRAPPER}} .ld-single-course-item .ld-course-content' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					]
				]
			);

			$this->add_control(
				'content_border_radius',
				[
					'label' => esc_html__( 'Border Radius', 'widgetkit-pro' ),
					'type'  => Controls_Manager::DIMENSIONS,
					'size_units' => [ 'px', '%' ],
					'selectors'  => [
						'{{WRAPPER}} .ld-single-course-item .ld-course-content' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					]
				]
			);

			$this->add_control(
				'content_item_bg_color',
				[
					'label'     => esc_html__( 'Background Color', 'widgetkit-pro' ),
					'type'      => Controls_Manager::COLOR,
					'default'   => '',
					'selectors' => [
						'{{WRAPPER}} .ld-single-course-item .ld-course-content' => 'background: {{VALUE}};',
					]
				]
			);

		$this->end_controls_section();
	}

	protected function render() {
		include( plugin_dir_path( __FILE__ ) . '../layout/learndash-related-course.php');
	}

}