<?php
/*
 * Elementor Confin Contact Form 7 Widget
 * Author & Copyright: themexshaper
*/

namespace Elementor;

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class Confin_Contact_Form extends Widget_Base{

	/**
	 * Retrieve the widget name.
	*/
	public function get_name(){
		return 'tmx-confin_contact_form';
	}

	/**
	 * Retrieve the widget title.
	*/
	public function get_title(){
		return esc_html__( 'Contact Form', 'confin-core' );
	}

	/**
	 * Retrieve the widget icon.
	*/
	public function get_icon() {
		return 'eicon-form-horizontal';
	}

	/**
	 * Retrieve the list of categories the widget belongs to.
	*/
	public function get_categories() {
		return ['themexshaper-category'];
	}

	/**
	 * Retrieve the list of scripts the Confin Contact Form widget depended on.
	 * Used to set scripts dependencies required to run the widget.
	*/
	/*
	public function get_script_depends() {
		return ['tmx-confin_contact_form'];
	}
	 */
	
	/**
	 * Register Confin Contact Form widget controls.
	 * Adds different input fields to allow the user to change and customize the widget settings.
	*/
	protected function register_controls(){
		
		$this->start_controls_section(
			'section_contact_form',
			[
				'label' => esc_html__( 'Form Options', 'confin-core' ),
			]
		);
		$this->add_control(
			'form_id',
			[
				'label' => esc_html__( 'Select contact form', 'confin-core' ),
				'type' => Controls_Manager::SELECT,
				'options' => Controls_Helper_Output::get_posts('wpcf7_contact_form'),
			]
		);
		$this->end_controls_section();// end: Section

	
			// Form Style

		$this->start_controls_section(
			'section_form_style',
			[
				'label' => esc_html__( 'Form', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'form_typography',
				'selector' => '{{WRAPPER}} .contact-pg-section .contact-form input[type="text"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="email"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="date"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="time"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="number"], 
				{{WRAPPER}} .contact-pg-section .contact-form textarea, 
				{{WRAPPER}} .contact-pg-section .contact-form select, 
				{{WRAPPER}} .contact-pg-section .contact-form .form-control, 
				{{WRAPPER}} .track-contact .track-trace select, 
				{{WRAPPER}} .track-contact .track-trace input',
			]
		);
		$this->add_group_control(
			Group_Control_Border::get_type(),
			[
				'name' => 'form_border',
				'label' => esc_html__( 'Border', 'confin-core' ),
				'selector' => '{{WRAPPER}} .contact-pg-section .contact-form input[type="text"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="email"], 
				{{WRAPPER}} .contact-pg-section .contact-forminput[type="date"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="time"], 
				{{WRAPPER}} .contact-pg-section .contact-form input[type="number"], 
				{{WRAPPER}} .contact-pg-section .contact-form textarea, 
				{{WRAPPER}} .contact-pg-section .contact-form select, 
				{{WRAPPER}} .contact-pg-section .contact-form .form-control, 
				{{WRAPPER}} .contact-pg-section .contact-form .nice-select,
				{{WRAPPER}} .track-contact .track-trace select, 
				{{WRAPPER}} .track-contact .track-trace input',

			]
		);
		$this->add_control(
			'placeholder_text_color',
			[
				'label' => __( 'Placeholder Text Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form input:not([type="submit"])::-webkit-input-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form input:not([type="submit"])::-moz-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form input:not([type="submit"])::-ms-input-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form input:not([type="submit"])::-o-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form textarea::-webkit-input-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form textarea::-moz-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form textarea::-ms-input-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .contact-pg-section .contact-form textarea::-o-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .track-contact .track-trace input::-webkit-input-placeholder' => 'color: {{VALUE}} !important;',
					'{{WRAPPER}} .track-contact .track-trace select::-webkit-input-placeholder' => 'color: {{VALUE}} !important;',
				],
			]
		);
		$this->add_control(
			'label_color',
			[
				'label' => __( 'Label Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form label' => 'color: {{VALUE}} !important;',
				],
			]
		);
		$this->add_control(
			'text_color',
			[
				'label' => __( 'Text Color', 'confin-core' ),
				'type' => Controls_Manager::COLOR,
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form input[type="text"], 
					{{WRAPPER}} .contact-pg-section .contact-form input[type="email"], 
					{{WRAPPER}} .contact-pg-section .contact-form input[type="date"], 
					{{WRAPPER}} .contact-pg-section .contact-form input[type="time"], 
					{{WRAPPER}} .contact-pg-section .contact-form input[type="number"], 
					{{WRAPPER}} .contact-pg-section .contact-form textarea, 
					{{WRAPPER}} .contact-pg-section .contact-form select, 
					{{WRAPPER}} .contact-pg-section .contact-form .form-control, 
					{{WRAPPER}} .track-contact .track-trace input, 
					{{WRAPPER}} .contact-pg-section .contact-form .nice-select' => 'color: {{VALUE}} !important;',
				],
			]
		);
		$this->end_controls_section();// end: Section
		
		$this->start_controls_section(
			'section_button_style',
			[
				'label' => esc_html__( 'Button', 'confin-core' ),
				'tab' => Controls_Manager::TAB_STYLE,
			]
		);
		$this->add_group_control(
			Group_Control_Typography::get_type(),
			[
				'name' => 'button_typography',
				'selector' => '{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn',
			]
		);
		$this->add_responsive_control(
			'btn_width',
			[
				'label' => esc_html__( 'Width', 'confin-core' ),
				'type' => Controls_Manager::SLIDER,
				'range' => [
					'px' => [
						'min' => 0,
						'max' => 1000,
						'step' => 1,
					],
				],
				'size_units' => [ 'px', '%' ],
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn' => 'min-width: {{SIZE}}{{UNIT}};',
				],
			]
		);
		$this->add_control(
			'btn_margin',
			[
				'label' => __( 'Margin', 'confin-core' ),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', 'em' ],
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);
		$this->add_control(
			'button_border_radius',
			[
				'label' => __( 'Border Radius', 'confin-core' ),
				'type' => Controls_Manager::DIMENSIONS,
				'size_units' => [ 'px', '%', 'em' ],
				'selectors' => [
					'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
				],
			]
		);
		$this->start_controls_tabs( 'button_style' );
			$this->start_controls_tab(
				'button_normal',
				[
					'label' => esc_html__( 'Normal', 'confin-core' ),
				]
			);
			$this->add_control(
				'button_color',
				[
					'label' => esc_html__( 'Color', 'confin-core' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn' => 'color: {{VALUE}};',
					],
				]
			);
			$this->add_control(
				'button_bg_color',
				[
					'label' => esc_html__( 'Background Color', 'confin-core' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn' => 'background-color: {{VALUE}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'button_border',
					'label' => esc_html__( 'Border', 'confin-core' ),
					'selector' => '{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit,.track-contact .track-trace .wpcf7-submit.submit-btn',
				]
			);
			$this->end_controls_tab();  // end:Normal tab
			
			$this->start_controls_tab(
				'button_hover',
				[
					'label' => esc_html__( 'Hover', 'confin-core' ),
				]
			);
			$this->add_control(
				'button_hover_color',
				[
					'label' => esc_html__( 'Color', 'confin-core' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit:hover,.track-contact .track-trace .wpcf7-submit.submit-btn:hover' => 'color: {{VALUE}};',
					],
				]
			);
			$this->add_control(
				'button_bg_hover_color',
				[
					'label' => esc_html__( 'Background Color', 'confin-core' ),
					'type' => Controls_Manager::COLOR,
					'selectors' => [
						'{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit:hover,.track-contact .track-trace .wpcf7-submit.submit-btn:hover' => 'background-color: {{VALUE}};',
					],
				]
			);
			$this->add_group_control(
				Group_Control_Border::get_type(),
				[
					'name' => 'button_hover_border',
					'label' => esc_html__( 'Border', 'confin-core' ),
					'selector' => '{{WRAPPER}} .contact-pg-section .contact-form .wpcf7-form-control.wpcf7-submit:hover,.track-contact .track-trace .wpcf7-submit.submit-btn:hover',
				]
			);
			$this->end_controls_tab();  // end:Hover tab
		$this->end_controls_tabs(); // end tabs
		
		$this->end_controls_section();// end: Section

		
		
	}

	/**
	 * Render Contact Form widget output on the frontend.
	 * Written in PHP and used to generate the final HTML.
	*/
	protected function render() {
		$settings = $this->get_settings_for_display();
		$form_id = !empty( $settings['form_id'] ) ? $settings['form_id'] : '';

		// Turn output buffer on
		ob_start(); ?>
		<div class="contact-section">
		     <?php echo do_shortcode( '[contact-form-7 id="'. $form_id .'"]' ); ?> 
		</div>
		<?php
		// Return outbut buffer
		echo ob_get_clean();
		
		}
		


	/**
	 * Render Contact Form widget output in the editor.
	 * Written as a Backbone JavaScript template and used to generate the live preview.
	*/
	
	//protected function _content_template(){}
	
}
Plugin::instance()->widgets_manager->register( new Confin_Contact_Form() );