<?php
namespace Sifency\Traits;

if ( ! defined( 'ABSPATH' ) ) {
	exit;  }
use Elementor\Controls_Manager;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
trait Sifency_Form_Controls {
	protected function add_sifency_form_controls( $args = array() ) {
		$this->start_controls_section(
			'section_content',
			array( 'label' => __( 'Form', 'sifency-addons' ) )
		);
		$this->add_control(
			'selected_form',
			array(
				'label'   => __( 'Select Form', 'sifency-addons' ),
				'type'    => Controls_Manager::SELECT,
				'options' => sifency_addons_get_all_forms(),
				'default' => '',
			)
		);
		$this->end_controls_section();
		$this->start_controls_section(
			'form_fields_style',
			array(
				'label' => __( 'Form Fields', 'sifency-addons' ),
				'tab'   => Controls_Manager::TAB_STYLE,
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'label_typography',
				'selector' => '{{WRAPPER}} .sifency-form-styler form label',
			)
		);
		$this->add_control(
			'label_color',
			array(
				'label'     => __( 'Label Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form label' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'label_spacing',
			array(
				'label'     => __( 'Label Spacing', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 0,
						'max' => 50,
					),
				),
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form label' => 'margin-bottom: {{SIZE}}px;' ),
			)
		);
		$this->add_responsive_control(
			'label_width',
			array(
				'label'      => esc_html__( 'Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%', 'em', 'rem', 'vw' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form label' => 'width: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_control(
			'field_heading',
			array(
				'label'     => __( 'Input & Textarea', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);
		$this->add_responsive_control(
			'field_width',
			array(
				'label'      => esc_html__( 'Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%', 'em', 'rem', 'vw' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input:not([type=submit])' => 'width: {{SIZE}}{{UNIT}}; display:inline-flex; align-items:center; justify-content:center;',
				),
			)
		);
		$this->add_responsive_control(
			'textarea_width',
			array(
				'label'      => esc_html__( 'Textarea Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%', 'em', 'rem', 'vw' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form textarea' => 'width: {{SIZE}}{{UNIT}}; display:inline-flex; align-items:center; justify-content:center;',
				),
			)
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			array(
				'name'     => 'input_typography',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea',
			)
		);
		$this->add_control(
			'field_text_color',
			array(
				'label'     => __( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'field_placeholder_color',
			array(
				'label'     => __( 'Placeholder Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input::placeholder, {{WRAPPER}} .sifency-form-styler form textarea::placeholder' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'field_bg_color',
			array(
				'label'     => __( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'field_border',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea',
			)
		);
		$this->add_control(
			'field_border_radius',
			array(
				'label'     => __( 'Border Radius', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'field_margin',
			array(
				'label'     => __( 'Margin', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'field_Padding',
			array(
				'label'     => __( 'Padding', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_control(
			'field_focus_heading',
			array(
				'label'     => __( 'Focus State', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);
		$this->add_control(
			'field_focus_border_color',
			array(
				'label'     => __( 'Border Color (Focus)', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:focus, {{WRAPPER}} .sifency-form-styler form textarea:focus' => 'border-color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'field_focus_bg_color',
			array(
				'label'     => __( 'Background (Focus)', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form input:focus, {{WRAPPER}} .sifency-form-styler form textarea:focus' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'select_field_heading',
			array(
				'label'     => __( 'Select Dropdown', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);
		$this->add_responsive_control(
			'select_width',
			array(
				'label'      => esc_html__( 'Width', 'sifency-addons' ),
				'type'       => Controls_Manager::SLIDER,
				'size_units' => array( 'px', '%', 'em', 'rem', 'vw' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form select' => 'width: {{SIZE}}{{UNIT}};',
				),
			)
		);
		$this->add_control(
			'select_bg_color',
			array(
				'label'     => __( 'Background Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form select' => 'background-color: {{VALUE}};' ),
			)
		);
		$this->add_control(
			'select_text_color',
			array(
				'label'     => __( 'Text Color', 'sifency-addons' ),
				'type'      => Controls_Manager::COLOR,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form select' => 'color: {{VALUE}};' ),
			)
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			array(
				'name'     => 'select_border',
				'selector' => '{{WRAPPER}} .sifency-form-styler form select',
			)
		);
		$this->add_responsive_control(
			'select_padding',
			array(
				'label'     => __( 'Padding', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form select' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		$this->add_responsive_control(
			'select_margin',
			array(
				'label'     => __( 'Margin', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form select' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);

		$this->add_control(
			'dropdown_border_radius',
			array(
				'label'     => __( 'Border Radius', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array( '{{WRAPPER}} .sifency-form-styler form select' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ),
			)
		);
		/*
		-------------------------------------------------------------------------- */
		/*
									Checkbox & Radio Styles                           */
		/* -------------------------------------------------------------------------- */
		$this->add_control(
			'checkbox_radio_heading',
			array(
				'label'     => __( 'Checkbox & Radio', 'sifency-addons' ),
				'type'      => Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);
		$this->add_responsive_control(
			'check_radio_size',
			array(
				'label'     => __( 'Size', 'sifency-addons' ),
				'type'      => Controls_Manager::SLIDER,
				'range'     => array(
					'px' => array(
						'min' => 10,
						'max' => 50,
					),
				),
				'selectors' => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="checkbox"], {{WRAPPER}} .sifency-form-styler form input[type="radio"]' => 'width: {{SIZE}}px; height: {{SIZE}}px;',
				),
			)
		);
		$this->add_control(
			'check_radio_accent_color',
			array(
				'label'       => __( 'Accent Color', 'sifency-addons' ),
				'type'        => Controls_Manager::COLOR,
				'description' => __( 'Works on modern browsers for checkboxes/radios', 'sifency-addons' ),
				'selectors'   => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="checkbox"], {{WRAPPER}} .sifency-form-styler form input[type="radio"]' => 'accent-color: {{VALUE}};',
				),
			)
		);
		$this->add_responsive_control(
			'check_radio_margin',
			array(
				'label'     => __( 'Margin', 'sifency-addons' ),
				'type'      => Controls_Manager::DIMENSIONS,
				'selectors' => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="checkbox"], {{WRAPPER}} .sifency-form-styler form input[type="radio"]' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->end_controls_section();
		/*
		-------------------------------------------------------------------------- */
		/*
									File Upload / Media                             */
		/* -------------------------------------------------------------------------- */
		$this->start_controls_section(
			'section_file_upload_style',
			array(
				'label' => __( 'File Upload / Media', 'sifency-addons' ),
				'tab'   => \Elementor\Controls_Manager::TAB_STYLE,
			)
		);

		$this->add_control(
			'file_field_heading',
			array(
				'label'     => __( 'File Field (Input)', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->add_control(
			'file_text_color',
			array(
				'label'     => __( 'Text Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]' => 'color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Typography::get_type(),
			array(
				'name'     => 'file_typography',
				'label'    => __( 'Typography', 'sifency-addons' ),
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]',
			)
		);

		// ── Wrapper (the whole input[type="file"]) ────────────────────────────────
		$this->add_control(
			'file_wrapper_heading',
			array(
				'label'     => __( 'File Field Wrapper', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->start_controls_tabs( 'file_wrapper_tabs' );

		$this->start_controls_tab(
			'file_wrapper_normal',
			array(
				'label' => esc_html__( 'Normal', 'sifency-addons' ),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			array(
				'name'     => 'file_wrapper_bg',
				'label'    => __( 'Background', 'sifency-addons' ),
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]',
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name'     => 'file_wrapper_border',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]',
			)
		);

		$this->add_control(
			'file_wrapper_padding',
			array(
				'label'      => __( 'Padding', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_control(
			'file_wrapper_margin',
			array(
				'label'      => __( 'Margin', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->end_controls_tab();

		$this->start_controls_tab(
			'file_wrapper_hover',
			array(
				'label' => esc_html__( 'Hover', 'sifency-addons' ),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Background::get_type(),
			array(
				'name'     => 'file_wrapper_bg_hover',
				'label'    => __( 'Hover Background', 'sifency-addons' ),
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]:hover',
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name'     => 'file_wrapper_border_hover',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]:hover',
			)
		);

		$this->add_control(
			'file_wrapper_padding_hover',
			array(
				'label'      => __( 'Hover Padding', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]:hover' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->add_control(
			'file_wrapper_margin_hover',
			array(
				'label'      => __( 'Hover Margin', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]:hover' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);

		$this->end_controls_tab();
		$this->end_controls_tabs();

		// ── File Button (Browse / Choose File button) ─────────────────────────────
		$this->add_control(
			'file_button_heading',
			array(
				'label'     => __( 'Choose File Button', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::HEADING,
				'separator' => 'before',
			)
		);

		$this->start_controls_tabs( 'file_button_tabs' );

		$this->start_controls_tab(
			'file_button_normal',
			array(
				'label' => esc_html__( 'Normal', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'file_button_bg',
			array(
				'label'     => __( 'Background Color', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button' => 'background-color: {{VALUE}};',
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button' => 'background-color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name'     => 'file_button_border',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button, {{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button',
			)
		);

		$this->add_control(
			'file_button_border_radius',
			array(
				'label'      => __( 'Border Radius', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
			)
		);
		$this->add_control(
			'file_button_padding',
			array(
				'label'      => __( 'Padding', 'sifency-addons' ),
				'type'       => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units' => array( 'px', 'em', '%' ),
				'selectors'  => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
				'default'    => array(
					'top'      => '8',
					'right'    => '16',
					'bottom'   => '8',
					'left'     => '16',
					'unit'     => 'px',
					'isLinked' => false,
				),
			)
		);

		$this->add_control(
			'file_button_margin',
			array(
				'label'       => __( 'Margin', 'sifency-addons' ),
				'type'        => \Elementor\Controls_Manager::DIMENSIONS,
				'size_units'  => array( 'px', 'em', '%' ),
				'selectors'   => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				),
				'default'     => array(
					'top'      => '0',
					'right'    => '12',
					'bottom'   => '0',
					'left'     => '0',
					'unit'     => 'px',
					'isLinked' => false,
				),
				'description' => __( 'Commonly used: margin-right to separate button from "No file chosen" text.', 'sifency-addons' ),
			)
		);
		$this->end_controls_tab();

		$this->start_controls_tab(
			'file_button_hover',
			array(
				'label' => esc_html__( 'Hover', 'sifency-addons' ),
			)
		);

		$this->add_control(
			'file_button_bg_hover',
			array(
				'label'     => __( 'Hover Background', 'sifency-addons' ),
				'type'      => \Elementor\Controls_Manager::COLOR,
				'selectors' => array(
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button:hover' => 'background-color: {{VALUE}};',
					'{{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button:hover' => 'background-color: {{VALUE}};',
				),
			)
		);

		$this->add_group_control(
			\Elementor\Group_Control_Border::get_type(),
			array(
				'name'     => 'file_button_border_hover',
				'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="file"]::file-selector-button:hover, {{WRAPPER}} .sifency-form-styler form input[type="file"]::-webkit-file-upload-button:hover',
			)
		);

		$this->end_controls_tab();
		$this->end_controls_tabs();

		$this->end_controls_section();
	}
}
