<!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_Service1_Area_Widget extends \Elementor\Widget_Base {

    public function get_name() {
        return 'myea_service1_area';
    }

    public function get_title() {
        return 'TG Service1 Area';
    }

    public function get_icon() {
        return 'eicon-info-box';
    }

    public function get_categories() {
        return [ 'general' ];
    }

    protected function register_controls() {

        $this->start_controls_section(
            'section_services',
            [
                'label' => 'Services',
                'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
            ]
        );

        $repeater = new \Elementor\Repeater();

        // আইকন ফিল্ড যোগ করা হয়েছে
        $repeater->add_control(
            'selected_icon',
            [
                'label' => 'Icon Class',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'fas fa-graduation-cap',
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'service_title',
            [
                'label' => 'Title',
                'type' => \Elementor\Controls_Manager::TEXT,
                'default' => 'Service Title',
                'label_block' => true,
            ]
        );

        $repeater->add_control(
            'service_content',
            [
                'label' => 'Content',
                'type' => \Elementor\Controls_Manager::TEXTAREA,
                'default' => 'Eimply dummy text printing ypese tting industry.',
            ]
        );

        $repeater->add_control(
            'service_link',
            [
                'label' => 'Link',
                'type' => \Elementor\Controls_Manager::URL,
                'placeholder' => 'https://your-link.com',
            ]
        );

        $this->add_control(
            'services',
            [
                'label' => 'Service Items',
                'type' => \Elementor\Controls_Manager::REPEATER,
                'fields' => $repeater->get_controls(),
                'default' => [
                    [
                        'service_title' => 'Scholarship Facility',
                        'selected_icon' => ['value' => 'fas fa-graduation-cap', 'library' => 'fa-solid'],
                    ],
                    [
                        'service_title' => 'Skilled Lecturers',
                        'selected_icon' => ['value' => 'fas fa-user', 'library' => 'fa-solid'],
                    ],
                    [
                        'service_title' => 'Book Library & Store',
                        'selected_icon' => ['value' => 'fas fa-book', 'library' => 'fa-solid'],
                    ],
                ],
                'title_field' => '{{{ service_title }}}',
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {
        $settings = $this->get_settings_for_display();

        if ( empty( $settings['services'] ) ) {
            return;
        }
        ?>
        <div class="service1-area">
            <div class="service1-inner-area">
                <div class="container">
                    <div class="row service1-wrapper">
                        <?php 
                        foreach ( $settings['services'] as $index => $item ) : 
                            $link_key = 'link_' . $index;
                            if ( ! empty( $item['service_link']['url'] ) ) {
                                $this->add_link_attributes( $link_key, $item['service_link'] );
                            }
                        ?>
                            <div class="col-xl-4 col-lg-4 col-md-4 col-sm-12 service-box1 elementor-repeater-item-<?php echo esc_attr( $item['_id'] ); ?>">
                                <div class="service-box-content">
                                    <h3>
                                        <?php if ( ! empty( $item['service_link']['url'] ) ) : ?>
                                            <a <?php echo $this->get_render_attribute_string( $link_key ); ?>>
                                        <?php endif; ?>
                                            <?php echo esc_html( $item['service_title'] ); ?>
                                        <?php if ( ! empty( $item['service_link']['url'] ) ) : ?>
                                            </a>
                                        <?php endif; ?>
                                    </h3>
                                    <p><?php echo wp_kses_post( $item['service_content'] ); ?></p>
                                </div>
                                <div class="service-box-icon">
                                    <i class="<?php echo esc_attr( $item['selected_icon'] ); ?>" aria-hidden="true"></i>
                                </div>
                            </div>
                        <?php endforeach; ?>
                    </div>
                </div>
            </div>
        </div>
        <?php
    }
}