<?php

namespace GenixCore\Widgets;

use Elementor\Widget_Base;
use \Elementor\Group_Control_Text_Shadow;
use \Elementor\Repeater;
use \Elementor\Control_Media;
use \Elementor\Utils;
use \Elementor\Core\Schemes\Typography;
use \Elementor\Controls_Manager;
use \Elementor\Group_Control_Border;
use \Elementor\Group_Control_Box_Shadow;
use \Elementor\Group_Control_Typography;
use \Elementor\Group_Control_Image_Size;


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

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

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

    /**
     * Retrieve the widget title.
     *
     * @since 1.0.0
     *
     * @access public
     *
     * @return string Widget title.
     */
    public function get_title()
    {
        return __('Pricing Home 5', '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()
    {


        // Pricing Section Header
        $this->start_controls_section(
            '_section_header_top',
            [
                'label' => esc_html__('Header', 'genixcore'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'section_top_titleh5',
            [
                'label' => esc_html__('Header Top Title', 'genixcore'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
                'default' => esc_html__('Our Pricings Plan', 'genixcore'),
            ]
        );
        $this->add_control(
            'section_top_stitleh5',
            [
                'label' => esc_html__('Header Top Short Title', 'genixcore'),
                'type' => Controls_Manager::TEXTAREA,
                'label_block' => true,
                'default' => esc_html__('We offer the best pricings around - from installations to repairs, maintenance, and more!', 'genixcore'),
            ]
        );
        $this->add_control(
            'section_pricing_bgh5',
            [
                'label' => esc_html__('Section Background', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $this->end_controls_section();


        // Pricing Section Shape Images
        $this->start_controls_section(
            '_pricing_section_shape',
            [
                'label' => esc_html__('Pricing Shape Image', 'genixcore'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );
        $this->add_control(
            'section_Shape_imageh5',
            [
                'label' => esc_html__('Header Shape Image', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );
        $this->add_control(
            'section_Shape_imageh52',
            [
                'label' => esc_html__('Header Shape Image Bottom', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $this->end_controls_section();





        // Pricing List
        $this->start_controls_section(
            '_section_price_listh5',
            [
                'label' => esc_html__('Pricing List', 'genixcore'),
                'tab' => Controls_Manager::TAB_CONTENT,
            ]
        );



        $repeater = new Repeater();


        $repeater->add_control(
            'tg_animationh5',
            [
                'label' => esc_html__('Select Animation Type', 'genixcore'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'default',
                'options' => [
                    'default' => esc_html__('Default', 'genixcore'),
                    'fade-up' => esc_html__('Fade Up', 'genixcore'),
                    'fade-right' => esc_html__('Fade Right', 'genixcore'),
                    'fade-left' => esc_html__('Fade Left', 'genixcore'),
                ],
                'label_block' => true,
            ]
        );
        $repeater->add_control(
            'tg_is_activeh5',
            [
                'label' => esc_html__('Select Pricing Type', 'genixcore'),
                'type' => \Elementor\Controls_Manager::SELECT,
                'default' => 'default',
                'options' => [
                    'default' => esc_html__('Default', 'genixcore'),
                    'active' => esc_html__('Popular', 'genixcore'),
                ],
            ]
        );
        $repeater->add_control(
            'main_titleh5',
            [
                'label' => esc_html__('Package Name', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'label_block' => true,
                'default' => esc_html__('Basic', 'genixcore'),
                'dynamic' => [
                    'active' => true
                ],
            ]
        );



        $repeater->add_control(
            'select_your_currency',
            [
                'label' => esc_html__('Select Your Currency', 'genixcore'),
                'type' => Controls_Manager::SELECT,
                'options' => [
                    '$' => esc_html__('US Dollar', 'genixcore'),
                    '€' => esc_html__('Euro', 'genixcore'), 
                    '£' => esc_html__('Pounds sterling', 'genixcore'), 
                    'R$' => esc_html__('Brazilian Real', 'genixcore'), 
                    'CA$' => esc_html__('Canadian Dollar', 'genixcore'), 
                    'A$' => esc_html__('Australian dollar', 'genixcore'), 
                    '৳' => esc_html__('Bangladeshi taka', 'genixcore'), 
                    '₹' => esc_html__('Indian rupee', 'genixcore'), 
                    '¥' => esc_html__('Japanese yen', 'genixcore'), 
                    '¥ /元' => esc_html__('Chinese yuan', 'genixcore'), 

                ],
                'default' => '$',
            ]
        );


        $repeater->add_control(
            'priceh5',
            [
                'label' => esc_html__('Price', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => '99',
                'dynamic' => [
                    'active' => true
                ]
            ]
        );

        $repeater->add_control(
            'durationh5',
            [
                'label' => esc_html__('Duration', 'genixcore'),
                'type' => Controls_Manager::TEXT,
                'default' => 'Monthly',
                'dynamic' => [
                    'active' => true
                ]
            ]
        );


        // icon and list title ----------------- 
        $repeater->add_control(
            'tg_svgh5',
            [
                'label' => esc_html__('Upload Icon', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $repeater->add_control(
            'list_itemh5',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('List Item', 'genixcore'),
                'default' => esc_html__('Weekly online meeting', 'genixcore'),
                'label_block' => true,
                'dynamic' => [
                    'active' => true,
                ]
            ]
        );
        $repeater->add_control(
            'tg_svgh52',
            [
                'label' => esc_html__('Upload Icon', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $repeater->add_control(
            'list_itemh52',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('List Item', 'genixcore'),
                'default' => esc_html__('Unlimited learning access', 'genixcore'),
                'label_block' => true,
                'dynamic' => [
                    'active' => true,
                ]
            ]
        );
        $repeater->add_control(
            'tg_svgh53',
            [
                'label' => esc_html__('Upload Icon', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
            ]
        );

        $repeater->add_control(
            'list_itemh53',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('List Item', 'genixcore'),
                'default' => esc_html__('24/7 technical support', 'genixcore'),
                'label_block' => true,
                'dynamic' => [
                    'active' => true,
                ]
            ]
        );
        $repeater->add_control(
            'tg_svgh54',
            [
                'label' => esc_html__('Upload Icon', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
 
            ]
        );

        $repeater->add_control(
            'list_itemh54',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('List Item', 'genixcore'),
                'default' => esc_html__('Personal training', 'genixcore'),
                'label_block' => true,
                'dynamic' => [
                    'active' => true,
                ]
            ]
        );
        $repeater->add_control(
            'tg_svgh55',
            [
                'label' => esc_html__('Upload Icon', 'genixcore'),
                'type' => Controls_Manager::MEDIA,
 
            ]
        );

        $repeater->add_control(
            'list_itemh55',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('List Item', 'genixcore'),
                'label_block' => true,
                'dynamic' => [
                    'active' => true,
                ]
            ]
        );

        // button text and url
        $repeater->add_control(
            'pricing_btn_txth5',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('Button Text', 'genixcore'),
                'default' => esc_html__('Choose Plan', 'genixcore'),
                'label_block' => true,
            ]
        );
        $repeater->add_control(
            'pricing_btn_urlh5',
            [
                'type' => Controls_Manager::TEXT,
                'label' => esc_html__('Button Url', 'genixcore'),
                'default' => esc_html__('#', 'genixcore'),
                'label_block' => true,
            ]
        );


        $this->add_control(
            'list_itemsh5',
            [
                'show_label' => false,
                'type' => Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'list_itemh5' => esc_html__('Weekly online meeting', 'genixcore'),
                    ],
                    [
                        'list_itemh52' => esc_html__('Unlimited learning access', 'genixcore'),
                    ],
                    [
                        'list_itemh53' => esc_html__('24/7 technical support', 'genixcore'),
                    ],
                    [
                        'list_itemh54' => esc_html__('Personal training', 'genixcore'),
                    ],
                ],
                'title_field' => '{{ list_itemh5 }}',
            ]
        );

        $this->end_controls_section();



        $this->start_controls_section(
            'section_style',
            [
                'label' => esc_html__('Style', 'genixcore'),
                'tab' => Controls_Manager::TAB_STYLE,
            ]
        );



        $this->add_control(
            'bg_hover_color',
            [
                'label' => esc_html__('Pricing Primary Color', 'genixcore'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .pricing__item-inner.active' => 'border-color: {{VALUE}}',
                    '{{WRAPPER}} .pricing__item-inner.active .trk-btn' => 'background: {{VALUE}}',
                    '{{WRAPPER}} .pricing__item-inner:hover' => 'border-color: {{VALUE}}',
                    '{{WRAPPER}} .trk-btn' => 'border-color: {{VALUE}}',
                    '{{WRAPPER}} .trk-btn:hover' => 'background: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'btn_text_color',
            [
                'label' => esc_html__('Button Color', 'genixcore'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .trk-btn' => 'color: {{VALUE}}',
                ],
            ]
        );

        $this->add_control(
            'text_hover_color',
            [
                'label' => esc_html__('Button Hover Color', 'genixcore'),
                'type' => Controls_Manager::COLOR,
                'selectors' => [
                    '{{WRAPPER}} .trk-btn:hover' => '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 
$pricing_bg = wp_get_attachment_url( $settings['section_pricing_bgh5']['id'], 'full' );                      
?>
  <section class="pricing padding-top padding-bottom bg--cover" 
    style="background-image:url(<?php if(!empty($pricing_bg)): echo esc_url($pricing_bg); endif; ?>)">
    <div class="section-header section-header--max50">
        <?php if(!empty($settings['section_top_titleh5'])): ?>
            <h2 class="mb-10 mt-minus-5"><?php echo esc_html($settings['section_top_titleh5']); ?></h2>
        <?php endif; ?>
        <?php if(!empty($settings['section_top_stitleh5'])): ?>
            <p><?php echo wp_kses_post($settings['section_top_stitleh5']); ?></p>
        <?php endif; ?>
    </div>
    <div class="container">
      <div class="pricing__wrapper">
        <div class="row g-4 align-items-center">
        <?php
        foreach ($settings['list_itemsh5'] as $item) : 
        ?>
        <div class="col-md-6 col-lg-4">
            <div class="pricing__item pricing__item--style2" data-aos="<?php echo esc_attr( $item['tg_animationh5'] ) ?>" data-aos-duration="1000">
              <div class="pricing__item-inner <?php echo esc_attr($item['tg_is_activeh5']); ?>">
                <div class="pricing__item-content">
                  <!-- pricing top part -->
                  <div class="pricing__item-top">
                    <h6 class="mb-15"><?php if(!empty($item['main_titleh5'])): echo esc_html($item['main_titleh5']); endif; ?></h6>
                    <h3 class="mb-25"><?php  if(!empty($item['select_your_currency'])): echo esc_html($item['select_your_currency']);  endif; ?> 
                    <?php if(!empty($item['priceh5'])): echo esc_html($item['priceh5']); endif; ?>/
                    <span><?php if(!empty($item['durationh5'])): echo esc_html($item['durationh5']); endif; ?></span> </h3>
                </div>
                <!-- pricing middle part -->
                <div class="pricing__item-middle">      
                    <ul class="pricing__list">
                        <li class="pricing__list-item">
                            <?php if(!empty($item['tg_svgh5']['url'])): ?>
                            <span>
                                <img src="<?php echo esc_url($item['tg_svgh5']['url']); ?>" alt="check" class="dark">
                            </span>
                            <?php endif; ?>
                            <?php if(!empty($item['list_itemh5'])): echo esc_html($item['list_itemh5']); endif; ?>
                        </li>
                        <li class="pricing__list-item">
                            <?php if(!empty($item['tg_svgh52']['url'])): ?>
                            <span>
                                <img src="<?php echo esc_url($item['tg_svgh52']['url']); ?>" alt="check" class="dark">
                            </span>
                            <?php endif; ?>
                            <?php if(!empty($item['list_itemh52'])): echo esc_html($item['list_itemh52']); endif; ?>
                        </li>
                        <li class="pricing__list-item">
                            <?php if(!empty($item['tg_svgh53']['url'])): ?>
                            <span>
                                <img src="<?php echo esc_url($item['tg_svgh53']['url']); ?>" alt="check" class="dark">
                            </span>
                            <?php endif; ?>
                            <?php if(!empty($item['list_itemh53'])): echo esc_html($item['list_itemh53']); endif; ?>
                        </li>

                        <li class="pricing__list-item">
                             <?php if(!empty($item['tg_svgh54']['url'])): ?>
                            <span>
                                <img src="<?php echo esc_url($item['tg_svgh54']['url']); ?>" alt="check" class="dark">
                            </span>
                            <?php endif; ?>
                            <?php if(!empty($item['list_itemh54'])): echo esc_html($item['list_itemh54']); endif; ?>
                        </li>
                        <?php if(!empty($item['tg_svgh55']['url']  ||  $item['list_itemh55'])): ?>
                        <li class="pricing__list-item"> 
                            <span>
                                <img src="<?php echo esc_url($item['tg_svgh55']['url']); ?>" alt="check" class="dark">
                            </span>
                            <?php echo esc_html($item['list_itemh55']); ?>
                        </li>
                        <?php endif; ?>
                    </ul>
                </div>
                <!-- pricing bottom part -->
                <?php if(!empty($item['pricing_btn_txth5'])): ?>
                <div class="pricing__item-bottom">
                    <a href="<?php echo esc_url($item['pricing_btn_urlh5']); ?>" class="trk-btn trk-btn--outline6 <?php echo esc_attr($item['tg_is_activeh5']); ?>"><?php echo esc_html($item['pricing_btn_txth5']); ?></a>
                </div>
                <?php endif; ?>
                </div>
              </div>
            </div>
        </div>
        <?php
         endforeach; 
        ?>
        </div>
      </div>
    </div>
    <?php 
    $pricing_shape1 = wp_get_attachment_url( $settings['section_Shape_imageh5']['id'], 'full' ); 
    $pricing_shape2 = wp_get_attachment_url( $settings['section_Shape_imageh52']['id'], 'full' );               
    ?>
    <div class="pricing__shape">
        <?php if(!empty($pricing_shape1)): ?>
        <span class="pricing__shape-item pricing__shape-item--5"> 
            <img src="<?php echo esc_url($pricing_shape1); ?>" alt="<?php echo bloginfo('name'); ?>">
        </span>
        <?php endif; ?>
        <?php if(!empty($pricing_shape2)): ?>
        <span class="pricing__shape-item pricing__shape-item--6"> 
            <img src="<?php echo esc_url($pricing_shape2); ?>" alt="<?php echo bloginfo('name'); ?>">
        </span>
        <?php endif; ?>
    </div>
  </section>
<?php
    }
}

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