<?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 = [] ) {
		$this->start_controls_section(
			'image_section',
			[
				'label' => esc_html__( 'Image', 'sifency-addons' ),
			]
		);

		$this->add_control(
			'image',
			[
				'label'   => esc_html__( 'Choose Image', 'sifency-addons' ),
				'type'    => Controls_Manager::MEDIA,
				'default' => [
					'url' => Utils::get_placeholder_image_src(),
				],
				'dynamic' => [
					'active' => true,
				],
			]
		);

		$this->add_group_control(
			Group_Control_Image_Size::get_type(),
			[
				'name'    => 'image',
				'default' => 'large',
			]
		);

		$this->add_responsive_control(
			'align',
			[
				'label'     => esc_html__( 'Alignment', 'sifency-addons' ),
				'type'      => Controls_Manager::CHOOSE,
				'options'   => [
					'left'   => [
						'title' => esc_html__( 'Left', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-left',
					],
					'center' => [
						'title' => esc_html__( 'Center', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-center',
					],
					'right'  => [
						'title' => esc_html__( 'Right', 'sifency-addons' ),
						'icon'  => 'eicon-text-align-right',
					],
				],
				'selectors' => [
					'{{WRAPPER}} .sifency-image-wrapper' => 'text-align: {{VALUE}};',
				],
			]
		);

		$this->add_control(
			'caption_source',
			[
				'label'   => esc_html__( 'Caption', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => [
					'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',
			[
				'label'     => esc_html__( 'Custom Caption', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXTAREA,
				'condition' => [
					'caption_source' => 'custom',
				],
				'dynamic'   => [
					'active' => true,
				],
			]
		);

		$this->add_control(
			'link_to',
			[
				'label'   => esc_html__( 'Link', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'default' => 'none',
				'options' => [
					'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',
			[
				'label'       => esc_html__( 'Link', 'sifency-addons' ),
				'type'        => Controls_Manager::URL,
				'dynamic'     => [
					'active' => true,
				],
				'placeholder' => esc_html__( 'https://your-link.com', 'sifency-addons' ),
				'condition'   => [
					'link_to' => 'custom',
				],
				'show_label'  => false,
			]
		);

		$this->end_controls_section();
	}
}