<?php
namespace AITheme\Elementor\Widgets;

use Elementor\Controls_Manager;

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

class Modal_Contact extends AI_Widget_Base {
    public function get_name() { return 'ai_modal_contact'; }
    public function get_title() { return __('Modal Contact', 'ai-theme'); }
    public function get_icon() { return 'eicon-form-horizontal'; }
    public function get_categories() { return array('ai-theme-modal'); }

    protected function register_controls() {
        $this->start_controls_section('content_section', ['label' => __('Content', 'ai-theme'), 'tab' => Controls_Manager::TAB_CONTENT]);
        $this->add_control('button_text', ['label' => __('Button Text', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Contact Us', 'ai-theme')]);
        $this->add_control('modal_title', ['label' => __('Modal Title', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Contact Us', 'ai-theme')]);
        $this->add_control('name_placeholder', ['label' => __('Name Placeholder', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Your Name', 'ai-theme')]);
        $this->add_control('email_placeholder', ['label' => __('Email Placeholder', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Your Email', 'ai-theme')]);
        $this->add_control('message_placeholder', ['label' => __('Message Placeholder', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Your Message', 'ai-theme')]);
        $this->add_control('submit_text', ['label' => __('Submit Text', 'ai-theme'), 'type' => Controls_Manager::TEXT, 'default' => __('Send Message', 'ai-theme')]);
        $this->end_controls_section();
    }

    protected function render() {
        $s = $this->get_settings_for_display();
        $id = 'ai-modal-' . $this->get_id();
        ?>
        <div class="ai-modal-trigger">
            <button class="ai-modal-open bg-blue-600 text-white px-6 py-3 rounded-lg hover:bg-blue-700 transition-colors font-medium" data-modal="<?php echo esc_attr($id); ?>"><?php echo esc_html($s['button_text']); ?></button>
        </div>
        <div class="ai-modal fixed inset-0 z-50 hidden items-center justify-center p-4 bg-black/50 backdrop-blur-sm" id="<?php echo esc_attr($id); ?>">
            <div class="ai-modal-content ai-modal-contact max-w-lg w-full bg-white rounded-2xl shadow-2xl p-8 relative">
                <button class="ai-modal-close absolute top-4 right-4 text-gray-500 hover:text-gray-700 transition-colors text-2xl">&times;</button>
                <div class="mb-6">
                    <h3 class="text-3xl font-bold text-gray-900 mb-2"><?php echo esc_html($s['modal_title']); ?></h3>
                </div>
                <form class="ai-modal-form space-y-4">
                    <div>
                        <input type="text" placeholder="<?php echo esc_attr($s['name_placeholder']); ?>" required class="w-full px-4 py-2 rounded-lg border border-gray-300 bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                    </div>
                    <div>
                        <input type="email" placeholder="<?php echo esc_attr($s['email_placeholder']); ?>" required class="w-full px-4 py-2 rounded-lg border border-gray-300 bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-transparent">
                    </div>
                    <div>
                        <textarea placeholder="<?php echo esc_attr($s['message_placeholder']); ?>" required rows="4" class="w-full px-4 py-2 rounded-lg border border-gray-300 bg-white text-gray-900 focus:ring-2 focus:ring-blue-500 focus:border-transparent"></textarea>
                    </div>
                    <button type="submit" class="w-full bg-blue-600 text-white py-3 rounded-lg hover:bg-blue-700 transition-colors font-medium"><?php echo esc_html($s['submit_text']); ?></button>
                </form>
            </div>
        </div>
        <?php
    }
}
