<?php

namespace GenixCore\Widgets;

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use \Elementor\Group_Control_Background;
use \Elementor\Group_Control_Image_Size;
use \Elementor\Repeater;
use \Elementor\Utils;
use \Elementor\Control_Media;

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

/**
 * Bitrader Core
 *
 * Elementor widget for hello world.
 *
 * @since 1.0.0
 */
class TG_ABOUT_SECTION extends Widget_Base
{

    /**
     * Retrieve the widget name.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget name.
     */
    public function get_name()
    {
        return 'genix-aboutsection';
    }

    /**
     * Retrieve the widget title.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title()
    {
        return __('Bitrader About', 'genixcore');
    }

    /**
     * Retrieve the widget icon.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget icon.
     */
    public function get_icon()
    {
        return 'genix-icon';
    }

    /**
     * Retrieve the list of categories the widget belongs to.
     *
     * Used to determine where to display the widget in the editor.
     *
     * Note that currently Elementor supports only one category.
     * When multiple categories passed, Elementor uses the first one.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return array Widget categories.
     */
    public function get_categories()
    {
        return ['genixcore'];
    }

    /**
     * Retrieve the list of scripts the widget depended on.
     *
     * Used to set scripts dependencies required to run the widget.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return array Widget scripts dependencies.
     */
    public function get_script_depends()
    {
        return ['genixcore'];
    }

    /**
     * Register the widget controls.
     *
     * Adds different input fields to allow the user to change and customize the widget settings.
     *
     * @since 1.0.0
     *
     * @access protected
     */
    protected function register_controls()
    {

        // layout Panel
        $this->start_controls_section(
            'genix_Aboutsec',
            [
                'label' => esc_html__('Design Layout', 'genixcore'),
            ]
        );
        $this->add_control(
            'tg_about_style',
            [
                'label' => esc_html__('Select Layout', 'genixcore'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    'layout-1' => esc_html__('Layout 1', 'genixcore'),
                    'layout-2' => esc_html__('Layout 2', 'genixcore'),
                ],
                'default' => 'layout-1',
            ]
        );
        $this->end_controls_section();



        // _tg_image h4 
        $this->start_controls_section(
            '_tg_about_sectionh4',
            [
                'label' => esc_html__('Image', 'genixcore'),
                'condition' => [
                    'tg_about_style' => 'layout-1'
                ]
            ]
        );

        $this->add_control(
            'tg_imageh4',
            [
                'label' => esc_html__('Choose Image', 'genixcore'),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->add_group_control(
            Group_Control_Image_Size::get_type(),
            [
                'name' => 'tg_image_size',
                'default' => 'full',
                'exclude' => [
                    'custom'
                ]
            ]
        );
        $this->end_controls_section();



        // _tg_image h5 
        $this->start_controls_section(
            '_tg_about_sectionh5',
            [
                'label' => esc_html__('Image', 'genixcore'),
                'condition' => [
                    'tg_about_style' => 'layout-2'
                ]
            ]
        );

        $this->add_control(
            'tg_imageh5',
            [
                'label' => esc_html__('Choose Image', 'genixcore'),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );
        $this->end_controls_section();
        // _tg_image h5 


         // _tg_author h5
        $this->start_controls_section(
            '_tg_progress_content',
            [
                'label' => esc_html__('Progress bar content', 'genixcore'),
                'condition' => [
                    'tg_about_style' => 'layout-2'
                ]
            ]
        );

        $this->add_control(
            'about_progressn',
            [
                'label' => esc_html__('Progress Number', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => wp_kses_post('90', 'genixcore'),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'about_progresstitle',
            [
                'label' => esc_html__('About Progress Title', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => wp_kses_post('Satisfied clients', 'genixcore'),
                'label_block' => true,
            ]
        );

        $this->end_controls_section();




        // h5 about right 
        $this->start_controls_section(
            '__tg_about_rights',
            [
                'label' => esc_html__('About right content style 2', 'genixcore'),
                'condition' => [
                    'tg_about_style' => 'layout-2'
                ]
            ]
        );
        $this->add_control(
            'about_h5titles',
            [
                'label' => esc_html__('Title', 'genixcore'),
                'type' => Controls_Manager::TEXTAREA,
                'default' => wp_kses_post('Our Commitment To Help Growing Your Business', 'genixcore'),
                'label_block' => true,
            ]
        );



        $fact = new \Elementor\Repeater();

        $fact->add_control(
            'about_h5title',
            [
                'label' => esc_html__('About title', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Building a Better Trading Future', 'genixcore'),
                'label_block' => true,
            ]
        );

        $fact->add_control(
            'about_h5titleimg',
            [
                'label' => esc_html__('Small Image', 'genixcore'),
                'type' => Controls_Manager::MEDIA,

            ]
        );

        $this->add_control(
            'abouts_item_lists',
            [
                'label' => esc_html__('About Lists', 'genixcore'),
                'type' => Controls_Manager::REPEATER,
                'fields' => $fact->get_controls(),
            ]
        );

        $this->end_controls_section();
        // Banner Fact ================================



        // _tg_author
        $this->start_controls_section(
            '_tg_author_infoh4',
            [
                'label' => esc_html__('Author Info', 'genixcore'),
                'condition' => [
                    'tg_about_style' => 'layout-1'
                ]
            ]
        );

        $this->add_control(
            'tg_author_imageh4',
            [
                'label' => esc_html__('Choose Image', 'genixcore'),
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->add_control(
            'about_titleh4',
            [
                'label' => esc_html__('Title', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => wp_kses_post('Mobarok Hossain', 'genixcore'),
                'label_block' => true,
            ]
        );

        $this->add_control(
            'about_stitle4',
            [
                'label' => esc_html__('About Short Title', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => wp_kses_post('Founder & MD', 'genixcore'),
                'label_block' => true,
            ]
        );

        $this->end_controls_section();



        // about right section
        $this->start_controls_section(
            '_about_right_section',
            [
                'label' => esc_html__('About Right Section', 'genixcore'),
            ]
        );

        $this->add_control(
            'abouts_titleh4',
            [
                'label' => esc_html__('Title', 'genixcore'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
            ]
        );

        $this->add_control(
            'about_desch4',
            [
                'label' => esc_html__('Description', 'genixcore'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
            ]
        );

        $this->end_controls_section();



        // About area custom start ================
        $this->start_controls_section(
            'tg_button_about',
            [
                'label' => esc_html__('Button', 'genixcore'),
           
            ]
        );

        $this->add_control(
            'about_button_show',
            [
                'label' => esc_html__('Show Button', 'genixcore'),
                'type' => Controls_Manager::SWITCHER,
                'label_on' => esc_html__('Show', 'genixcore'),
                'label_off' => esc_html__('Hide', 'genixcore'),
                'return_value' => 'yes',
                'default' => 'yes',
            ]
        );

        $this->add_control(
            'tgabout_btn_text',
            [
                'label' => esc_html__('Button Text', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => esc_html__('Button Text', 'genixcore'),
                'title' => esc_html__('Enter button text', 'genixcore'),
                'label_block' => true,
                'condition' => [
                    'about_button_show' => 'yes'
                ],
            ]
        );

        $this->add_control(
            'tgabout_btn_link_type',
            [
                'label' => esc_html__('Button Link Type', 'genixcore'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    '1' => 'Custom Link',
                    '2' => 'Internal Page',
                ],
                'default' => '1',
                'label_block' => true,
                'condition' => [
                    'about_button_show' => 'yes'
                ],
            ]
        );

        $this->add_control(
            'tgabout_btn_link',
            [
                'label' => esc_html__('Button link', 'genixcore'),
                'type' => Controls_Manager::URL,
                'dynamic' => [
                    'active' => true,
                ],
                'placeholder' => esc_html__('https://your-link.com', 'genixcore'),
                'show_external' => false,
                'default' => [
                    'url' => '#',
                    'is_external' => true,
                    'nofollow' => true,
                    'custom_attributes' => '',
                ],
                'condition' => [
                    'tgabout_btn_link_type' => '1',
                    'about_button_show' => 'yes'
                ],
                'label_block' => true,
            ]
        );
        $this->add_control(
            'tgabout_btn_page_link',
            [
                'label' => esc_html__('Select Button Page', 'genixcore'),
                'type' => Controls_Manager::SELECT2,
                'label_block' => true,
                'options' => genix_get_all_pages(),
                'condition' => [
                    'tgabout_btn_link_type' => '2',
                    'about_button_show' => 'yes'
                ]
            ]
        );

        $this->add_responsive_control(
            'tg_align',
            [
                'label' => esc_html__('Alignment', 'genixcore'),
                'type' => Controls_Manager::CHOOSE,
                'options' => [
                    'left' => [
                        'title' => esc_html__('Left', 'genixcore'),
                        'icon' => 'eicon-text-align-left',
                    ],
                    'center' => [
                        'title' => esc_html__('Center', 'genixcore'),
                        'icon' => 'eicon-text-align-center',
                    ],
                    'right' => [
                        'title' => esc_html__('Right', 'genixcore'),
                        'icon' => 'eicon-text-align-right',
                    ],
                ],
                'default' => 'left',
                'toggle' => false,
                'selectors' => [
                    '{{WRAPPER}}' => 'text-align: {{VALUE}};'
                ]
            ]
        );
        $this->end_controls_section();
        // About area custom start ================


        // Bittrade button bg color
        $this->start_controls_section(
            '_about_section_btn_bgh4',
            [
                'label' => esc_html__('Bittrade Button BG Color h4', 'genixcore'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );
        // Banner button bg color
        $this->add_control(
            'h4_button_aboutbg',
            [
                'label' => esc_html__( 'Button BG Color', 'genixcore' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#00D094',
                'selectors' => [
                    '{{WRAPPER}} .about_btnc a' => 'background-color: {{VALUE}}',
                ],
            ]
        );


        $this->end_controls_section();



        // Bittrade button bg color h5
        $this->start_controls_section(
            '_about_section_btn_bgh5',
            [
                'label' => esc_html__('Bittrade Button BG Color h5', 'genixcore'),
                'tab'   => Controls_Manager::TAB_STYLE,
            ]
        );
        // Banner button bg color
        $this->add_control(
            'h5_button_aboutbg',
            [
                'label' => esc_html__( 'Button BG Color', 'genixcore' ),
                'type' => \Elementor\Controls_Manager::COLOR,
                'default' => '#3863E0',
                'selectors' => [
                    '{{WRAPPER}} .about_btnch5 a' => 'background-color: {{VALUE}}',
                ],
            ]
        );


        $this->end_controls_section();






    }

    /**
     * Render the widget output on the frontend.
     *
     * Written in PHP and used to generate the final HTML.
     *
     * @since 1.0.0
     *
     * @access protected
     */
    protected function render()
    {
        $settings = $this->get_settings_for_display();

        
    ?>

        <script>
            jQuery(document).ready(function($) {

                AOS.init();

            });
        </script>

    <?php if ($settings['tg_about_style']  == 'layout-1') : ?>
  
    <section class="about about--style3 padding-bottom ">
        <div class="container">
          <div class="about__wrapper">
            <div class="row g-4 align-items-center">
              <div class="col-md-6">
                <div class="about__thumb about__thumb--style4" data-aos="fade-right" data-aos-duration="800">
                  <div class="about__thumb-inner">
                    <div class="about__thumb-image text-center floating-content">
                        <?php
                        $about_bigimg = wp_get_attachment_url( $settings['tg_imageh4']['id'], 'full' );
                        if (!empty($about_bigimg)) : 
                        ?>
                        <img class="dark" src="<?php echo esc_url($about_bigimg); ?>" alt="<?php bloginfo('name'); ?>">
                      <?php endif; ?>
                      <div class="floating-content__bottom-left floating-content__bottom-left--style3" data-aos="fade-right" data-aos-duration="1000">
                        <div class="floating-content__item floating-content__item--style4">
                            <?php
                            $about_img = wp_get_attachment_url( $settings['tg_author_imageh4']['id'], 'full' );
                            if (!empty($about_img)) : 
                            ?>
                                <div class="floating-content__item-thum">
                                    <img src="<?php echo esc_url($about_img); ?>" width="65" alt="<?php echo esc_attr__('Author', 'genixcore') ?>">
                                </div>
                            <?php endif; ?>
                            <?php if (!empty($settings['about_titleh4'] || $settings['about_stitle4'])) : ?>
                                <div class="floating-content__item-content">
                                    <p><?php echo wp_kses_post($settings['about_titleh4']) ?></p>
                                    <span><?php echo wp_kses_post($settings['about_stitle4']) ?></span>
                                </div>
                            <?php endif; ?>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="about__content" data-aos="fade-left" data-aos-duration="800">
                <?php if (!empty($settings['abouts_titleh4'])) : ?>
                  <h2><?php echo wp_kses_post($settings['abouts_titleh4']) ?></h2>
                <?php endif; ?>
                <?php if (!empty($settings['about_desch4'])) : ?>
                  <p class="mb-0"><?php echo wp_kses_post($settings['about_desch4']) ?> </p>
                <?php endif; ?>


                <?php 
                // About button area  start ================
                if ('2' == $settings['tgabout_btn_link_type']) {
                    $this->add_render_attribute('tg-button-arg', 'href', get_permalink($settings['tgabout_btn_page_link']));
                    $this->add_render_attribute('tg-button-arg', 'target', '_self');
                    $this->add_render_attribute('tg-button-arg', 'rel', 'nofollow');
                    $this->add_render_attribute('tg-button-arg', 'class', 'trk-btn trk-btn--primary trk-btn--arrow');
                } else {
                    if (!empty($settings['tgabout_btn_link']['url'])) {
                        $this->add_link_attributes('tg-button-arg', $settings['tgabout_btn_link']);
                        $this->add_render_attribute('tg-button-arg', 'class', 'trk-btn trk-btn--primary trk-btn--arrow');
                    }
                    
                }
                ?>
                <?php if (!empty($settings['about_button_show'])) : ?>
                    <div class="about_btnc">
                      <a <?php echo $this->get_render_attribute_string('tg-button-arg'); ?>>
                        <?php echo $settings['tgabout_btn_text']; ?>    
                      </a>
                    </div>
                <?php
                endif; 
                // About button area  start ================
                ?>

                </div>
              </div>
            </div>
          </div>
        </div>
    </section>


    <?php else: ?>

    <section class="about about--style3 padding-top padding-bottom ">
        <div class="container">
          <div class="about__wrapper">
            <div class="row g-5 align-items-center justify-content-between">
              <div class="col-md-6">
                <div class="about__thumb about__thumb--style3" data-aos="fade-right" data-aos-duration="800">
                  <div class="about__thumb-inner">
                    <div class="about__thumb-image text-center floating-content">
                        <?php
                            $about_img2 = wp_get_attachment_url( $settings['tg_imageh5']['id'], 'full' );
                            if (!empty($about_img2)) : 
                            ?>
                            <img src="<?php echo esc_url($about_img2); ?>" alt="<?php echo esc_attr__('Thumbnail', 'genixcore') ?>">
                        <?php endif; ?>

                      <div class="floating-content__top-right floating-content__top-right--style3" data-aos="fade-up" data-aos-duration="1000">
                        <div class="floating-content__item floating-content__item--style6">

                          <h3> <span class="purecounter" data-purecounter-start="0" data-purecounter-end="<?php echo esc_attr($settings['about_progressn']); ?>"></span>%
                          </h3>
                          <p><?php echo esc_html($settings['about_progresstitle']); ?></p>

                          <div class="progress">
                            <div class="progress-bar--style2 w-75" role="progressbar" aria-valuenow="90" aria-valuemin="0"
                              aria-valuemax="100"></div>
                          </div>
                        </div>
                      </div>
                    </div>
                  </div>
                </div>
              </div>
              <div class="col-md-6">
                <div class="about__content" data-aos="fade-left" data-aos-duration="800">
                  <h2><?php if(!empty($settings['about_h5titles'])): echo esc_html($settings['about_h5titles']); endif; ?></h2>
                  <ul>
                    <?php foreach ($settings['abouts_item_lists'] as $item): ?>
                    <li>
                        <span>
                        <?php
                            $about_icon2 = wp_get_attachment_url( $item['about_h5titleimg']['id'], 'full' );
                            if (!empty($about_icon2)) : 
                            ?>
                            <img src="<?php echo esc_url($about_icon2); ?>" alt="<?php echo esc_attr__('Icon img', 'genixcore') ?>" class="dark" >
                        <?php endif; ?>
         
                        </span> 
                        <?php if(!empty($item['about_h5title'])): echo esc_html($item['about_h5title']); endif; ?>
                    </li>
                    <?php endforeach;  ?>
                  </ul>

                <?php 
                // About button area  start ================
                if ('2' == $settings['tgabout_btn_link_type']) {
                    $this->add_render_attribute('tg-button-arg', 'href', get_permalink($settings['tgabout_btn_page_link']));
                    $this->add_render_attribute('tg-button-arg', 'target', '_self');
                    $this->add_render_attribute('tg-button-arg', 'rel', 'nofollow');
                    $this->add_render_attribute('tg-button-arg', 'class', 'trk-btn  trk-btn--tertiary');
                } else {
                    if (!empty($settings['tgabout_btn_link']['url'])) {
                        $this->add_link_attributes('tg-button-arg', $settings['tgabout_btn_link']);
                        $this->add_render_attribute('tg-button-arg', 'class', 'trk-btn  trk-btn--tertiary');
                    }
                    
                }
                ?>
                <?php if (!empty($settings['about_button_show'])) : ?>
                <div class="about_btnch5">
                    <a <?php echo $this->get_render_attribute_string('tg-button-arg'); ?>>
                        <?php echo esc_html($settings['tgabout_btn_text']); ?>    
                    </a>
                </div>
                <?php
                endif; 
                // About button area  start ================
                ?>
                </div>
              </div>
            </div>
          </div>
        </div>
    </section>

    <?php endif; ?>

<?php
    }
}

$widgets_manager->register(new TG_ABOUT_SECTION());
