<?php
if ( ! defined('ABSPATH') ) { exit; }
if ( ! class_exists('Elementor\\Widget_Base') ) { return; }

use Elementor\Widget_Base;
use Elementor\Controls_Manager;
use Elementor\Repeater;

class Nikan_Unordered_Grid extends Widget_Base {

  public function get_name(){ return 'nikan_unordered_grid'; }
  public function get_title(){ return 'بنر نامنظم'; }
  public function get_icon(){ return 'eicon-gallery-grid'; }
  public function get_categories(){ return ['nikan']; }

  protected function register_controls(){
    $rep = new Repeater();
    $rep->add_control('image',[
      'label'=>'تصویر',
      'type'=>Controls_Manager::MEDIA,
    ]);
    $rep->add_control('link',[
      'label'=>'لینک',
      'type'=>Controls_Manager::URL,
    ]);

    $this->add_control('items',[
      'label'=>'آیتم‌ها',
      'type'=>Controls_Manager::REPEATER,
      'fields'=>$rep->get_controls(),
    ]);
  }

  protected function render(){
    $s=$this->get_settings_for_display();
    if(empty($s['items'])) return;
    ?>
    <div class="nikan-unordered-grid">
      <?php foreach($s['items'] as $it): ?>
        <a href="<?php echo esc_url($it['link']['url']); ?>">
          <img src="<?php echo esc_url($it['image']['url']); ?>">
        </a>
      <?php endforeach; ?>
    </div>
    <?php
  }
}
