<?php

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

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

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

    /**
     * Get widget icon.
     *
     * Retrieve Manage It 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 Manage It 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(
            'manage_it_content_style',
            [
                'label'        => esc_html__('Manage It 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'),
                ],
            ]
        );

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

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

        $layout_one_tab_list = new \Elementor\Repeater();

        $layout_one_tab_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_tab_list->add_control(
            'subtitle',
            [
                'label'         => esc_html__('Subtitle', 'daltech-core'),
                'type'             => \Elementor\Controls_Manager::TEXTAREA,
                'rows'            => '2',
                'default'      => __('Subtitle', 'daltech-core'),
                'label_block'     => true,
            ]
        );

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

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

        $layout_one_tab_list->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,
                ],
            ]
        );


        $layout_one_tab_list->add_control(
            'active_status',
            [
                'label' => __('Is active?', 'daltech-core'),
                'type' => \Elementor\Controls_Manager::SWITCHER,
                'label_on' => __('Yes', 'ploming-addon'),
                'label_off' => __('No', 'ploming-addon'),
                'return_value' => 'yes',
                'default' => 'no',
            ]
        );

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

        $this->add_control(
            'manage_it_image_divider',
            [
                'type' => \Elementor\Controls_Manager::DIVIDER,
            ]
        );

        $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' => ['1']
                ]
            ]
        );

        $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' => ['1']
                ]
            ]
        );

        $this->end_controls_section();

        // include DALTECH_PLUGIN_WIDGET_STYLE_PATH . 'Manage It-style.php';
    }

    // Output For User
    protected function render()
    {
        $settings = $this->get_settings_for_display();
        if ($settings['style'] == '1') :
?>
            <!--<< Manage It Section Start >>-->
            <section class="manage-it-section fix section-padding">
                <div class="container">
                    <div class="manage-it-wrapper">
                        <div class="row justify-content-between">
                            <div class="col-lg-6">
                                <div class="manage-it-content">
                                    <div class="section-title">
                                        <span class="fadeInUp">
                                            <?php echo wp_kses_post($settings['section_subtitle'], 'daltech_kses_allowed_html'); ?>
                                        </span>
                                        <h2 class="fadeInUp">
                                            <?php echo wp_kses_post($settings['section_title'], 'daltech_kses_allowed_html'); ?>
                                        </h2>
                                    </div>
                                    <div class="single-tab-items mt-4 mt-md-0">
                                        <ul class="nav mb-4" role="tablist">
                                            <?php
                                            $counter = 1;
                                            foreach ($settings['layout_one_tab_list'] as $item) :
                                            ?>
                                                <li class="nav-item fadeInUp" role="presentation">
                                                    <a href="#daltec-item<?php echo esc_attr($counter); ?>" data-bs-toggle="tab" class="nav-link <?php echo esc_attr(('yes' == $item['active_status'] ? 'active' : '')); ?>" role="tab">
                                                        <?php echo wp_kses_post($item['title'], 'daltech_kses_allowed_html'); ?>
                                                    </a>
                                                </li>
                                            <?php
                                                $counter++;
                                            endforeach;
                                            ?>
                                        </ul>
                                        <div class="tab-content">
                                            <?php
                                            $counter = 1;
                                            foreach ($settings['layout_one_tab_list'] as $item) :
                                            ?>
                                                <div id="daltec-item<?php echo esc_attr($counter); ?>" class="tab-pane fade <?php echo esc_attr(('yes' == $item['active_status'] ? 'show active' : '')); ?>" role="tabpanel">
                                                    <div class="tab-content-items">
                                                        <p class="fadeInUp">
                                                            <?php echo wp_kses_post($item['subtitle'], 'daltech_kses_allowed_html'); ?>
                                                        </p>
                                                        <div class="list-area">
                                                            <?php echo wp_kses_post($item['check_list'], 'daltech_kses_allowed_html'); ?>
                                                        </div>
                                                        <?php if (!empty($item['button_label'])) : ?>
                                                            <a href="<?php echo esc_url($item['url']['url']); ?>" class="theme-btn fadeInUp">
                                                                <span>
                                                                    <?php echo wp_kses_post($item['button_label'], 'daltech_kses_allowed_html'); ?>
                                                                    <i class="fas fa-chevron-right"></i>
                                                                </span>
                                                            </a>
                                                        <?php endif; ?>
                                                    </div>
                                                </div>
                                            <?php
                                                $counter++;
                                            endforeach;
                                            ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-lg-5 mt-5 mt-lg-0 wow fadeInUp" data-wow-delay=".4s">
                                <div class="manage-image bg-cover" style="background-image: url(<?php echo esc_url($settings['bg_image_one']['url']); ?>);">
                                    <div class="counting-shape">
                                        <?php
                                        if (!empty($settings['bg_image_two']['url'])) :
                                            echo daltech_img_tag(array(
                                                'url'   => esc_url($settings['bg_image_two']['url'])
                                            ));
                                        endif;
                                        ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
            <!-- End  Manage It Style One -->


<?php
        endif;
    }
}
