<?php
namespace Sifency\Traits;

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

trait Sifency_Blog_Controls {

	protected function add_sifency_blog_controls( $args = array() ) {
		// --- Layout Section ---
		$this->start_controls_section(
			'section_layout',
			array(
				'label' => esc_html__( 'Layout Settings', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'skin_layout',
			array(
				'label'        => esc_html__( 'Skin Design', 'sifency-addons' ),
				'type'         => Controls_Manager::SELECT,
				'default'      => 'classic',
				'options'      => array(
					'classic'  => esc_html__( 'Classic Card', 'sifency-addons' ),
					'overlay'  => esc_html__( 'Overlay (Image Background)', 'sifency-addons' ),
					'list'     => esc_html__( 'List View (Left Image)', 'sifency-addons' ),
					'floating' => esc_html__( 'Floating Date Box', 'sifency-addons' ),
					'minimal'  => esc_html__( 'Minimal Clean', 'sifency-addons' ),
				),
				'prefix_class' => 'sifency-skin-',
			)
		);
		$this->add_control(
			'layout_style',
			array(
				'label'   => esc_html__( 'Grid Structure', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => array(
					'grid'     => esc_html__( 'Grid', 'sifency-addons' ),
					'carousel' => esc_html__( 'Carousel', 'sifency-addons' ),
				),
				'default' => 'grid',
			)
		);

		$this->add_responsive_control(
			'columns',
			array(
				'label'          => esc_html__( 'Columns', 'sifency-addons' ),
				'type'           => Controls_Manager::SELECT,
				'default'        => '3',
				'tablet_default' => '2',
				'mobile_default' => '1',
				'options'        => array(
					'1' => '1',
					'2' => '2',
					'3' => '3',
					'4' => '4',
					'5' => '5',
					'6' => '6',
				),
				'selectors'      => array( '{{WRAPPER}} .sifency-addons-blog-grid' => 'grid-template-columns: repeat({{VALUE}}, 1fr);' ),
				'condition'      => array( 'layout_style' => 'grid' ),
			)
		);

		$this->add_responsive_control(
			'gap',
			array(
				'label'     => esc_html__( 'Gap', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'default'   => array( 'size' => 30 ),
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 100,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-addons-blog-grid' => 'gap: {{SIZE}}{{UNIT}};' ),
				'condition' => array( 'layout_style' => 'grid' ),
			)
		);
		$this->add_control(
			'hr_content',
			array(
				'type' => \Elementor\Controls_Manager::DIVIDER,
			)
		);

		// --- Element Visibility ---

		$this->add_control(
			'show_thumbnail',
			array(
				'label'   => esc_html__( 'Show Image', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'show_date',
			array(
				'label'   => esc_html__( 'Show Date', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'yes',
			)
		);
		$this->add_control(
			'date_format',
			array(
				'label'     => esc_html__( 'Date Format', 'sifency-addons' ),
				'type'      => Controls_Manager::SELECT,
				'default'   => 'default',
				'options'   => array(
					'default' => esc_html__( 'Default', 'sifency-addons' ),
					'custom'  => esc_html__( 'Custom', 'sifency-addons' ),
				),
				'condition' => array( 'show_date' => 'yes' ),
			)
		);
		$this->add_control(
			'custom_date_format',
			array(
				'label'       => esc_html__( 'Custom Format string', 'sifency-addons' ),
				'type'        => Controls_Manager::TEXT,
				'default'     => 'F j, Y',
				'description' => sprintf( /* translators: See %1$sphp date formats%2$s */ esc_html__( 'See %1$sphp date formats%2$s.', 'sifency-addons' ), '<a href="https://www.php.net/manual/en/function.date.php" target="_blank">', '</a>' ),
				'condition'   => array(
					'show_date'   => 'yes',
					'date_format' => 'custom',
				),
			)
		);

		$this->add_control(
			'date_icon',
			array(
				'label'     => esc_html__( 'Date Icon', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::ICONS,
				'condition' => array(
					'show_date' => 'yes',
				),
			)
		);
		$this->add_control(
			'show_excerpt',
			array(
				'label'     => esc_html__( 'Show Excerpt', 'sifency-addons' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
				'separator' => 'before',
			)
		);
		$this->add_control(
			'excerpt_length',
			array(
				'label'     => esc_html__( 'Excerpt Length (Words)', 'sifency-addons' ),
				'type'      => Controls_Manager::NUMBER,
				'default'   => 20,
				'condition' => array( 'show_excerpt' => 'yes' ),
			)
		);
		$this->add_control(
			'show_read_more',
			array(
				'label'     => esc_html__( 'Show Read More', 'sifency-addons' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
				'separator' => 'before',
			)
		);
		$this->add_control(
			'read_more_text',
			array(
				'label'     => esc_html__( 'Read More Text', 'sifency-addons' ),
				'type'      => Controls_Manager::TEXT,
				'default'   => esc_html__( 'Read More', 'sifency-addons' ),
				'condition' => array( 'show_read_more' => 'yes' ),
			)
		);
		$this->add_control(
			'read_more_icon',
			array(
				'label'     => esc_html__( 'Button Icon', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::ICONS,
				'condition' => array( 'show_read_more' => 'yes' ),
			)
		);

		// --- Category Controls ---
		$this->add_control(
			'show_category',
			array(
				'label'     => esc_html__( 'Show Category', 'sifency-addons' ),
				'type'      => Controls_Manager::SWITCHER,
				'default'   => 'yes',
				'separator' => 'before',
			)
		);
		$this->add_control(
			'category_limit',
			array(
				'label'       => esc_html__( 'Max Categories', 'sifency-addons' ),
				'type'        => Controls_Manager::NUMBER,
				'min'         => 1,
				'placeholder' => esc_html__( 'All', 'sifency-addons' ),
				'condition'   => array( 'show_category' => 'yes' ),
				'description' => esc_html__( 'Leave empty to show all categories.', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'category_icon',
			array(
				'label'     => esc_html__( 'Category Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'condition' => array( 'show_category' => 'yes' ),
			)
		);

		// --- Tag Controls ---
		$this->add_control(
			'show_tags',
			array(
				'label'   => esc_html__( 'Show Tags', 'sifency-addons' ),
				'type'    => Controls_Manager::SWITCHER,
				'default' => 'no',
			)
		);
		$this->add_control(
			'tag_limit',
			array(
				'label'       => esc_html__( 'Max Tags', 'sifency-addons' ),
				'type'        => Controls_Manager::NUMBER,
				'min'         => 1,
				'placeholder' => esc_html__( 'All', 'sifency-addons' ),
				'condition'   => array( 'show_tags' => 'yes' ),
				'description' => esc_html__( 'Leave empty to show all tags.', 'sifency-addons' ),
			)
		);
		$this->add_control(
			'tag_icon',
			array(
				'label'     => esc_html__( 'Tag Icon', 'sifency-addons' ),
				'type'      => Controls_Manager::ICONS,
				'condition' => array( 'show_tags' => 'yes' ),
			)
		);

		$this->add_sifency_addons_flex_alignment_controls(
			array(
				'prefix'   => 'flex_',
				'label'    => esc_html__( 'Blog Inner Wrapper', 'sifency-addons' ),
				'selector' => '.sifency-blog-inner-wrapper',
			)
		);
		$this->end_controls_section();
	}
}
