<?php

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

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

    /**
     * Get widget title.
     *
     * Retrieve Project Nav Tab widget title.
     *
     * @since 1.0.0
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title()
    {
        return esc_html__('Project', 'daltech-core');
    }

    /**
     * Get widget icon.
     *
     * Retrieve Project Nav Tab 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 Project Nav Tab widget belongs to.
     *
     * @since 1.0.0
     * @access public
     *
     * @return array Widget categories.
     */
    public function get_categories()
    {
        return ['daltech'];
    }

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

        $this->start_controls_section(
            'project_content_style',
            [
                'label'        => esc_html__('Project Style', '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__('Section Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('section title', 'daltech-core'),
                'default'         => esc_html__('Default Section Title', 'daltech-core'),
                'condition' => [
                    'style' => ['2', '3']
                ]
            ]
        );

        $this->add_control(
            'section_subtitle',
            [
                'label'         => esc_html__('Section Subtitle', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'placeholder'     => esc_html__('section subtitle', 'daltech-core'),
                'default'         => esc_html__('Default Section SubTitle', 'daltech-core'),
                'condition' => [
                    'style' => ['2', '3']
                ]
            ]
        );

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

        $this->add_control(
            'button_label',
            [
                'label'     => __('Button Label', 'daltech-core'),
                'type'         => \Elementor\Controls_Manager::TEXTAREA,
                'rows'         => 2,
                'default'      => __('Button Label', 'daltech-core'),
                'condition' => [
                    'style' => ['3']
                ]
            ]
        );

        $this->add_control(
            'url',
            [
                'label'         => __('URL', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::URL,
                'placeholder'     => __('https://your-link.com', 'daltech-core'),
                'show_external' => true,
                'default'         => [
                    'url'             => '#',
                    'is_external'     => false,
                    'nofollow'         => false,
                ],
                'condition' => [
                    'style' => ['3']
                ]
            ]
        );


        $layout_one_project_list = new \Elementor\Repeater();

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

        $layout_one_project_list->add_control(
            'subtitle',
            [
                'label'         => esc_html__('Sub-Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'             => '3',
                'default'      => __('Sub-Title', 'daltech-core'),
                'label_block'     => true,
            ]
        );

        $layout_one_project_list->add_control(
            'image',
            [
                'label' => esc_html__('Image', 'agrofa-addon'),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $layout_one_project_list->add_control(
            'url',
            [
                'label'         => esc_html__('URL', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::URL,
                'placeholder'     => esc_html__('https://your-link.com', 'daltech-core'),
                'show_external' => true,
                'default'         => [
                    'url'             => '#',
                    'is_external'     => true,
                    'nofollow'         => true,
                ],
            ]
        );

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


        $info_list = new \Elementor\Repeater();

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

        $info_list->add_control(
            'subtitle',
            [
                'label'         => esc_html__('Sub-Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'             => '3',
                'default'      => __('Sub-Title', 'daltech-core'),
                'label_block'     => true,
            ]
        );

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

        $layout_four_project_content_list = new \Elementor\Repeater();

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

        $layout_four_project_content_list->add_control(
            'subtitle',
            [
                'label'         => esc_html__('Sub-Title', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'             => '3',
                'default'      => __('Sub-Title', 'daltech-core'),
                'label_block'     => true,
            ]
        );


        $layout_four_project_content_list->add_control(
            'check_list',
            [
                'label'         => esc_html__('Check List', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::CODE,
                'rows'             => '6',
                'default'      => __('Sub-Title', 'daltech-core'),
                'label_block'     => true,
            ]
        );

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

        $this->add_control(
            'bg_image_one',
            [
                'label'            => esc_html__('Add Image One', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'style' => ['3', '4', '5']
                ]
            ]
        );

        $this->add_control(
            'bg_image_two',
            [
                'label'            => esc_html__('Add Image Two', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
                'condition' => [
                    'style' => ['3', '4', '5']
                ]
            ]
        );


        $this->end_controls_section();

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

    // Output For User
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        if ($settings['style'] == '1') :
?>
            <!--<< Project Section Start >>-->
            <section class="project-section fix section-padding">
                <div class="container">
                    <div class="row g-4">
                        <?php
                        foreach ($settings['layout_one_project_list'] as $item) :
                            $image_name = $item['image']['url'];
                            list($width, $height) = getimagesize($image_name);
                        ?>
                            <div class="col-lg-<?php if ($width >= '660') : echo esc_attr("7");
                                                else : echo ("5");
                                                endif; ?> wow fadeInUp" data-wow-delay=".3s">
                                <div class="project-image">
                                    <?php
                                    if (!empty($item['image']['url'])) {
                                        echo daltech_img_tag(array(
                                            'url'    => esc_url($item['image']['url']),
                                        ));
                                    }
                                    ?>
                                    <a href="<?php echo esc_url($item['image']['url']); ?>" class="icon img-popup">
                                        <i class="fal fa-plus"></i>
                                    </a>
                                    <div class="project-content">
                                        <h3>
                                            <a href="<?php echo esc_url($item['url']['url']); ?>">
                                                <?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?></a>
                                        </h3>
                                        <p> <?php echo wp_kses($item['subtitle'], 'daltech_allowed_tags'); ?></p>
                                    </div>
                                </div>
                            </div>
                        <?php
                        endforeach;
                        ?>
                    </div>
                </div>
            </section>
            <!-- End  Project Style One -->

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

            <!-- Start  Project Style Two -->
            <section class="case-study-2 fix section-padding">
                <div class="container">
                    <div class="section-title style-2 text-center">
                        <span class="wow fadeInUp">
                            <?php echo wp_kses_post($settings['section_subtitle'], 'daltech_kses_allowed_html'); ?>
                        </span>
                        <h2 class="wow fadeInUp" data-wow-delay=".3s">
                            <?php echo wp_kses_post($settings['section_title'], 'daltech_kses_allowed_html'); ?>
                        </h2>
                    </div>
                </div>
                <div class="case-study-wrapper">
                    <div class="case-studies-carousel-active-2">
                        <?php
                        foreach ($settings['layout_one_project_list'] as $item) :
                        ?>
                            <div class="case-study-items">
                                <div class="case-study-image">
                                    <?php
                                    if (!empty($item['image']['url'])) {
                                        echo daltech_img_tag(array(
                                            'url'    => esc_url($item['image']['url']),
                                        ));
                                    }
                                    ?>
                                </div>
                                <div class="case-study-content">
                                    <h3>
                                        <a href="<?php echo esc_url($item['url']['url']); ?>">
                                            <?php echo wp_kses($item['title'], 'daltech_allowed_tags'); ?>
                                        </a>
                                    </h3>
                                    <p> <?php echo wp_kses($item['subtitle'], 'daltech_allowed_tags'); ?></p>
                                    <a href="<?php echo esc_url($item['url']['url']); ?>" class="icon">
                                        <i class="fal fa-arrow-right"></i>
                                    </a>
                                </div>
                            </div>
                        <?php
                        endforeach;
                        ?>

                    </div>
                </div>
            </section>
            <!-- End  Project Style Two -->

            <script>
                (function($) {
                    "use strict";
                    $(document).ready(function() {
                        if ($('.case-studies-carousel-active-2').length > 0) {
                            $('.case-studies-carousel-active-2').slick({
                                autoplay: true,
                                autoplaySpeed: 1500,
                                speed: 1000,
                                arrows: false,
                                slidesToShow: 3,
                                slidesToScroll: 1,
                                dots: false,
                                dotsClass: 'slide-dots',
                                responsive: [{
                                        breakpoint: 1499,
                                        settings: {
                                            slidesToShow: 3,
                                        }
                                    },
                                    {
                                        breakpoint: 1399,
                                        settings: {
                                            slidesToShow: 2,
                                        }
                                    },
                                    {
                                        breakpoint: 768,
                                        settings: {
                                            slidesToShow: 2,
                                            center: true,
                                        }
                                    },
                                    {
                                        breakpoint: 700,
                                        settings: {
                                            slidesToShow: 1
                                        }
                                    }
                                ],

                            });
                        }

                    });
                }(jQuery));
            </script>

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

            <!-- Start  Project Style Three -->
            <section class="project-details fix">
                <div class="container">
                    <div class="project-details-wrapper">
                        <div class="row g-4 justify-content-between align-items-center">
                            <div class="col-lg-7">
                                <div class="project-title-content">
                                    <span class="text">
                                        <?php echo wp_kses_post($settings['section_subtitle'], 'daltech_kses_allowed_html'); ?></span>
                                    <h2>
                                        <?php echo wp_kses_post($settings['section_title'], 'daltech_kses_allowed_html'); ?>
                                    </h2>
                                    <p>
                                        <?php echo wp_kses_post($settings['section_summary'], 'daltech_kses_allowed_html'); ?>
                                    </p>

                                    <?php if (!empty($settings['button_label'])) : ?>
                                        <a href="<?php echo esc_url($settings['url']['url']); ?>" class="theme-btn">
                                            <span>
                                                <?php echo wp_kses_post($settings['button_label'], 'daltech_kses_allowed_html'); ?>
                                                <i class="fas fa-chevron-right"></i>
                                            </span>
                                        </a>
                                    <?php endif; ?>
                                </div>
                            </div>
                            <div class="col-lg-3">
                                <div class="details-info">
                                    <?php
                                    foreach ($settings['info_list'] as $item) :
                                    ?>
                                        <div class="info-items mb-4">
                                            <h5><?php echo wp_kses_post($item['title'], 'daltech_kses_allowed_html'); ?></h5>
                                            <p><?php echo wp_kses_post($item['subtitle'], 'daltech_kses_allowed_html'); ?></p>
                                        </div>
                                    <?php
                                    endforeach;
                                    ?>
                                </div>
                            </div>
                        </div>
                        <div class="project-details-image">
                            <div class="row g-4">
                                <div class="col-lg-4">
                                    <div class="details-image">
                                        <?php
                                        if (!empty($settings['bg_image_one']['url'])) {
                                            echo daltech_img_tag(array(
                                                'url'    => esc_url($settings['bg_image_one']['url']),
                                            ));
                                        }
                                        ?>
                                    </div>
                                </div>
                                <div class="col-lg-8">
                                    <div class="details-image">
                                        <?php
                                        if (!empty($settings['bg_image_two']['url'])) {
                                            echo daltech_img_tag(array(
                                                'url'    => esc_url($settings['bg_image_two']['url']),
                                            ));
                                        }
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!-- End  Project Style Three -->

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

            <!-- Strat  Project Style Four -->
            <div class="container">
                <div class="project-details-wrapper">

                    <?php
                    $counter = 1;
                    foreach ($settings['layout_four_project_content_list'] as $item) :
                    ?>
                        <div class="project-details-content <?php echo esc_attr(('2' ==  $counter ? 'style-2' : '')); ?>">
                            <div class="row">
                                <div class="col-lg-4">
                                    <div class="title-content">
                                        <h2>
                                            <?php echo wp_kses_post($item['title'], 'daltech_kses_allowed_html'); ?>
                                        </h2>
                                    </div>
                                </div>
                                <div class="col-lg-1"></div>
                                <div class="col-lg-6">
                                    <div class="details-content">
                                        <p>
                                            <?php echo wp_kses_post($item['subtitle'], 'daltech_kses_allowed_html'); ?>
                                        </p>
                                        <?php echo wp_kses_post($item['check_list'], 'daltech_kses_allowed_html'); ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    <?php
                        $counter++;
                    endforeach;
                    ?>
                    <div class="project-details-image mt-0">
                        <div class="row g-4">
                            <div class="col-lg-6">
                                <?php
                                if (!empty($settings['bg_image_one']['url'])) {
                                    echo daltech_img_tag(array(
                                        'url'    => esc_url($settings['bg_image_one']['url']),
                                    ));
                                }
                                ?>
                            </div>
                            <div class="col-lg-6">
                                <?php
                                if (!empty($settings['bg_image_two']['url'])) {
                                    echo daltech_img_tag(array(
                                        'url'    => esc_url($settings['bg_image_two']['url']),
                                    ));
                                }
                                ?>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
            <!-- End  Project Style Four -->

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

            <!-- End  Project Style Five -->
            <div class="project-details-wrapper fix section-padding pt-0">
                <div class="container">
                    <div class="project-details-image mt-0">
                        <div class="row g-4">
                            <div class="col-lg-4">
                                <div class="details-image">
                                    <?php
                                    if (!empty($settings['bg_image_one']['url'])) {
                                        echo daltech_img_tag(array(
                                            'url'    => esc_url($settings['bg_image_one']['url']),
                                        ));
                                    }
                                    ?>
                                </div>
                            </div>
                            <div class="col-lg-8">
                                <div class="details-image">
                                    <?php
                                    if (!empty($settings['bg_image_two']['url'])) {
                                        echo daltech_img_tag(array(
                                            'url'    => esc_url($settings['bg_image_two']['url']),
                                        ));
                                    }
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- End  Project Style Five -->

<?php
        endif;
    }
}
