<?php
/**
 * A reusable Elementor trait for adding a comprehensive and generic "Item" style preset.
 *
 * This trait applies styles to any element with the '.sifency-item-style' class, making it
 * perfect for styling the container of loop items (blog posts, products, team members, etc.).
 *
 * @package Sifency\Traits
 */

namespace Sifency\Traits;

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

use Elementor\Controls_Manager;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Border;
use Elementor\Group_Control_Box_Shadow;

/**
 * Trait Sifency_Item_Style_Controls
 */
trait Sifency_Item_Style_Controls {

	/**
	 * Adds the complete item styling control panel to the current widget instance.
	 *
	 * @param array $args { Optional. Arguments to customize the controls.
	 *     @type string $prefix        A unique prefix for control names.
	 *     @type string $section_label The label for the style section.
	 * }
	 */
	protected function add_sifency_item_style_controls( $args = [] ) {
		$args = wp_parse_args( $args, [
			'prefix'        => 'item_',
			'section_label' => esc_html__( 'Item Style', 'sifency-addons' ),
		] );

		$prefix   = $args['prefix'];
		$selector = '{{WRAPPER}} .sifency-item-style';

		$this->start_controls_section(
			$prefix . 'style_section',
			[ 'label' => $args['section_label'], 'tab' => Controls_Manager::TAB_STYLE ]
		);

		$this->start_controls_tabs( $prefix . 'style_tabs' );

		// --- NORMAL TAB ---
		$this->start_controls_tab( $prefix . 'normal_tab', [ 'label' => esc_html__( 'Normal', 'sifency-addons' ) ] );
		$this->add_group_control( Group_Control_Background::get_type(), [ 'name' => $prefix . 'background', 'selector' => $selector ] );
		$this->add_group_control( Group_Control_Border::get_type(), [ 'name' => $prefix . 'border', 'selector' => $selector ] );
		$this->add_responsive_control( $prefix . 'border_radius', [ 'label' => esc_html__( 'Border Radius', 'sifency-addons' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', '%' ], 'selectors' => [ $selector => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ] );
		$this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => $prefix . 'box_shadow', 'selector' => $selector ] );
		$this->end_controls_tab();

		// --- HOVER TAB ---
		$this->start_controls_tab( $prefix . 'hover_tab', [ 'label' => esc_html__( 'Hover', 'sifency-addons' ) ] );
		$this->add_group_control( Group_Control_Background::get_type(), [ 'name' => $prefix . 'hover_background', 'selector' => $selector . ':hover' ] );
		$this->add_control( $prefix . 'hover_border_color', [ 'label' => esc_html__( 'Border Color', 'sifency-addons' ), 'type' => Controls_Manager::COLOR, 'selectors' => [ $selector . ':hover' => 'border-color: {{VALUE}};' ] ] );
		$this->add_group_control( Group_Control_Box_Shadow::get_type(), [ 'name' => $prefix . 'hover_box_shadow', 'selector' => $selector . ':hover' ] );
		$this->add_control(
			$prefix . 'hover_transform',
			[
				'label' => esc_html__( 'Hover Transform', 'sifency-addons' ),
				'type' => Controls_Manager::SELECT,
				'options' => [ '' => 'None', 'translateY(-8px)' => 'Lift Up', 'scale(1.05)' => 'Scale Up' ],
				'selectors' => [ $selector . ':hover' => 'transform: {{VALUE}};' ],
			]
		);
		$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->add_control( 'hr_item_spacing_' . $prefix, [ 'type' => Controls_Manager::DIVIDER, 'style' => 'thick' ] );
		
		$this->add_responsive_control( $prefix . 'padding', [ 'label' => esc_html__( 'Padding', 'sifency-addons' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', '%' ], 'selectors' => [ $selector => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ] );
		$this->add_responsive_control( $prefix . 'margin', [ 'label' => esc_html__( 'Margin', 'sifency-addons' ), 'type' => Controls_Manager::DIMENSIONS, 'size_units' => [ 'px', 'em', '%' ], 'selectors' => [ $selector => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ] );
		
		$this->add_control( $prefix . 'transition_duration', [ 'label' => esc_html__( 'Transition Duration (s)', 'sifency-addons' ), 'type' => Controls_Manager::SLIDER, 'range' => [ 'px' => [ 'max' => 2, 'step' => 0.1 ] ], 'default' => [ 'size' => 0.3 ], 'selectors' => [ $selector => 'transition: all {{SIZE}}s ease-in-out;' ] ] );

		$this->end_controls_section();
	}
}