<?php

if (!defined('ABSPATH')) exit;

class EIC_Imagen_Card_Widget extends \Elementor\Widget_Base {

    public function get_name() {
        return 'imagen_card_widget';
    }

    public function get_title() {
        return 'Imagen Card Adaptable';
    }

    public function get_icon() {
        return 'eicon-image';
    }

    public function get_categories() {
        return ['general'];
    }

    protected function register_controls() {

        $this->start_controls_section(
            'content_section',
            [
                'label' => 'Imagen'
            ]
        );

        $this->add_control(
            'imagen',
            [
                'label' => 'Seleccionar Imagen',
                'type' => \Elementor\Controls_Manager::MEDIA,
                'default' => [
                    'url' => \Elementor\Utils::get_placeholder_image_src(),
                ],
            ]
        );

        $this->add_control(
            'altura',
            [
                'label' => 'Altura',
                'type' => \Elementor\Controls_Manager::SLIDER,
                'size_units' => ['px','vh'],
                'range' => [
                    'px' => ['min'=>200,'max'=>800],
                    'vh' => ['min'=>20,'max'=>100]
                ],
                'default' => [
                    'unit' => 'px',
                    'size' => 400
                ]
            ]
        );

        $this->end_controls_section();
    }

    protected function render() {

        $settings = $this->get_settings_for_display();

        ?>
        <div class="eic-card" style="height:<?php echo $settings['altura']['size'].$settings['altura']['unit']; ?>">
            <img src="<?php echo esc_url($settings['imagen']['url']); ?>" />
        </div>
        <?php
    }
}
