<?php
namespace AITheme\Elementor\Widgets;

use Elementor\Controls_Manager;

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

class Video_Centered extends AI_Widget_Base {
    public function get_name() { return 'ai_video_centered'; }
    public function get_title() { return __('Video Centered', 'ai-theme'); }
    public function get_icon() { return 'eicon-youtube'; }
    public function get_categories() { return array('ai-theme-video'); }

    protected function register_controls() {
        $this->start_controls_section('content_section', ['label' => __('Content', 'ai-theme'), 'tab' => Controls_Manager::TAB_CONTENT]);
        $this->add_control('title', ['label' => __('Title', 'ai-theme'), 'type' => Controls_Manager::TEXT]);
        $this->add_control('subtitle', ['label' => __('Subtitle', 'ai-theme'), 'type' => Controls_Manager::TEXT]);
        $this->add_control('video_url', ['label' => __('Video URL', 'ai-theme'), 'type' => Controls_Manager::URL]);
        $this->add_control('poster', ['label' => __('Poster Image', 'ai-theme'), 'type' => Controls_Manager::MEDIA]);
        $this->end_controls_section();
    }

    protected function render() {
        $s = $this->get_settings_for_display();
        ?>
        <div class="ai-video ai-video-centered bg-white py-16">
            <div class="ai-container-narrow">
                <?php if (!empty($s['title']) || !empty($s['subtitle'])) : ?>
                <div class="text-center mb-12">
                    <?php if (!empty($s['title'])) : ?><h2 class="ai-video-title text-4xl font-bold text-gray-900 mb-4"><?php echo esc_html($s['title']); ?></h2><?php endif; ?>
                    <?php if (!empty($s['subtitle'])) : ?><p class="ai-video-subtitle text-lg text-gray-600"><?php echo esc_html($s['subtitle']); ?></p><?php endif; ?>
                </div>
                <?php endif; ?>
                <?php if (!empty($s['video_url']['url'])) : ?>
                <div class="relative aspect-video bg-gray-900 rounded-2xl overflow-hidden shadow-2xl group">
                    <iframe src="<?php echo esc_url($s['video_url']['url']); ?>" title="Video player" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen class="absolute inset-0 w-full h-full"></iframe>
                </div>
                <?php endif; ?>
            </div>
        </div>
        <?php
    }
}
