<?php
    namespace Pixebuilder\Element;
    
    // prevent direct file access
	if( !defined( 'ABSPATH' ) ) exit;

    class Image extends Item{

        static function get_name(){
            return 'image';
        }

        static function get_title(){
            return esc_html__('Image', 'pixebuilder');
        }

        static function get_icon(){
            return 'image';
        }

        static function item_class($settings){
            return 'pixe-type-flex';
        }
        
        static function render_content($settings){
            if( empty($settings['image']['id']) && empty($settings['image']['url']) ) return '';
            if( !isset($settings['overlay']) ) $settings['overlay'] = '';
            if( !isset($settings['overlay-atts']) ) $settings['overlay-atts'] = '';
            
            $image_size = empty($settings['layout']['image-size'])? 'full': $settings['layout']['image-size'];
            $image_link = empty($settings['link'])? array('link-to' => 'none'): $settings['link'];
            $image = array_merge($settings['image'], $image_link);
            $link_tag = pixe_get_link_tag($image);

            $ret  = '<div class="pixe-image" >';
            $ret .= $link_tag;
            if( !empty($image['id']) ){
                $ret .= wp_get_attachment_image($settings['image']['id'], $image_size);
                $ret .= pixe_get_image_overlay_content($settings['image']['id'], $settings['overlay-atts'], $settings['overlay']);
            }else if( !empty($image['url']) ){
                $ret .= pixe_get_image($image['url']);
            }
            $ret .= empty($link_tag)? '': '</a>';
            $ret .= '</div>';

            return $ret;
        }

    }

    \Pixe_Builder::register_element('Pixebuilder\Element\Image');