<?php
/**
 * Hero Gradient Widget
 *
 * Vibrant gradient background with glassmorphic design elements and stats
 *
 * @package AI_Theme
 */

namespace AITheme\Elementor\Widgets;

use Elementor\Controls_Manager;

if (!defined('ABSPATH')) {
    exit;
}

class Hero_Gradient extends AI_Widget_Base {

    public function get_name() {
        return 'ai_hero_gradient';
    }

    public function get_title() {
        return __('Hero Gradient', 'ai-theme');
    }

    public function get_icon() {
        return 'eicon-banner';
    }

    public function get_categories() {
        return array('ai-theme-hero');
    }

    public function get_keywords() {
        return array('hero', 'banner', 'gradient', 'glassmorphism', 'ai');
    }

    protected function register_controls() {
        $this->start_controls_section(
            'content_section',
            array(
                'label' => __('Content', 'ai-theme'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            )
        );

        $this->add_control(
            'badge_text',
            array(
                'label'   => __('Badge Text', 'ai-theme'),
                'type'    => Controls_Manager::TEXT,
                'default' => __('New Release', 'ai-theme'),
            )
        );

        $this->add_control(
            'heading',
            array(
                'label'   => __('Heading', 'ai-theme'),
                'type'    => Controls_Manager::TEXT,
                'default' => __('Beautiful Gradient Hero', 'ai-theme'),
            )
        );

        $this->add_control(
            'subheading',
            array(
                'label'   => __('Subheading', 'ai-theme'),
                'type'    => Controls_Manager::TEXTAREA,
                'default' => __('Create stunning websites with our platform. Experience the future of web design today.', 'ai-theme'),
            )
        );

        $this->add_control(
            'cta_text',
            array(
                'label'   => __('CTA Text', 'ai-theme'),
                'type'    => Controls_Manager::TEXT,
                'default' => __('Get Started', 'ai-theme'),
            )
        );

        $this->add_control(
            'cta_link',
            array(
                'label' => __('CTA Link', 'ai-theme'),
                'type'  => Controls_Manager::URL,
            )
        );

        $this->add_control(
            'background_image',
            array(
                'label' => __('Background Image', 'ai-theme'),
                'type'  => Controls_Manager::MEDIA,
            )
        );

        $this->end_controls_section();

        // Stats Section
        $this->start_controls_section(
            'stats_section',
            array(
                'label' => __('Stats', 'ai-theme'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            )
        );

        $this->add_control(
            'show_stats',
            array(
                'label'        => __('Show Stats', 'ai-theme'),
                'type'         => Controls_Manager::SWITCHER,
                'label_on'     => __('Yes', 'ai-theme'),
                'label_off'    => __('No', 'ai-theme'),
                'return_value' => 'yes',
                'default'      => 'yes',
            )
        );

        $this->add_control(
            'stat1_value',
            array(
                'label'     => __('Stat 1 Value', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => '50k+',
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->add_control(
            'stat1_label',
            array(
                'label'     => __('Stat 1 Label', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Active Users', 'ai-theme'),
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->add_control(
            'stat2_value',
            array(
                'label'     => __('Stat 2 Value', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => '98%',
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->add_control(
            'stat2_label',
            array(
                'label'     => __('Stat 2 Label', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Satisfaction', 'ai-theme'),
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->add_control(
            'stat3_value',
            array(
                'label'     => __('Stat 3 Value', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => '24/7',
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->add_control(
            'stat3_label',
            array(
                'label'     => __('Stat 3 Label', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Support', 'ai-theme'),
                'condition' => array('show_stats' => 'yes'),
            )
        );

        $this->end_controls_section();

        // Awards Section
        $this->start_controls_section(
            'awards_section',
            array(
                'label' => __('Awards/Badges', 'ai-theme'),
                'tab'   => Controls_Manager::TAB_CONTENT,
            )
        );

        $this->add_control(
            'show_awards',
            array(
                'label'        => __('Show Awards', 'ai-theme'),
                'type'         => Controls_Manager::SWITCHER,
                'label_on'     => __('Yes', 'ai-theme'),
                'label_off'    => __('No', 'ai-theme'),
                'return_value' => 'yes',
                'default'      => 'yes',
            )
        );

        $this->add_control(
            'award1_text',
            array(
                'label'     => __('Award 1', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Product of the Day', 'ai-theme'),
                'condition' => array('show_awards' => 'yes'),
            )
        );

        $this->add_control(
            'award2_text',
            array(
                'label'     => __('Award 2', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Top Rated 2024', 'ai-theme'),
                'condition' => array('show_awards' => 'yes'),
            )
        );

        $this->add_control(
            'award3_text',
            array(
                'label'     => __('Award 3', 'ai-theme'),
                'type'      => Controls_Manager::TEXT,
                'default'   => __('Trusted by 1000+ Teams', 'ai-theme'),
                'condition' => array('show_awards' => 'yes'),
            )
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();
        $bg_style = '';
        if (!empty($settings['background_image']['url'])) {
            $bg_url = esc_url($settings['background_image']['url']);
            $bg_style = "background-image: url({$bg_url}); background-size: cover; background-position: center;";
        }
        ?>
        <section
            class="ai-hero ai-hero-gradient relative min-h-screen flex items-center justify-center overflow-hidden"
            data-block-type="hero"
            data-block-variant="hero-gradient"
        >
            <!-- Animated gradient background layers -->
            <div class="absolute inset-0">
                <div class="absolute inset-0 bg-gradient-to-br from-violet-600 via-purple-600 to-fuchsia-600"></div>
                <div class="absolute inset-0 bg-gradient-to-tr from-pink-500 via-rose-500 to-orange-500 opacity-70"></div>
                <div class="absolute inset-0 bg-gradient-to-bl from-blue-500 via-cyan-500 to-teal-500 opacity-50"></div>

                <?php if (!empty($settings['background_image']['url'])) : ?>
                    <div class="absolute inset-0 opacity-20 mix-blend-overlay" style="<?php echo esc_attr($bg_style); ?>"></div>
                <?php endif; ?>
            </div>

            <!-- Floating geometric shapes -->
            <div class="absolute inset-0 overflow-hidden pointer-events-none">
                <div class="absolute top-20 left-20 w-32 h-32 bg-white/10 rounded-full blur-xl"></div>
                <div class="absolute top-40 right-32 w-24 h-24 bg-white/10 rounded-full blur-lg"></div>
                <div class="absolute bottom-32 left-40 w-40 h-40 bg-white/10 rounded-full blur-2xl"></div>
                <div class="absolute bottom-20 right-20 w-28 h-28 bg-white/10 rounded-full blur-xl"></div>
            </div>

            <!-- Main content -->
            <div class="relative max-w-6xl mx-auto px-6 md:px-8 py-20 text-center">
                <!-- Glassmorphic card container -->
                <div class="backdrop-blur-md bg-white/10 rounded-3xl p-8 md:p-12 lg:p-16 shadow-2xl border border-white/20">

                    <?php if (!empty($settings['badge_text'])) : ?>
                        <div class="inline-flex items-center gap-2 px-4 py-2 rounded-full bg-white/20 backdrop-blur-sm mb-8">
                            <span class="w-2 h-2 rounded-full bg-white animate-pulse"></span>
                            <span class="text-white text-sm font-semibold"><?php echo esc_html($settings['badge_text']); ?></span>
                        </div>
                    <?php endif; ?>

                    <?php if (!empty($settings['heading'])) : ?>
                        <h1 class="ai-hero-heading text-6xl md:text-7xl lg:text-8xl font-black leading-tight text-white mb-8">
                            <?php echo esc_html($settings['heading']); ?>
                        </h1>
                    <?php endif; ?>

                    <?php if (!empty($settings['subheading'])) : ?>
                        <p class="ai-hero-subheading text-xl md:text-2xl text-white/90 max-w-3xl mx-auto mb-10">
                            <?php echo esc_html($settings['subheading']); ?>
                        </p>
                    <?php endif; ?>

                    <?php if (!empty($settings['cta_text'])) : ?>
                        <div class="mb-10">
                            <a
                                href="<?php echo esc_url($settings['cta_link']['url'] ?? '#'); ?>"
                                class="inline-flex items-center justify-center gap-2 px-10 py-5 text-lg font-bold shadow-2xl hover:shadow-3xl hover:scale-105 transition-all duration-300 bg-white text-purple-600 rounded-lg"
                            >
                                <?php echo esc_html($settings['cta_text']); ?>
                                <svg class="w-6 h-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 8l4 4m0 0l-4 4m4-4H3" />
                                </svg>
                            </a>
                        </div>
                    <?php endif; ?>

                    <?php if ($settings['show_stats'] === 'yes') : ?>
                        <div class="grid grid-cols-3 gap-8 max-w-2xl mx-auto">
                            <?php if (!empty($settings['stat1_value'])) : ?>
                                <div class="backdrop-blur-sm bg-white/10 rounded-2xl p-6 border border-white/20">
                                    <div class="text-4xl font-bold text-white mb-2"><?php echo esc_html($settings['stat1_value']); ?></div>
                                    <div class="text-white/80 text-sm"><?php echo esc_html($settings['stat1_label']); ?></div>
                                </div>
                            <?php endif; ?>
                            <?php if (!empty($settings['stat2_value'])) : ?>
                                <div class="backdrop-blur-sm bg-white/10 rounded-2xl p-6 border border-white/20">
                                    <div class="text-4xl font-bold text-white mb-2"><?php echo esc_html($settings['stat2_value']); ?></div>
                                    <div class="text-white/80 text-sm"><?php echo esc_html($settings['stat2_label']); ?></div>
                                </div>
                            <?php endif; ?>
                            <?php if (!empty($settings['stat3_value'])) : ?>
                                <div class="backdrop-blur-sm bg-white/10 rounded-2xl p-6 border border-white/20">
                                    <div class="text-4xl font-bold text-white mb-2"><?php echo esc_html($settings['stat3_value']); ?></div>
                                    <div class="text-white/80 text-sm"><?php echo esc_html($settings['stat3_label']); ?></div>
                                </div>
                            <?php endif; ?>
                        </div>
                    <?php endif; ?>
                </div>

                <?php if ($settings['show_awards'] === 'yes') : ?>
                    <div class="flex flex-wrap justify-center gap-6 mt-12 opacity-80">
                        <?php if (!empty($settings['award1_text'])) : ?>
                            <div class="backdrop-blur-sm bg-white/10 rounded-lg px-6 py-3 border border-white/20">
                                <span class="text-white text-sm font-semibold"><?php echo esc_html($settings['award1_text']); ?></span>
                            </div>
                        <?php endif; ?>
                        <?php if (!empty($settings['award2_text'])) : ?>
                            <div class="backdrop-blur-sm bg-white/10 rounded-lg px-6 py-3 border border-white/20">
                                <span class="text-white text-sm font-semibold"><?php echo esc_html($settings['award2_text']); ?></span>
                            </div>
                        <?php endif; ?>
                        <?php if (!empty($settings['award3_text'])) : ?>
                            <div class="backdrop-blur-sm bg-white/10 rounded-lg px-6 py-3 border border-white/20">
                                <span class="text-white text-sm font-semibold"><?php echo esc_html($settings['award3_text']); ?></span>
                            </div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </section>
        <?php
    }
}
