<?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_Event_Controls {
	use Sifency_Addons_Flex_Controls;

	protected function add_sifency_event_controls( $args = array() ) {
		$this->start_controls_section( 'section_content', array( 'label' => 'Events Content' ) );
		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts',
				),
				'default' => 'custom',
			)
		);
		$this->add_control(
			'show_image',
			array(
				'label'   => 'Show Event Image',
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_date',
			array(
				'label'   => 'Show Date',
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_location',
			array(
				'label'   => 'Show Location',
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_excerpt',
			array(
				'label'   => 'Show Excerpt',
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_button',
			array(
				'label'   => 'Show Button',
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'read_more_text',
			array(
				'label'     => 'Button Text',
				'type'      => Controls_Manager::TEXT,
				'default'   => 'View More',
				'condition' => array(
					'show_button' => 'yes',
					'source'      => 'posts',
				),
			)
		);
		$repeater = new Repeater();
		$repeater->add_control(
			'event_image',
			array(
				'label'   => 'Image',
				'type'    => Controls_Manager::MEDIA,
				'default' => array( 'url' => \Elementor\Utils::get_placeholder_image_src() ),
			)
		);
		$repeater->add_control(
			'title',
			array(
				'label'   => 'Title',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Event Title',
			)
		);
		$repeater->add_control(
			'date',
			array(
				'label'   => 'Date',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Jan 01, 2024',
			)
		);
		$repeater->add_control(
			'location',
			array(
				'label'   => 'Location',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'New York, USA',
			)
		);
		$repeater->add_control(
			'excerpt',
			array(
				'label' => 'Description',
				'type'  => Controls_Manager::TEXTAREA,
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);
		$repeater->add_control(
			'read_more_text',
			array(
				'label'   => 'Button Text',
				'type'    => Controls_Manager::TEXT,
				'default' => 'View More',
			)
		);
		$this->add_control(
			'event_list',
			array(
				'label'       => 'Event Items',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array(
					array(
						'title'    => 'Community Meetup',
						'date'     => 'May 25, 2024',
						'location' => 'Online',
					),
					array(
						'title'    => 'Design Conference',
						'date'     => 'June 10, 2024',
						'location' => 'San Francisco',
					),
				),
				'title_field' => '{{{ title }}}',
				'condition'   => array( 'source' => 'custom' ),
			)
		);
		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'      => 'thumbnail',
				'default'   => 'medium',
				'condition' => array( 'show_image' => 'yes' ),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section( 'section_icons', array( 'label' => 'Icons Settings' ) );
		$this->add_control(
			'date_icon',
			array(
				'label'   => 'Date Icon',
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'icon-calendar-alt',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->add_control(
			'location_icon',
			array(
				'label'   => 'Location Icon',
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'icon-circle',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->add_control(
			'button_icon',
			array(
				'label'   => 'Button Icon',
				'type'    => Controls_Manager::ICONS,
				'default' => array(
					'value'   => 'icon-right-open-big',
					'library' => 'sifency-icons',
				),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_arg_controls(
			array(
				'default_post' => 'event',
				'condition'    => array( 'source' => 'posts' ),
			)
		);
		$this->start_controls_section( 'section_layout', array( 'label' => 'Layout' ) );
		$this->add_control(
			'layout_style',
			array(
				'label'   => 'Layout Style',
				'type'    => Controls_Manager::SELECT,
				'default' => 'style-1',
				'options' => array(
					'style-1' => 'Style 1: Modern List (Row)',
					'style-2' => 'Style 2: Grid Card (Column)',
					'style-3' => 'Style 3: Side Image (Split)',
					'style-5' => 'Style 4: Overlay (Background)',
				),
			)
		);
		$this->add_responsive_control(
			'columns',
			array(
				'label'     => 'Columns',
				'type'      => Controls_Manager::SELECT,
				'default'   => '1',
				'options'   => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
				),
				'selectors' => array( '{{WRAPPER}} .sifency-event-wrapper' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ),
			)
		);
		$this->add_responsive_control(
			'gap',
			array(
				'label'     => 'Gap',
				'type'      => Controls_Manager::SLIDER,
				'default'   => array( 'size' => 30 ),
				'selectors' => array( '{{WRAPPER}} .sifency-event-wrapper' => 'gap: {{SIZE}}px;' ),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'image_flex_',
				'label'    => esc_html__( 'Image Content', 'sifency-addons' ),
				'selector' => '.sifency-event-item',
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'label'    => esc_html__( 'Content Wrap', 'sifency-addons' ),
				'selector' => '.sifency-event-info',
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'meta_',
				'selector' => '.sifency-event-item__meta',
			)
		);
		$this->end_controls_section();
	}
}
