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

    class Title extends Item{

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

        static function get_default(){
            return array(
                'title' => 'Add your heading text here'
            );
        }

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

        static function get_icon(){
            return 'title';
        }
        
        static function render_content($settings){
            $ret = '';

            if( !empty($settings['title']) ){
                
                $tag = empty($settings['title-tag'])? 'h3': $settings['title-tag'];

                // background filter
                if( !empty($settings['background']) ){
                    pixe_set_background_color_filter($settings['background']);
                }

                // get icon
                $icon_data = empty($settings['title-icon'])? '': $settings['title-icon'];
                $icon = empty($icon_data['icon'])? '': pixe_get_icon($icon_data['icon'], array(
                    'icon-class' => 'pixe-inline-icon' . pixe_get_responsive_class($icon_data, 'icon-hide-on')
                ));
                $icon_position = empty($icon_data['position'])? 'left': $icon_data['position'];

                $atts = array();
                if( !empty($settings['title-typo']['preset']) ){
                    $atts['typo-preset'] = $settings['title-typo']['preset'];
                }
            
                $ret .= '<' . $tag . ' class="pixe-inline" ';
                $ret .= pixe_get_data_atts($atts);
                $ret .= '>';
                $ret .= $icon && in_array($icon_position, array('left', 'left-block', 'left-stretch'))? $icon: '';
                $ret .= do_shortcode($settings['title']);
                $ret .= $icon && in_array($icon_position, array('right', 'right-block', 'right-stretch'))? $icon: '';
                $ret .= '</' . $tag . '>';
            }
            return $ret;
        }

    }

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