<?php

/**
 * Elementor Contact Form Widget.
 *
 * Elementor widget that inserts an embbedable content into the page, from any given URL.
 *
 * @since 1.0.0
 */
class Daltech_Contact_Form extends \Elementor\Widget_Base
{

    /**
     * Get widget name.
     *
     * Retrieve Contact Form widget name.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget name.
     */
    public function get_name()
    {
        return 'daltech_contact_form';
    }

    /**
     * Get widget title.
     *
     * Retrieve Contact Form widget title.
     *
     * @since 1.0.0
     * @access public 
     *
     * @return string Widget title.
     */
    public function get_title()
    {
        return esc_html__('Contact Form', 'Daltech-core');
    }

    /**
     * Get widget icon.
     *
     * Retrieve contact_formor widget icon.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon()
    {
        return 'eicon-code';
    }

    /**
     * Get widget categories.
     *
     * Retrieve the list of categories the contact_formor widget belongs to.
     *
     * @since 1.0.0
     * @access public
     *
     * @return array Widget categories.
     */
    public function get_categories()
    {
        return ['daltech'];
    }

    public function get_script_depends()
    {
        return array('main');
    }

    // Add The Input For User
    protected function register_controls()
    {


        $this->start_controls_section(
            'contact_form_content',
            [
                'label'        => esc_html__('Set Content', 'Daltech-core'),
                'tab'        => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'style',
            [
                'label'     => esc_html__('Style', 'Daltech-core'),
                'type'         => \Elementor\Controls_Manager::SELECT,
                'default'     => '1',
                'options'     => [
                    '1'      => esc_html__('Style One', 'Daltech-core'),
                    '2'      => esc_html__('Style Two', 'Daltech-core'),
                    '3'      => esc_html__('Style Three', 'Daltech-core'),
                    '4'      => esc_html__('Style Four', 'Daltech-core'),
                    '5'      => esc_html__('Style Five', 'Daltech-core'),
                ],
            ]
        );

        $this->add_control(
            'section_title',
            [
                'label'         => esc_html__('Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('section title', 'daltech-core'),
                'default'         => esc_html__('Default Section Title', 'daltech-core'),
                'rows'           => '4',
                'label_block'     => true,
            ]
        );

        $this->add_control(
            'section_subtitle',
            [
                'label'         => esc_html__('Sub-Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('section subtitle', 'daltech-core'),
                'default'         => esc_html__('Default Section SubTitle', 'daltech-core'),
                'rows'           => '4',
                'label_block'     => true,
            ]
        );

        $this->add_control(
            'section_summary',
            [
                'label'         => esc_html__('Summary', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('section Summary', 'daltech-core'),
                'default'         => esc_html__('Default Section Summary', 'daltech-core'),
                'rows'           => '4',
                'label_block'     => true,
                'condition' => [
                    'style' => ['2', '1', '5']
                ]
            ]
        );

        $this->add_control(
            'form_title',
            [
                'label'         => esc_html__('Form Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('Form title', 'daltech-core'),
                'default'         => esc_html__('Default Form Title', 'daltech-core'),
                'rows'           => '4',
                'label_block'     => true,
                'condition' => [
                    'style' => ['2', '4', '5']
                ]
            ]
        );

        $this->add_control(
            'form_subtitle',
            [
                'label'         => esc_html__('Form Sub Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('Form  Sub title', 'daltech-core'),
                'default'         => esc_html__('Default Form Sub Title', 'daltech-core'),
                'rows'           => '4',
                'label_block'     => true,
                'condition' => [
                    'style' => ['2', '4', '5']
                ]
            ]
        );

        $this->add_control(
            'contact_shortcode',
            [
                'label'         => esc_html__('Contact Form Shortcode', 'cleanu-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'             => 2,
                'placeholder'     => esc_html__('Put your shortcode Here', 'cleanu-core'),
            ]

        );

        $contact_info_list = new \Elementor\Repeater();

        $contact_info_list->add_control(
            'title',
            [
                'label'         => esc_html__('Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 2,
                'placeholder' => __('Title', 'daltech-core'),
                'default' => __('Default Title', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $contact_info_list->add_control(
            'content',
            [
                'label'         => esc_html__('Content', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 2,
                'placeholder' => __('Content', 'daltech-core'),
                'default' => __('Default Content', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'contact_info_list',
            [
                'label'     => esc_html__('Info List', 'daltech-core'),
                'type'         => \Elementor\Controls_Manager::REPEATER,
                'fields'     => $contact_info_list->get_controls(),
                'default'     => [
                    [
                        'list_title' => esc_html__('Add Info', 'daltech-core'),
                    ],
                ],
                'title_field' => '{{{ title }}}',
                'condition' => [
                    'style' => ['2']
                ]
            ]
        );

        $layout_two_contact_info_list = new \Elementor\Repeater();

        $layout_two_contact_info_list->add_control(
            'title_one',
            [
                'label'         => esc_html__('Title One', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 2,
                'placeholder' => __('Info Title One', 'daltech-core'),
                'default' => __('Default Info Title One', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $layout_two_contact_info_list->add_control(
            'content_one',
            [
                'label'         => esc_html__('Content One', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 4,
                'placeholder' => __('Content', 'daltech-core'),
                'default' => __('Default Content', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $layout_two_contact_info_list->add_control(
            'title_two',
            [
                'label'         => esc_html__('Title Two', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 2,
                'placeholder' => __('Info Title Two', 'daltech-core'),
                'default' => __('Default Info Title Two', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $layout_two_contact_info_list->add_control(
            'content_two',
            [
                'label'         => esc_html__('Content Two', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::CODE,
                'rows' => 5,
                'placeholder' => __('Content Two', 'daltech-core'),
                'default' => __('Default Content Two', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'layout_two_contact_info_list',
            [
                'label'     => esc_html__('Info List', 'daltech-core'),
                'type'         => \Elementor\Controls_Manager::REPEATER,
                'fields'     => $layout_two_contact_info_list->get_controls(),
                'default'     => [
                    [
                        'list_title' => esc_html__('Add Info List', 'daltech-core'),
                    ],
                ],
                'title_field' => '{{{ title_one }}}',
                'condition' => [
                    'style' => ['4']
                ]
            ]
        );

        $layout_five_contact_info_list = new \Elementor\Repeater();

        $layout_five_contact_info_list->add_control(
            'title',
            [
                'label'         => esc_html__('Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows' => 2,
                'placeholder' => __('Info Title', 'daltech-core'),
                'default' => __('Default Info Title', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $layout_five_contact_info_list->add_control(
            'content',
            [
                'label'         => esc_html__('Content One', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::CODE,
                'rows' => 4,
                'placeholder' => __('Content', 'daltech-core'),
                'default' => __('Default Content', 'daltech-core'),
                'label_block' => true,
            ]
        );

        $layout_five_contact_info_list->add_control(
            'icon_style',
            [
                'label'     => esc_html__('Icon Style', 'daltech-core'),
                'type'         => \Elementor\Controls_Manager::SELECT,
                'default'     => '1',
                'options'     => [
                    '1'      => esc_html__('Flaticon', 'daltech-core'),
                    '3'     => esc_html__('Icon Image', 'daltech-core'),
                    '2'      => esc_html__('Custom Icon', 'daltech-core'),
                ],
            ]
        );

        $layout_five_contact_info_list->add_control(
            'flat_icon',
            [
                'label'      => esc_html__('Icon One', 'daltech-core'),
                'type'       => \Elementor\Controls_Manager::ICON,
                'options'    => daltech_flaticons(),
                'include'    => daltech_include_flaticons(),
                'default'    => 'flaticon-vegetables',
                'condition' => [
                    'icon_style' => '1'
                ]
            ]
        );

        $layout_five_contact_info_list->add_control(
            'custom_icon',
            [
                'label'         => esc_html__('Custom Icon', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'  =>     '1',
                'label_block'     => true,
                'condition' => [
                    'icon_style' => '2'
                ]
            ]
        );

        $layout_five_contact_info_list->add_control(
            'icon_image',
            [
                'label'            => esc_html__('Add Image Icon', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'condition' => [
                    'icon_style' => '3'
                ]
            ]
        );

        $this->add_control(
            'layout_five_contact_info_list',
            [
                'label'     => esc_html__('Info List', 'daltech-core'),
                'type'         => \Elementor\Controls_Manager::REPEATER,
                'fields'     => $layout_five_contact_info_list->get_controls(),
                'default'     => [
                    [
                        'list_title' => esc_html__('Add Info List', 'daltech-core'),
                    ],
                ],
                'title_field' => '{{{ title }}}',
                'condition' => [
                    'style' => ['5']
                ]
            ]
        );

        $this->add_control(
            'contact_image',
            [
                'label'            => esc_html__('Background Image', 'Daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'style' => ['1', '2', '5']
                ]
            ]
        );

        $this->add_control(
            'shape_one',
            [
                'label'            => esc_html__('Shape One', 'Daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'style' => ['1', '2']
                ]
            ]
        );

        $this->add_control(
            'shape_two',
            [
                'label'            => esc_html__('Shape Two', 'Daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'style' => ['1']
                ]
            ]
        );

        $this->end_controls_section();

        include DALTECH_PLUGIN_WIDGET_STYLE_PATH . 'contact-style.php';
    }

    // Output For User
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        if ($settings['style'] == '1') :
?>

            <!--<< Contact Section Start >>-->
            <section class="contact-section fix section-padding">
                <div class="container">
                    <div class="contact-wrapper">
                        <div class="shape-image">
                            <?php
                            if (!empty($settings['shape_one']['url'])) {
                                echo daltech_img_tag(array(
                                    'url'    => esc_url($settings['shape_one']['url']),
                                ));
                            }
                            ?>
                        </div>
                        <div class="row align-items-center">
                            <div class="col-lg-6">
                                <div class="contact-image bg-cover" style="background-image: url(<?php echo esc_url($settings['contact_image']['url']); ?>);">
                                    <div class="shape-image-2">
                                        <?php
                                        if (!empty($settings['shape_two']['url'])) {
                                            echo daltech_img_tag(array(
                                                'url'    => esc_url($settings['shape_two']['url']),
                                            ));
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 mt-5 mt-lg-0">
                                <div class="contact-area">
                                    <div class="section-title">
                                        <span class="wow fadeInUp">
                                            <?php echo wp_kses($settings['section_subtitle'], 'daltech_allowed_tags'); ?>
                                        </span>
                                        <h2 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['section_title'], 'daltech_allowed_tags'); ?>
                                        </h2>
                                    </div>
                                    <div class="contact-form-items mt-5 mt-md-0">
                                        <?php echo do_shortcode($settings['contact_shortcode']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!-- End Contact -->

        <?php elseif ($settings['style'] == '2') : ?>

            <!--<< Contact Section Start >>-->
            <!--<< Contact Section Start >>-->
            <section class="contact-section-2 fix section-padding bg-cover" style="background-image: url(<?php echo esc_url($settings['contact_image']['url']); ?>);">
                <div class="contact-image">
                    <?php
                    if (!empty($settings['shape_one']['url'])) {
                        echo daltech_img_tag(array(
                            'url'    => esc_url($settings['shape_one']['url']),
                        ));
                    }
                    ?>
                </div>
                <div class="container">
                    <div class="contact-wrapper-2">
                        <div class="row align-items-center">
                            <div class="col-lg-6">
                                <div class="contact-content">
                                    <div class="section-title style-2">
                                        <span class="wow fadeInUp">
                                            <?php echo wp_kses($settings['section_subtitle'], 'daltech_allowed_tags'); ?>
                                        </span>
                                        <h2 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['section_title'], 'daltech_allowed_tags'); ?>
                                        </h2>
                                    </div>
                                    <p class="mt-4 mt-md-0 wow fadeInUp" data-wow-delay=".5s">
                                        <?php echo wp_kses($settings['section_summary'], 'daltech_allowed_tags'); ?>
                                    </p>

                                    <div class="contact-info-area">
                                        <?php
                                        foreach ($settings['contact_info_list'] as $item) :
                                        ?>
                                            <div class="contact-info-items mb-4 wow fadeInUp" data-wow-delay=".7s">
                                                <div class="icon">
                                                    <i class="far fa-phone"></i>
                                                </div>
                                                <div class="content">
                                                    <p><?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?></p>
                                                    <h3>
                                                        <?php echo wp_kses($item['content'], 'daltech_allowed_tags'); ?>
                                                    </h3>
                                                </div>
                                            </div>
                                        <?php
                                        endforeach;
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 mt-5 mt-lg-0">
                                <div class="contact-box">
                                    <div class="contact-title">
                                        <h3 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['form_title'], 'daltech_allowed_tags'); ?></h3>
                                        <p class="wow fadeInUp" data-wow-delay=".5s">
                                            <?php echo wp_kses($settings['form_subtitle'], 'daltech_allowed_tags'); ?></p>
                                    </div>
                                    <div class="contact-form-items">
                                        <?php echo do_shortcode($settings['contact_shortcode']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!-- End Contact Two -->

        <?php elseif ($settings['style'] == '3') : ?>

            <!--<< Contact Section Start Three >>-->
            <div class="single-sidebar-widget">
                <div class="wid-title">
                    <h3> <?php echo wp_kses($settings['section_title'], 'daltech_allowed_tags'); ?></h3>
                </div>
                <div id="contact-form" class="message-form">
                    <?php echo do_shortcode($settings['contact_shortcode']); ?>
                </div>
            </div>
            <!-- End Contact Three -->

        <?php elseif ($settings['style'] == '4') : ?>

            <!--<< Contact Section Start Four >>-->
            <section class="team-contact-area fix section-padding">
                <div class="container">
                    <div class="team-contact-wrapper">
                        <div class="row">
                            <div class="col-lg-6">
                                <div class="get-touch-items">
                                    <div class="get-touch-title">
                                        <h2 class="wow fadeInUp">
                                            <?php echo wp_kses($settings['section_title'], 'daltech_allowed_tags'); ?>
                                        </h2>
                                        <p class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['section_subtitle'], 'daltech_allowed_tags'); ?>
                                        </p>
                                    </div>
                                    <?php
                                    foreach ($settings['layout_two_contact_info_list'] as $item) :
                                    ?>
                                        <div class="contact-items">
                                            <div class="contact-info wow fadeInUp" data-wow-delay=".3s">
                                                <h4><?php echo wp_kses($item['title_one'], 'daltech_allowed_tags'); ?></h4>
                                                <h5><?php echo wp_kses($item['content_one'], 'daltech_allowed_tags'); ?></h5>
                                            </div>
                                            <div class="contact-info wow fadeInUp" data-wow-delay=".5s">
                                                <h4><?php echo wp_kses($item['title_two'], 'daltech_allowed_tags'); ?></h4>
                                                <?php echo wp_kses($item['content_two'], 'daltech_allowed_tags'); ?>
                                            </div>
                                        </div>
                                    <?php
                                    endforeach;
                                    ?>
                                </div>
                            </div>
                            <div class="col-lg-6 mt-5 mt-lg-0">
                                <div class="contact-box">
                                    <div class="contact-title">
                                        <h3 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['form_title'], 'daltech_allowed_tags'); ?></h3>
                                        <p class="wow fadeInUp" data-wow-delay=".5s">
                                            <?php echo wp_kses($settings['form_subtitle'], 'daltech_allowed_tags'); ?></p>
                                    </div>
                                    <div class="contact-form-items">
                                        <div id="contact-form">
                                            <?php echo do_shortcode($settings['contact_shortcode']); ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!--<< Contact Section Start Four >>-->

        <?php elseif ($settings['style'] == '5') : ?>

            <!--<< Contact Section Start Five >>-->
            <section class="contact-main-area fix section-padding">
                <div class="container">
                    <div class="contact-main-wrapper">
                        <div class="row g-4">
                            <div class="col-lg-6">
                                <div class="contact-content">
                                    <div class="section-title mb-2">
                                        <span class="wow fadeInUp"><?php echo wp_kses($settings['section_subtitle'], 'daltech_allowed_tags'); ?></span>
                                        <h2 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['section_title'], 'daltech_allowed_tags'); ?></h2>
                                    </div>
                                    <p class="mt-4 mt-md-0 wow fadeInUp" data-wow-delay=".4s">
                                        <?php echo wp_kses($settings['section_summary'], 'daltech_allowed_tags'); ?>
                                    </p>
                                    <div class="row g-4 mt-3">
                                        <?php
                                        foreach ($settings['layout_five_contact_info_list'] as $item) :
                                        ?>
                                            <div class="col-lg-6 wow fadeInUp" data-wow-delay=".3s">
                                                <div class="info-items">
                                                    <div class="icon">
                                                        <?php if (!empty($item['flat_icon'])) : ?>
                                                            <i class="<?php echo esc_attr($item['flat_icon']); ?>"></i>
                                                        <?php endif; ?>
                                                        <?php if (!empty($item['icon_image']['url'])) : ?>
                                                            <img src="<?php echo esc_url($item['icon_image']['url']); ?>" alt="<?php echo get_bloginfo('name'); ?>">
                                                        <?php endif; ?>
                                                        <?php
                                                        if (!empty($item['custom_icon'])) : ?>
                                                            <i class="<?php echo esc_attr($item['custom_icon']); ?>"></i>
                                                        <?php endif; ?>
                                                    </div>
                                                    <div class="content">
                                                        <h5><?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?></h5>
                                                        <?php echo wp_kses($item['content'], 'daltech_allowed_tags'); ?>

                                                    </div>
                                                </div>
                                            </div>
                                        <?php
                                        endforeach;
                                        ?>
                                    </div>
                                    <div class="contact-image wow fadeInUp" data-wow-delay=".4s">
                                        <?php
                                        if (!empty($settings['contact_image']['url'])) {
                                            echo daltech_img_tag(array(
                                                'url'    => esc_url($settings['contact_image']['url']),
                                            ));
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-6 mt-5 mt-lg-0">
                                <div class="contact-form-items">
                                    <div class="contact-title">
                                        <h3 class="wow fadeInUp" data-wow-delay=".3s">
                                            <?php echo wp_kses($settings['form_title'], 'daltech_allowed_tags'); ?></h3>
                                        <p class="wow fadeInUp" data-wow-delay=".5s">
                                            <?php echo wp_kses($settings['form_subtitle'], 'daltech_allowed_tags'); ?></p>
                                    </div>
                                    <div id="contact-form">
                                        <?php echo do_shortcode($settings['contact_shortcode']); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!--<< Contact Section Start Five >>-->

<?php
        endif;
    }
}
