<?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_Sticky_Stack;
use Sifency\Traits\Sifency_Addons_Floating_Count_Controls;

trait Sifency_Projects_Controls {
	use Sifency_Addons_Sticky_Stack;
	use Sifency_Addons_Floating_Count_Controls;

	protected function add_sifency_projects_controls( $args = array() ) {

		$this->start_controls_section( 'section_content', array( 'label' => 'Portfolio Content' ) );

		$this->add_control(
			'source',
			array(
				'label'   => 'Source',
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'custom' => 'Custom',
					'posts'  => 'Posts',
				),
				'default' => 'custom',
			)
		);

		$repeater = new Repeater();
		$repeater->add_control(
			'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' => 'Project Title',
			)
		);
		$repeater->add_control(
			'category',
			array(
				'label'   => 'Category',
				'type'    => Controls_Manager::TEXTAREA,
				'default' => 'Web Design',
			)
		);
		$repeater->add_control(
			'link',
			array(
				'label'   => 'Link',
				'type'    => Controls_Manager::URL,
				'default' => array( 'is_external' => 'true' ),
			)
		);

		$this->add_control(
			'project_list',
			array(
				'label'       => 'Portfolio Items',
				'type'        => Controls_Manager::REPEATER,
				'fields'      => $repeater->get_controls(),
				'default'     => array( array( 'title' => 'Project #1' ), array( 'title' => 'Project #2' ) ),
				'title_field' => '{{{ title }}}',
				'condition'   => array( 'source' => 'custom' ),
			)
		);
		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'    => 'thumbnail',
				'default' => 'large',
			)
		);

		$this->end_controls_section();

		$this->start_controls_section( 'section_settings', array( 'label' => 'Settings' ) );
		$this->add_control(
			'show_count',
			array(
				'label'   => esc_html__( 'Show Item Count', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_sifency_addons_floating_count_controls();
		$this->add_control(
			'show_excerpt',
			array(
				'label'        => esc_html__( 'Show Excerpt', 'sifency-addons' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'sifency-addons' ),
				'label_off'    => esc_html__( 'Hide', 'sifency-addons' ),
				'return_value' => 'yes',
				'default'      => 'yes',
				'condition'    => array( 'source' => 'posts' ),
			)
		);
		$this->add_control(
			'show_category',
			array(
				'label'        => esc_html__( 'Show Category', 'sifency-addons' ),
				'type'         => \Elementor\Controls_Manager::SWITCHER,
				'label_on'     => esc_html__( 'Show', 'sifency-addons' ),
				'label_off'    => esc_html__( 'Hide', 'sifency-addons' ),
				'return_value' => 'yes',
				'condition'    => array( 'source' => 'posts' ),
			)
		);
		$this->add_control(
			'show_read_more',
			array(
				'label'   => esc_html__( 'Show Button', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'read_more_text',
			array(
				'label'     => esc_html__( 'Button Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => esc_html__( 'View Project', 'sifency-addons' ),
				'condition' => array( 'show_read_more' => 'yes' ),
			)
		);
		$this->add_control(
			'button_next_icon',
			array(
				'label'     => esc_html__( 'Button Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'default'   => array(
					'value'   => 'icon-right-open-big',
					'library' => 'sifency-icons',
				),
				'condition' => array( 'show_read_more' => 'yes' ),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_arg_controls(
			array(
				'default_post' => 'portfolio',
				'condition'    => array( 'source' => 'posts' ),
			)
		);
		$this->start_controls_section( 'section_layout', array( 'label' => 'Layout Settings' ) );

		$this->add_control(
			'display_type',
			array(
				'label'     => 'Display Type',
				'type'      => Controls_Manager::SELECT,
				'options'   => array(
					'grid'     => 'Grid',
					'carousel' => 'Carousel',
				),
				'default'   => 'grid',
				'condition' => array( 'layout_style!' => 'style-3' ),
			)
		);
		$this->add_control(
			'layout_style',
			array(
				'label'   => esc_html__( 'Design Style', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'style-1',
				'options' => array(
					'style-1' => esc_html__( 'Style 1: Overlay Gradient (Modern)', 'sifency-addons' ),
					'style-2' => esc_html__( 'Style 2: Classic Card (Clean)', 'sifency-addons' ),
					'style-3' => esc_html__( 'Style 3: Interactive List (Hover Image)', 'sifency-addons' ),
					'style-4' => esc_html__( 'Style 4: Minimal Hover (Box)', 'sifency-addons' ),
					'style-5' => esc_html__( 'Style 5: Alternating Split (Masonry Feel)', 'sifency-addons' ),
				),
			)
		);
		$this->add_responsive_control(
			'columns',
			array(
				'label'          => 'Columns',
				'type'           => Controls_Manager::SELECT,
				'default'        => '3',
				'tablet_default' => '2',
				'mobile_default' => '1',
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
				),
				'selectors'      => array( '{{WRAPPER}} .sifency-portfolio--grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ),
				'condition'      => array(
					'display_type'  => 'grid',
					'layout_style!' => array( 'style-3', 'style-5' ),
				),
			)
		);
		$this->add_responsive_control(
			'gap',
			array(
				'label'     => 'Gap',
				'type'      => Controls_Manager::SLIDER,
				'default'   => array( 'size' => 30 ),
				'selectors' => array(
					'{{WRAPPER}} .sifency-portfolio--grid' => 'gap: {{SIZE}}px;',
					'{{WRAPPER}} .sifency-portfolio-style-3 .sifency-portfolio-item' => 'margin-bottom: {{SIZE}}px;',
				),
			)
		);
		$this->add_responsive_control(
			'button_alignment',
			array(
				'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'flex-start' => array(
						'title' => esc_html__( 'Left', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-left',
					),
					'center'     => array(
						'title' => esc_html__( 'Center', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-center',
					),
					'flex-end'   => array(
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'default'   => 'flex-start',
				'selectors' => array(
					'{{WRAPPER}} .sifency-pf-btn' => 'align-self: {{VALUE}};',
				),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'selector'  => '.sifency-content-wrap',
				'condition' => array( 'layout_style!' => 'style-3' ),
			)
		);
		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'label'     => esc_html__( 'Count & Content', 'sifency-addons' ),
				'prefix'    => 'count_content_flex',
				'selector'  => '.sifency-list-left',
				'condition' => array( 'layout_style' => 'style-3' ),
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'section_style_overlay',
			array(
				'label'     => esc_html__( 'Overlay', 'sifency-addons' ),
				'tab'       => Controls_Manager::TAB_STYLE,
				'condition' => array( 'layout_style!' => 'style-3' ),
			)
		);
		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			array(
				'name'     => 'overlay_background',
				'label'    => esc_html__( 'Background', 'sifency-addons' ),
				'types'    => array( 'classic', 'gradient' ),
				'selector' => '{{WRAPPER}} .sifency-image-overlay, {{WRAPPER}} .sifency-portfolio-style-1 .sifency-portfolio-image::after',
			)
		);
		$this->add_control(
			'overlay_opacity',
			array(
				'label'     => esc_html__( 'Opacity', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'max'  => 1,
						'min'  => 0,
						'step' => 0.01,
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-image-overlay, {{WRAPPER}} .sifency-portfolio-style-1 .sifency-portfolio-image::after' => 'opacity: {{SIZE}};',
				),
			)
		);
		$this->add_control(
			'overlay_hover_opacity',
			array(
				'label'     => esc_html__( 'Hover Opacity', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'max'  => 1,
						'min'  => 0,
						'step' => 0.01,
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-portfolio-item:hover .sifency-image-overlay, {{WRAPPER}} .sifency-portfolio-style-1 .sifency-portfolio-item:hover .sifency-portfolio-image::after' => 'opacity: {{SIZE}};',
				),
			)
		);
		$this->end_controls_section();
		$this->add_sifency_addons_floating_count_style_controls();
		$this->add_sifency_addons_sticky_stack();
	}
}
