<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet"
        integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.3.0/css/all.min.css"
        integrity="sha512-SzlrxWUlpfuzQ+pcUCosxcglQRNAq/DZjVsC0lE40xsADsfeQoEypE+enwcOiGjk/bSuGGKHEyjSoQ1zVisanQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
</html>
<?php

if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly

class MYEA_Video_Area_Widget extends \Elementor\Widget_Base {

    public function get_name() {
        return 'myea_video_area';
    }

    public function get_title() {
        return 'TG Video Area';
    }

    public function get_icon() {
        return 'eicon-video-camera';
    }

    public function get_categories() {
        return [ 'general' ];
    }

    protected function register_controls() {

        // Video Content Section
        $this->start_controls_section(
            'section_video_content',
            [
                'label' => 'Video Content',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $this->add_control(
            'video_title',
            [
                'label' => 'Title',
                'type' => \Elementor\Controls_Manager::TEXTAREA,
                'default' => 'Watch Campus Life Video Tour',
            ]
        );

        $this->add_control(
            'video_sub_title',
            [
                'label' => 'Sub Title',
                'type' => \Elementor\Controls_Manager::TEXTAREA,
                'default' => "Vmply dummy text of the printing and typesetting industryorem\nIpsum industry's standard dum an unknowramble.",
            ]
        );

        $this->add_control(
            'video_url',
            [
                'label' => 'YouTube Video URL',
                'type' => \Elementor\Controls_Manager::TEXT,
                'placeholder' => 'https://www.youtube.com/watch?v=xxxx',
                'default' => 'http://www.youtube.com/watch?v=1iIZeIy7TqM',
                'label_block' => true,
            ]
        );

        $this->add_control(
            'bg_image',
            [
                'label' => 'Background Image',
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();

        // Background Image Handling
        $bg_url = ! empty( $settings['bg_image']['url'] ) ? esc_url( $settings['bg_image']['url'] ) : '';
        ?>
        
        <div class="video-area overlay-video bg-common-style" style="background-image: url('<?php echo $bg_url; ?>');">
            <div class="container">
                <div class="video-content">
                    <?php if ( ! empty( $settings['video_title'] ) ) : ?>
                        <h2 class="video-title"><?php echo wp_kses_post( $settings['video_title'] ); ?></h2>
                    <?php endif; ?>

                    <?php if ( ! empty( $settings['video_sub_title'] ) ) : ?>
                        <p class="video-sub-title"><?php echo nl2br( wp_kses_post( $settings['video_sub_title'] ) ); ?></p>
                    <?php endif; ?>

                    <?php if ( ! empty( $settings['video_url'] ) ) : ?>
                        <a class="play-btn popup-youtube wow bounceInUp" 
                           data-wow-duration="2s" 
                           data-wow-delay=".1s" 
                           href="<?php echo esc_url( $settings['video_url'] ); ?>">
                            <i class="fa fa-play" aria-hidden="true"></i>
                        </a>
                    <?php endif; ?>
                </div>
            </div>
        </div>

        <?php
    }
}