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

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

        static function get_default(){
            return array(
                'icon' => array(
                    'icon' => array( 
                        "type" => "font-awesome", 
                        "value" => "fas fa-cloud-arrow-up"
                    ),
                    'width' => '30px'
                )
            );
        }

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

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

        static function item_class($settings){
            return 'pixe-type-button';
        }
        
        static function render_content($settings){
            $settings['link'] = empty($settings['link'])? array(): $settings['link'];
            
            $ret = '';
            if( !empty($settings['icon']['icon']) ){
                // background filter
                if( !empty($settings['background']) ){
                    pixe_set_background_color_filter($settings['background']);
                }

                $link_tag = pixe_get_link_tag($settings['link'], array(
                    'default-link-to' => 'custom'
                ));
                
                $ret .= $link_tag;
                $ret .= pixe_get_icon($settings['icon']['icon']);
                $ret .= empty($link_tag)? '': '</a>';
            }

            return $ret;
        }
    }

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