<?php
namespace Sifency\Traits;
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}
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 = [] ) {
      $this->start_controls_section(
            'section_content',
            [ 'label' => __('Form', 'sifency-addons') ]
        );
        $this->add_control(
            'selected_form',
            [
                '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',
            [ 'label' => __('Form Fields', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );

        // Label Typography & Color
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [ 'name' => 'label_typography', 'selector' => '{{WRAPPER}} .sifency-form-styler form label' ]
        );

        $this->add_control(
            'label_color',
            [ 'label' => __('Label Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form label' => 'color: {{VALUE}};' ] ]
        );

        $this->add_control(
            'label_spacing',
            [
                'label' => __('Label Spacing', 'sifency-addons'),
                'type' => Controls_Manager::SLIDER,
                'range' => [ 'px' => [ 'min' => 0, 'max' => 50 ] ],
                'selectors' => [ '{{WRAPPER}} .sifency-form-styler form label' => 'margin-bottom: {{SIZE}}px;' ],
            ]
        );

        $this->add_control(
            'field_heading',
            [
                'label' => __('Input & Textarea', 'sifency-addons'),
                'type' => Controls_Manager::HEADING,
                'separator' => 'before',
            ]
        );

        // Input Typography
        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [ 'name' => 'input_typography', 'selector' => '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' ]
        );

        // Colors & Background
        $this->add_control(
            'field_text_color',
            [ 'label' => __('Text Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'color: {{VALUE}};' ] ]
        );

        $this->add_control(
            'field_placeholder_color',
            [ 'label' => __('Placeholder Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input::placeholder, {{WRAPPER}} .sifency-form-styler form textarea::placeholder' => 'color: {{VALUE}};' ] ]
        );

        $this->add_control(
            'field_bg_color',
            [ 'label' => __('Background Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'background-color: {{VALUE}};' ] ]
        );

        // Border + Radius + Padding
        $this->add_group_control(
            Group_Control_Border::get_type(),
            [ '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',
            [ 'label' => __('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{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_padding',
            [ 'label' => __('Padding', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input:not([type=submit]), {{WRAPPER}} .sifency-form-styler form textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]
        );

        // Focus State
        $this->add_control(
            'field_focus_heading',
            [ 'label' => __('Focus State', 'sifency-addons'), 'type' => Controls_Manager::HEADING, 'separator' => 'before' ]
        );

        $this->add_control(
            'field_focus_border_color',
            [ 'label' => __('Border Color (Focus)', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input:focus, {{WRAPPER}} .sifency-form-styler form textarea:focus' => 'border-color: {{VALUE}};' ] ]
        );

        $this->add_control(
            'field_focus_bg_color',
            [ 'label' => __('Background (Focus)', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input:focus, {{WRAPPER}} .sifency-form-styler form textarea:focus' => 'background-color: {{VALUE}};' ] ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'form_button_style',
            [ 'label' => __('Submit Button', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );

        $this->add_group_control(
            Group_Control_Typography::get_type(),
            [ 'name' => 'button_typography', 'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' ]
        );

        $this->start_controls_tabs('button_tabs');
        
        // Normal
        $this->start_controls_tab('button_normal_tab', [ 'label' => __('Normal', 'sifency-addons') ]);
        $this->add_control('button_text_color', [ 'label' => __('Text Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' => 'color: {{VALUE}};' ] ]);
        $this->add_control('button_bg_color', [ 'label' => __('Background', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' => 'background-color: {{VALUE}};' ] ]);
        $this->end_controls_tab();

        // Hover
        $this->start_controls_tab('button_hover_tab', [ 'label' => __('Hover', 'sifency-addons') ]);
        $this->add_control('button_hover_text_color', [ 'label' => __('Text Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"]:hover, {{WRAPPER}} .sifency-form-styler form button[type="submit"]:hover' => 'color: {{VALUE}};' ] ]);
        $this->add_control('button_hover_bg_color', [ 'label' => __('Background', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"]:hover, {{WRAPPER}} .sifency-form-styler form button[type="submit"]:hover' => 'background-color: {{VALUE}};' ] ]);
        $this->end_controls_tab();

        $this->end_controls_tabs();

        $this->add_group_control(
            Group_Control_Border::get_type(),
            [ 'name' => 'button_border', 'selector' => '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' ]
        );

        $this->add_control(
            'button_border_radius',
            [ 'label' => __('Border Radius', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]
        );

        $this->add_responsive_control(
            'button_padding',
            [ 'label' => __('Padding', 'sifency-addons'), 'type' => Controls_Manager::DIMENSIONS, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler form input[type="submit"], {{WRAPPER}} .sifency-form-styler form button[type="submit"]' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};' ] ]
        );

        $this->end_controls_section();
        $this->start_controls_section(
            'form_message_style',
            [ 'label' => __('Messages', 'sifency-addons'), 'tab' => Controls_Manager::TAB_STYLE ]
        );

        $this->add_control('success_color', [ 'label' => __('Success Message Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler .success' => 'color: {{VALUE}};' ] ]);
        $this->add_control('error_color', [ 'label' => __('Error Message Color', 'sifency-addons'), 'type' => Controls_Manager::COLOR, 'selectors' => [ '{{WRAPPER}} .sifency-form-styler .error' => 'color: {{VALUE}};' ] ]);

        $this->end_controls_section();
	}
}