<?php
use Elementor\Controls_Manager;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Background;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;

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

class Banae_Count_Down_Control {

	/**
	 * The main widget controls registration method
	 * 
	 * @param mixed $widget
	 * 
	 * @return void
	 */
	public static function add_register_controls( $widget ) {
		$widget->start_controls_section(
			'countdown_content_section',
			[
				'label' => esc_html__( 'Countdown', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$widget->add_control(
			'cb_datetime',
			[
				'label' => esc_html__( 'Date & Time', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::DATE_TIME,
			]
		);

		$widget->end_controls_section();

		$widget->start_controls_section(
			'countdown_settings_section',
			[
				'label' => esc_html__( 'Countdown Settings', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$widget->add_control(
			'show_label_days',
			[
				'label' => esc_html__( 'Show Label Days', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);

		$widget->add_control(
			'label_days',
			[
				'label' => esc_html__( 'Label Days', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Days', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type Label Name', 'banana-addons-for-elementor' ),
				'condition' => [
					'show_label_days' => 'yes',
				]
			]
		);

		$widget->add_control(
			'show_label_hours',
			[
				'label' => esc_html__( 'Show Label Hours', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);

		$widget->add_control(
			'label_hours',
			[
				'label' => esc_html__( 'Label Hours', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Hours', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type Label Name', 'banana-addons-for-elementor' ),
				'condition' => [
					'show_label_hours' => 'yes',
				]
			]
		);

		$widget->add_control(
			'show_label_minutes',
			[
				'label' => esc_html__( 'Show Label Minutes', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);

		$widget->add_control(
			'label_minutes',
			[
				'label' => esc_html__( 'Label Minutes', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Minutes', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type Label Name', 'banana-addons-for-elementor' ),
				'condition' => [
					'show_label_minutes' => 'yes',
				]
			]
		);

		$widget->add_control(
			'show_label_seconds',
			[
				'label' => esc_html__( 'Show Label Seconds', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'yes',
			]
		);

		$widget->add_control(
			'label_seconds',
			[
				'label' => esc_html__( 'Label Seconds', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( 'Seconds', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type Label Name', 'banana-addons-for-elementor' ),
				'condition' => [
					'show_label_seconds' => 'yes',
				]
			]
		);

		$widget->add_responsive_control(
			'label_text_align',
			[
				'label' => esc_html__( 'Alignment', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::CHOOSE,
				'options' => [
					'left' => [
						'title' => esc_html__( 'Left', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-text-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-text-align-right',
					],
				],
				'default' => 'center',
				'toggle' => true,
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item' => 'text-align: {{VALUE}};',
				],
			]
		);

		$widget->add_control(
			'separator_options',
			[
				'label' => esc_html__( 'Separator Options', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::HEADING,
				'separator' => 'before',
			]
		);

		$widget->add_control(
			'show_separator',
			[
				'label' => esc_html__( 'Show Separator', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$widget->add_control(
			'label_separator',
			[
				'label' => esc_html__( 'Separator', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXT,
				'default' => esc_html__( ':', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type separator', 'banana-addons-for-elementor' ),
				'condition' => [
					'show_separator' => 'yes',
				]
			]
		);

		$widget->end_controls_section();

		$widget->start_controls_section(
			'countdown_end_action_section',
			[
				'label' => esc_html__( 'End Action', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_CONTENT,
			]
		);

		$widget->add_control(
			'end_action_type',
			[
				'label' => esc_html__( 'End Action Type', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SELECT,
				'default' => 'message',
				'options' => [
					'none' => esc_html__( 'None', 'banana-addons-for-elementor' ),
					'message' => esc_html__( 'Message', 'banana-addons-for-elementor' ),
					'redirect' => esc_html__( 'Re-direct Link', 'banana-addons-for-elementor' ),
					//'image' => esc_html__( 'Image', 'banana-addons-for-elementor' ),
				],
				'selectors' => [],
			]
		);

		$widget->add_control(
			'end_action_message',
			[
				'label' => esc_html__( 'Message', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::TEXTAREA,
				'rows' => 10,
				'default' => esc_html__( 'Countdown ended!', 'banana-addons-for-elementor' ),
				'placeholder' => esc_html__( 'Type your end message here', 'banana-addons-for-elementor' ),
				'condition' => [
					'end_action_type' => 'message',
				],
			]
		);

		$widget->add_control(
			'end_action_url',
			[
				'label' => esc_html__( 'Redirect URL', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::URL,
				'options' => [ 'url', 'is_external', 'nofollow' ],
				'default' => [
					'url' => '',
					'is_external' => true,
					//'nofollow' => true,
				],
				'label_block' => true,
				'condition' => [
					'end_action_type' => 'redirect',
				],
			]
		);

		$widget->end_controls_section();

		// Style Tabs Start Here
		$widget->start_controls_section(
			'countdown_style_section',
			[
				'label' => esc_html__( 'Common', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);

		$widget->add_control(
			'box_align',
			[
				'label' => esc_html__( 'Position', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::CHOOSE,
				'options' => [
					'left' => [
						'title' => esc_html__( 'Left', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-h-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-h-align-center',
					],
					'right' => [
						'title' => esc_html__( 'Right', 'banana-addons-for-elementor' ),
						'icon' => 'eicon-h-align-right',
					],
				],
				'default' => 'center',
				'toggle' => true,
				'selectors' => [
					'{{WRAPPER}} .banae-countdown' => 'justify-content: {{VALUE}};',
				],
			]
		);


		$widget->add_control(
			'box_width',
			[
				'label' => esc_html__( 'Box Width', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 1,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 84,
				],
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$widget->add_control(
			'box_height',
			[
				'label' => esc_html__( 'Box Height', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 1,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 84,
				],
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item' => 'height: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$widget->add_control(
			'box_padding',
			[
				'label' => esc_html__( 'Box Padding', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'default' => [
					'top' => 12,
					'right' => 6,
					'bottom' => 12,
					'left' => 6,
					'unit' => 'px',
					'isLinked' => false,
				],
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'box_background',
				'types' => [ 'classic', 'gradient', 'image' ],
				'exclude' => [ 'video' ],
				'selector' => '{{WRAPPER}} .banae-countdown-item',
			]
		);

		$widget->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'box_border',
				'selector' => '{{WRAPPER}} .banae-countdown-item',
			]
		);

		$widget->add_control(
			'box_border_radius',
			[
				'label' => esc_html__( 'Border Radius', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'default' => [
					'top' => 6,
					'right' => 6,
					'bottom' => 6,
					'left' => 6,
					'unit' => 'px',
					'isLinked' => false,
				],
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Box_Shadow::get_type(),
			[
				'name' => 'box_shadow',
				'selector' => '{{WRAPPER}} .banae-countdown-item',
			]
		);

		$widget->add_control(
			'space_between_box',
			[
				'label' => esc_html__( 'Space Between Box', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 2,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 10,
				],
				'selectors' => [
					'{{WRAPPER}} .banae-countdown' => 'gap: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$widget->add_control(
			'time_options',
			[
				'label' => esc_html__( 'Time Number Styles', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::HEADING,
				'separator' => 'before',
			]
		);

		$widget->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'time_typography',
				'label' => esc_html__( 'Number Typography', 'banana-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .banae-countdown-item .banae-cd-days',
			]
		);

		$widget->add_control(
			'time_text_color',
			[
				'label' => esc_html__( 'Time Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item .banae-cd-days' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'label_options',
			[
				'label' => esc_html__( 'Time Label Styles', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::HEADING,
				'separator' => 'before',
			]
		);

		$widget->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'label_typography',
				'label' => esc_html__( 'Label Typography', 'banana-addons-for-elementor' ),
				'selector' => '{{WRAPPER}} .banae-countdown-item .banae-cd-label',
			]
		);

		$widget->add_control(
			'label_text_color',
			[
				'label' => esc_html__( 'Label Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-countdown-item .banae-cd-label' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'show_individual_styles',
			[
				'label' => esc_html__( 'Customize each time box?', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SWITCHER,
				'label_on' => esc_html__( 'Show', 'banana-addons-for-elementor' ),
				'label_off' => esc_html__( 'Hide', 'banana-addons-for-elementor' ),
				'return_value' => 'yes',
				'default' => 'no',
			]
		);

		$widget->end_controls_section();

		// Separator Style Tabs
		$widget->start_controls_section(
			'separator_style_section',
			[
				'label' => esc_html__( 'Count Down Separator', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'show_separator' => 'yes',
				],
			]
		);

		$widget->add_control(
			'separator_color',
			[
				'label' => esc_html__( 'Separator Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .your-class' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_responsive_control(
			'separator_font_size',
			[
				'label' => esc_html__( 'Font size', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::SLIDER,
				'size_units' => [ 'px', '%', 'em', 'rem' ],
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 5,
					],
					'%' => [
						'min' => 0,
						'max' => 100,
					],
				],
				'default' => [
					'unit' => 'px',
					'size' => 24,
				],
				'selectors' => [
					'{{WRAPPER}} .your-class' => 'width: {{SIZE}}{{UNIT}};',
				],
			]
		);

		$widget->end_controls_section();

		// Each Time Box Style Tabs
		$widget->start_controls_section(
			'days_box_style_section',
			[
				'label' => esc_html__( 'Time Days', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'show_individual_styles' => 'yes',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'days_background',
				'types' => [ 'classic', 'gradient', 'image' ],
				'exclude' => [ 'video' ],
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-days',
			]
		);

		$widget->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'days_border',
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-days',
			]
		);

		$widget->add_control(
			'days_counter_color',
			[
				'label' => esc_html__( 'Number Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-days .banae-cd-number' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'days_label_color',
			[
				'label' => esc_html__( 'Label Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-days .banae-cd-label' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->end_controls_section();

		// Hours Box Style Section
		$widget->start_controls_section(
			'hours_box_style_section',
			[
				'label' => esc_html__( 'Time Hours', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'show_individual_styles' => 'yes',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'hours_background',
				'types' => [ 'classic', 'gradient', 'image' ],
				'exclude' => [ 'video' ],
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-hours',
			]
		);

		$widget->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'hours_border',
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-hours',
			]
		);

		$widget->add_control(
			'hours_counter_color',
			[
				'label' => esc_html__( 'Number Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-hours .banae-cd-number' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'hours_label_color',
			[
				'label' => esc_html__( 'Label Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-hours .banae-cd-label' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->end_controls_section();

		// Minutes Box Style Section
		$widget->start_controls_section(
			'minutes_box_style_section',
			[
				'label' => esc_html__( 'Time Minutes', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'show_individual_styles' => 'yes',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'minutes_background',
				'types' => [ 'classic', 'gradient', 'image' ],
				'exclude' => [ 'video' ],
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-minutes',
			]
		);

		$widget->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'minutes_border',
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-minutes',
			]
		);

		$widget->add_control(
			'minutes_counter_color',
			[
				'label' => esc_html__( 'Number Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-minutes .banae-cd-number' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'minutes_label_color',
			[
				'label' => esc_html__( 'Label Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-minutes .banae-cd-label' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->end_controls_section();

		// Seconds Box Style Section
		$widget->start_controls_section(
			'seconds_box_style_section',
			[
				'label' => esc_html__( 'Time Seconds', 'banana-addons-for-elementor' ),
				'tab' => Controls_Manager::TAB_STYLE,
				'condition' => [
					'show_individual_styles' => 'yes',
				],
			]
		);

		$widget->add_group_control(
			Group_Control_Background::get_type(),
			[
				'name' => 'seconds_background',
				'types' => [ 'classic', 'gradient', 'image' ],
				'exclude' => [ 'video' ],
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-seconds',
			]
		);

		$widget->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'seconds_border',
				'selector' => '{{WRAPPER}} .banae-countdown .banae-tm-seconds',
			]
		);

		$widget->add_control(
			'seconds_counter_color',
			[
				'label' => esc_html__( 'Number Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-seconds .banae-cd-number' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->add_control(
			'seconds_label_color',
			[
				'label' => esc_html__( 'Label Color', 'banana-addons-for-elementor' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .banae-tm-seconds .banae-cd-label' => 'color: {{VALUE}}',
				],
			]
		);

		$widget->end_controls_section();
	}
}