<?php
namespace AITheme\Elementor\Widgets;

use Elementor\Controls_Manager;
use Elementor\Repeater;

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

class Features_Minimal extends AI_Widget_Base {
    public function get_name() { return 'ai_features_minimal'; }
    public function get_title() { return __('Features Minimal', 'ai-theme'); }
    public function get_icon() { return 'eicon-check-circle'; }
    public function get_categories() { return array('ai-theme-features'); }

    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]);

        $repeater = new Repeater();
        $repeater->add_control('title', ['label' => __('Title', 'ai-theme'), 'type' => Controls_Manager::TEXT]);
        $repeater->add_control('description', ['label' => __('Description', 'ai-theme'), 'type' => Controls_Manager::TEXTAREA]);
        $this->add_control('features', ['label' => __('Features', 'ai-theme'), 'type' => Controls_Manager::REPEATER, 'fields' => $repeater->get_controls()]);
        $this->end_controls_section();
    }

    protected function render() {
        $s = $this->get_settings_for_display();
        ?>
        <section class="ai-features ai-features-minimal py-16">
            <div class="ai-container">
                <?php if (!empty($s['title'])) : ?>
                <div class="text-center mb-12">
                    <h2 class="text-4xl font-bold mb-4"><?php echo esc_html($s['title']); ?></h2>
                </div>
                <?php endif; ?>
                <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8">
                    <?php foreach ($s['features'] as $f) : ?>
                    <div class="ai-feature-item text-center">
                        <div class="mb-3 flex items-center justify-center">
                            <div class="w-16 h-16 mx-auto rounded-full flex items-center justify-center relative">
                                <div class="absolute inset-0 rounded-full" style="background-color: var(--color-primary, #3b82f6); opacity: 0.1;"></div>
                                <span class="relative z-10 text-2xl">✓</span>
                            </div>
                        </div>
                        <h3 class="text-lg font-semibold mb-2"><?php echo esc_html($f['title']); ?></h3>
                        <div class="text-sm text-gray-600 prose prose-sm max-w-none"><?php echo wp_kses_post($f['description']); ?></div>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </section>
        <?php
    }
}
