<?php
if(class_exists('WPCF7')) {
    $cf7 = get_posts('post_type="wpcf7_contact_form"&numberposts=-1');

    $contact_forms = array();
    if ($cf7) {
        foreach ($cf7 as $cform) {
            $contact_forms[$cform->ID] = $cform->post_title;
        }
    } else {
        $contact_forms[esc_html__('No contact forms found', 'kaitex')] = 0;
    }

    pxl_add_custom_widget(
        array(
            'name' => 'pxl_contact_form',
            'title' => esc_html__('BR Contact Form', 'kaitex'),
            'icon' => 'eicon-form-horizontal',
            'categories' => array('pxltheme-core'),
            'params' => array(
                'sections' => array(
                    array(
                        'name' => 'tab_content',
                        'label' => esc_html__('Content', 'kaitex'),
                        'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
                        'controls' => array(
                            array(
                                'name' => 'form_id',
                                'label' => esc_html__('Select Form', 'kaitex'),
                                'type' => \Elementor\Controls_Manager::SELECT,
                                'options' => $contact_forms,
                            ),
                            array(
                                'name' => 'h_width',
                                'label' => esc_html__( 'Max Width', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'control_type' => 'responsive',
                                'size_units' => [ 'px', '%' ],
                                'range' => [
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form' => 'max-width: {{SIZE}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'style',
                                'label' => esc_html__('Style', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SELECT,
                                'options' => [
                                    'style1' => 'Style 1',
                                    'style2' => 'Style 2',
                                ],
                                'default' => 'style1',
                            ),
                        ),
                    ),
                    array(
                        'name' => 'tab_style_input',
                        'label' => esc_html__('Input', 'kaitex'),
                        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                        'controls' => array(
                            array(
                                'name' => 'placeholder_color',
                                'label' => esc_html__('Placeholder Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input::-webkit-input-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input::-moz-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input:-ms-input-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input:-moz-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input::placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea::-webkit-input-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea::-moz-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea:-ms-input-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea:-moz-placeholder' => 'color: {{VALUE}};',
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea::placeholder' => 'color: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'label_color',
                                'label' => esc_html__('Label Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled label' => 'color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'label_typography',
                                'label' => esc_html__('Label Typography', 'kaitex' ),
                                'type' => \Elementor\Group_Control_Typography::get_type(),
                                'control_type' => 'group',
                                'selector' => '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled label',
                            ),
                            array(
                                'name' => 'input_color',
                                'label' => esc_html__('Input Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input, {{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea' => 'color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'input_typography',
                                'label' => esc_html__('Input Typography', 'kaitex' ),
                                'type' => \Elementor\Group_Control_Typography::get_type(),
                                'control_type' => 'group',
                                'selector' => '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input, {{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea',
                            ),
                            array(
                                'name' => 'input_height',
                                'label' => esc_html__('Input Height', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vw' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vh' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'control_type' => 'responsive',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input' => 'height: {{SIZE}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'input_border_radius',
                                'label' => esc_html__('Input Border Radius', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'control_type' => 'responsive',
                                'size_units' => [ 'px', '%' ],
                                'default' => [
                                    'unit' => '%',
                                ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'input_padding',
                                'label' => esc_html__('Input Padding', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                                'control_type' => 'responsive',
                            ),
                            array(
                                'name' => 'textarea_height',
                                'label' => esc_html__('Textarea Height', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vw' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vh' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'control_type' => 'responsive',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea' => 'height: {{SIZE}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'textarea_padding',
                                'label' => esc_html__('Textarea Padding', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                                'control_type' => 'responsive',
                            ),
                            array(
                                'name' => 'input_bg_color',
                                'label' => esc_html__('Background Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input, {{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea' => 'background-color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'border_color',
                                'label' => esc_html__( 'Border Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'default' => '',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input, {{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea' => 'border-color: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'border_color_active',
                                'label' => esc_html__( 'Border Color Active', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'default' => '',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled input:focus, {{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-filled textarea:focus' => 'border-color: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'input_spacer_bottom',
                                'label' => esc_html__('Spacer Bottom', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vw' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vh' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'control_type' => 'responsive',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .input-contact + .input-contact' => 'margin-top: {{SIZE}}{{UNIT}};',
                                ],
                            ),
                        ),
                    ),
                    array(
                        'name' => 'tab_style_button',
                        'label' => esc_html__('Button', 'kaitex'),
                        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                        'controls' => array(
                            array(
                                'name' => 'button_typography',
                                'label' => esc_html__('Button Typography', 'kaitex' ),
                                'type' => \Elementor\Group_Control_Typography::get_type(),
                                'control_type' => 'group',
                                'selector' => '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button',
                            ),
                            array(
                                'name' => 'button_color',
                                'label' => esc_html__('Button Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit' => 'color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'hover_button_color',
                                'label' => esc_html__('Hover Button Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit:hover' => 'color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'bg_button_color',
                                'label' => esc_html__('Background Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit' => 'background-color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'bg_button_color_hv',
                                'label' => esc_html__('Background Color Hover', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit:hover' => 'background-color: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'dot_color',
                                'label' => esc_html__('Dot Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit:before' => 'background-color: {{VALUE}};',
                                ],
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'button_height',
                                'label' => esc_html__('Height', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SLIDER,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                    'px' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vw' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                    'vh' => [
                                        'min' => 0,
                                        'max' => 3000,
                                    ],
                                ],
                                'control_type' => 'responsive',
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wp-row-ctf7 .wpcf7-submit' => 'min-height: {{SIZE}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'button_padding',
                                'label' => esc_html__('Padding', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'size_units' => [ 'px' ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                                'control_type' => 'responsive',
                                'separator' => 'before',
                            ),
                            array(
                                'name' => 'button_border_radius',
                                'label' => esc_html__('Border Radius', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'control_type' => 'responsive',
                                'size_units' => [ 'px', '%' ],
                                'default' => [
                                    'unit' => '%',
                                ],
                                'range' => [
                                    '%' => [
                                        'min' => 0,
                                        'max' => 100,
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                            ),
                            array(
                                'name' => 'button_border_type',
                                'label' => esc_html__( 'Border Type', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::SELECT,
                                'options' => [
                                    '' => esc_html__( 'None', 'kaitex' ),
                                    'solid' => esc_html__( 'Solid', 'kaitex' ),
                                    'double' => esc_html__( 'Double', 'kaitex' ),
                                    'dotted' => esc_html__( 'Dotted', 'kaitex' ),
                                    'dashed' => esc_html__( 'Dashed', 'kaitex' ),
                                    'groove' => esc_html__( 'Groove', 'kaitex' ),
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button' => 'border-style: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'button_border_width',
                                'label' => esc_html__( 'Border Width', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button' => 'border-width: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                                'condition' => [
                                    'button_border_type!' => '',
                                ],
                                'responsive' => true,
                            ),
                            array(
                                'name' => 'button_border_color',
                                'label' => esc_html__('Border Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button' => 'border-color: {{VALUE}};',
                                ],
                                'condition' => [
                                    'button_border_type!' => '',
                                ],
                            ),
                            array(
                                'name'         => 'button_box_shadow',
                                'label'        => esc_html__( 'Box Shadow', 'kaitex' ),
                                'type'         => \Elementor\Group_Control_Box_Shadow::get_type(),
                                'control_type' => 'group',
                                'selector'     => '{{WRAPPER}} .pxl-contact-form .wpcf7-submit, {{WRAPPER}} .pxl-contact-form button'
                            ),
                        ),
                    ),
                    array(
                        'name' => 'section_style_box',
                        'label' => esc_html__('Box', 'kaitex'),
                        'tab' => \Elementor\Controls_Manager::TAB_STYLE,
                        'controls' => array(
                            array(
                                'name' => 'align',
                                'label' => esc_html__( 'Alignment', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::CHOOSE,
                                'control_type' => 'responsive',
                                'options' => [
                                    'left' => [
                                        'title' => esc_html__( 'Left', 'kaitex' ),
                                        'icon' => 'eicon-text-align-left',
                                    ],
                                    'center' => [
                                        'title' => esc_html__( 'Center', 'kaitex' ),
                                        'icon' => 'eicon-text-align-center',
                                    ],
                                    'right' => [
                                        'title' => esc_html__( 'Right', 'kaitex' ),
                                        'icon' => 'eicon-text-align-right',
                                    ],
                                ],
                                'selectors' => [
                                    '{{WRAPPER}} .pxl-contact-form' => 'text-align: {{VALUE}};',
                                ],
                            ),
                            array(
                                'name' => 'box_padding',
                                'label' => esc_html__('Box Padding', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::DIMENSIONS,
                                'size_units' => [ 'px', '%', 'vw', 'vh' ],
                                'selectors' => [
                                    '{{WRAPPER}} .wp-row-ctf7' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
                                ],
                                'control_type' => 'responsive',
                            ),
                            array(
                                'name' => 'bg_color',
                                'label' => esc_html__( 'Background Color', 'kaitex' ),
                                'type' => \Elementor\Controls_Manager::COLOR,
                                'selectors' => [
                                    '{{WRAPPER}} .wp-row-ctf7' => 'background-color: {{VALUE}};',
                                ],
                            ),
                        ),
                    ),
                    kaitex_widget_animation_settings()
                ),
            ),
        ),
        kaitex_get_class_widget_path()
    );
}