<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit; }
use \Elementor\Controls_Manager;
use Elementor\Utils;
use Elementor\Group_Control_Image_Size;

trait Sifency_Image_Controls {
	protected function add_sifency_image_controls( $args = array() ) {
		$this->start_controls_section(
			'image_section',
			array(
				'label' => esc_html__( 'Image', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'image',
			array(
				'label'   => esc_html__( 'Choose Image', 'sifency-addons' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => array(
					'url' => Utils::get_placeholder_image_src(),
				),
				'dynamic' => array(
					'active' => true,
				),
			)
		);

		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			array(
				'name'    => 'image',
				'default' => 'large',
			)
		);
		$this->add_responsive_control(
			'align',
			array(
				'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => array(
					'left'   => 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',
					),
					'right'  => array(
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-image-wrapper' => 'text-align: {{VALUE}};',
				),
			)
		);
		$this->add_control(
			'caption_source',
			array(
				'label'   => esc_html__( 'Caption', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'none'       => esc_html__( 'None', 'sifency-addons' ),
					'attachment' => esc_html__( 'Attachment Caption', 'sifency-addons' ),
					'custom'     => esc_html__( 'Custom Caption', 'sifency-addons' ),
				),
				'default' => 'none',
			)
		);
		$this->add_control(
			'caption',
			array(
				'label'     => esc_html__( 'Custom Caption', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXTAREA,
				'condition' => array(
					'caption_source' => 'custom',
				),
				'dynamic'   => array(
					'active' => true,
				),
			)
		);
		$this->add_control(
			'link_to',
			array(
				'label'   => esc_html__( 'Link', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'none',
				'options' => array(
					'none'   => esc_html__( 'None', 'sifency-addons' ),
					'file'   => esc_html__( 'Media File (Lightbox)', 'sifency-addons' ),
					'custom' => esc_html__( 'Custom URL', 'sifency-addons' ),
				),
			)
		);
		$this->add_control(
			'link',
			array(
				'label'       => esc_html__( 'Link', 'sifency-addons' ),
				'type'        => Controls_Manager::URL,
				'dynamic'     => array(
					'active' => true,
				),
				'placeholder' => esc_html__( 'https://your-link.com', 'sifency-addons' ),
				'condition'   => array(
					'link_to' => 'custom',
				),
				'show_label'  => false,
			)
		);
		$this->end_controls_section();
	}
}
