<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Repeater;
use Elementor\Group_Control_Image_Size;
use Sifency\Traits\Sifency_Addons_Flex_Controls;

trait Sifency_Award_Controls {
	use Sifency_Addons_Flex_Controls;

	protected function add_sifency_award_controls( $args = array() ) {
		$this->start_controls_section( 'section_content', array( 'label' => 'Awards' ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts (Requires "award" CPT)',
				),
				'default' => 'custom',
			)
		);
		$repeater = new Repeater();
		$repeater->add_control(
			'award_image',
			array(
				'label'   => 'Image',
				'type'    => Controls_Manager::MEDIA,
				'default' => array( 'url' => \Elementor\Utils::get_placeholder_image_src() ),
			)
		);
		$repeater->add_control(
			'award_year',
			array(
				'label'   => 'Year',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => current_time( 'Y' ),
			)
		);
		$repeater->add_control(
			'award_title',
			array(
				'label'   => 'Title',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Award Title',
			)
		);
		$repeater->add_control(
			'awarding_body',
			array(
				'label'   => 'Awarding Body',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Awarding Organization',
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'View Project',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);
		$repeater->add_control(
			'award_level',
			array(
				'label'   => 'Award Level (e.g. Winner, Gold)',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Winner',
			)
		);
		$this->add_control(
			'show_image',
			array(
				'label'        => 'Show Image',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'show_title',
			array(
				'label'        => 'Show Title',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'show_award_level',
			array(
				'label'        => 'Show Award Level',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'show_excerpt',
			array(
				'label'        => 'Show Excerpt',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'show_date',
			array(
				'label'        => 'Show Date',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'show_button',
			array(
				'label'        => 'Show Button',
				'type'         => Controls_Manager::SWITCHER,
				'default'      => 'yes',
				'return_value' => 'yes',
			)
		);
		$this->add_control(
			'read_more_text',
			array(
				'label'     => 'Button Text',
				'type'      => Controls_Manager::TEXT,
				'default'   => 'View Projects',
				'condition' => array( 'show_button' => 'yes' ),
			)
		);
		$this->add_control(
			'arrow_next_icon',
			array(
				'label'   => esc_html__( 'Next Icon', 'sifency-addons' ),
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'icon-right-open-big',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->add_control(
			'awards_list',
			array(
				'label'       => 'Award Items',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array(
					array(
						'award_year'    => '2023',
						'award_title'   => 'Best Website Design',
						'awarding_body' => 'Digital Awards Inc.',
					),
					array(
						'award_year'    => '2022',
						'award_title'   => 'User Experience Prize',
						'awarding_body' => 'UX Design Magazine',
					),
				),
				'title_field' => '{{{ award_title }}} - {{{ award_year }}}',
				'condition'   => array( 'source' => 'custom' ),
			)
		);
		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'      => 'thumbnail',
				'default'   => 'thumbnail',
				'separator' => 'none',
				'condition' => array( 'show_image' => 'yes' ),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_arg_controls(
			array(
				'default_post' => 'award',
				'condition'    => array( 'source' => 'posts' ),
			)
		);

		$this->start_controls_section( 'section_layout', array( 'label' => 'Layout' ) );

		$this->add_control(
			'layout_style',
			array(
				'label'   => 'Layout',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'list'        => 'Classic List (Timeline)',
					'list-modern' => 'Modern List (Flex)',
					'grid'        => 'Grid',
				),
				'default' => 'list',
			)
		);
		$this->add_control(
			'enable_hover_image',
			array(
				'label'       => 'Mouse Hover Cursor Image',
				'type'        => Controls_Manager::SWITCHER,
				'default'     => '',
				'description' => 'Image floats on cursor movement. Hides static image.',
				'condition'   => array(
					'layout_style!' => 'grid',
					'show_image'    => 'yes',
				),
			)
		);
		$this->add_responsive_control(
			'columns',
			array(
				'label'     => 'Columns',
				'type'      => Controls_Manager::SELECT,
				'default'   => '2',
				'options'   => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-awards--grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ),
				'condition' => array( 'layout_style' => 'grid' ),
			)
		);

		$this->add_responsive_control(
			'gap',
			array(
				'label'     => 'Gap',
				'type'      => Controls_Manager::SLIDER,
				'selectors' => array( '{{WRAPPER}} .sifency-awards--grid, {{WRAPPER}} .sifency-awards--list, {{WRAPPER}} .sifency-awards--list-modern' => 'gap: {{SIZE}}px;' ),
			)
		);
		$this->add_responsive_control(
			'award_image_width',
			array(
				'label'     => 'Image Width',
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 20,
						'max' => 300,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-award-img-wrapper img' => 'width: {{SIZE}}{{UNIT}}; height: auto;' ),
				'condition' => array(
					'show_image'         => 'yes',
					'enable_hover_image' => '',
				),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'selector' => '.award-title_and_content-wrap',
				'prefix'   => 'title_and_content_',
				'label'    => esc_html__( 'Title and Content', 'sifency-addons' ),
				'selector' => '.award-title-and-content',
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'label'    => esc_html__( 'Date & Content', 'sifency-addons' ),
				'selector' => '.award-content-wrap',
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'image_and_content_',
				'label'    => esc_html__( 'Image & Content', 'sifency-addons' ),
				'selector' => '.sifency-award-left',
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_list_timeline_style',
			array(
				'label'     => esc_html__( 'Timeline List Style', 'sifency-addons' ),
				'tab'       => \Elementor\Controls_Manager::TAB_STYLE,
				'condition' => array(
					'layout_style' => 'list',
				),
			)
		);
		$this->add_control(
			'line_heading',
			array(
				'label' => esc_html__( 'Timeline Line', 'sifency-addons' ),
				'type'  => \Elementor\Controls_Manager::HEADING,
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			array(
				'name'           => 'timeline_line_background',
				'label'          => esc_html__( 'Line Background', 'sifency-addons' ),
				'types'          => array( 'classic', 'gradient' ),
				'selector'       => '{{WRAPPER}} .sifency-awards--list::before',
				'fields_options' => array(
					'background' => array(
						'label' => esc_html__( 'Line Type', 'sifency-addons' ),
					),
					'color'      => array(
						'label' => esc_html__( 'Line Color', 'sifency-addons' ),
					),
				),
			)
		);

		$this->add_responsive_control(
			'line_width',
			array(
				'label'      => esc_html__( 'Line Width', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => 1,
						'max' => 10,
					),
				),
				'default'    => array( 'size' => 1 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list::before' => 'width: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'line_top_spacing',
			array(
				'label'      => esc_html__( 'Top Spacing (Padding)', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 0,
						'max' => 150,
					),
				),
				'default'    => array( 'size' => 20 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list::before' => 'top: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'line_bottom_spacing',
			array(
				'label'      => esc_html__( 'Bottom Spacing (Padding)', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => 0,
						'max' => 150,
					),
				),
				'default'    => array( 'size' => 20 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list::before' => 'bottom: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'list_padding_left',
			array(
				'label'      => esc_html__( 'Distance from Line (Padding Left)', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => 0,
						'max' => 100,
					),
				),
				'default'    => array( 'size' => 47 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list' => 'padding-left: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_control(
			'dot_heading',
			array(
				'label'     => esc_html__( 'Timeline Dot', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->add_responsive_control(
			'dot_size',
			array(
				'label'      => esc_html__( 'Dot Size', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => 5,
						'max' => 50,
					),
				),
				'default'    => array( 'size' => 20 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'width: {{SIZE}}{{UNIT}}; height: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_control(
			'dot_bg_color',
			array(
				'label'     => esc_html__( 'Dot BG Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'background-color: {{VALUE}};',
				),
			)
		);

		$this->add_control(
			'dot_border_color',
			array(
				'label'     => esc_html__( 'Dot Border Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'border-color: {{VALUE}};',
				),
			)
		);

		$this->add_responsive_control(
			'dot_border_radius',
			array(
				'label'      => esc_html__( 'Dot Border Radius', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%', 'em' ),
				'default'    => array(
					'top'      => '50',
					'right'    => '50',
					'bottom'   => '50',
					'left'     => '50',
					'unit'     => '%',
					'isLinked' => true,
				),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'dot_top_offset',
			array(
				'label'      => esc_html__( 'Dot Vertical Position', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%' ),
				'range'      => array(
					'px' => array(
						'min' => -50,
						'max' => 100,
					),
				),
				'default'    => array( 'size' => 20 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'top: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->add_responsive_control(
			'dot_left_offset',
			array(
				'label'      => esc_html__( 'Dot Horizontal Position', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::SLIDER,
				'size_units' => array( 'px' ),
				'range'      => array(
					'px' => array(
						'min' => -150,
						'max' => 0,
					),
				),
				'default'    => array( 'size' => -57 ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-awards--list .sifency-award-item::before' => 'left: {{SIZE}}{{UNIT}};',
				),
			)
		);

		$this->end_controls_section();
	}
}
