<?php

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

    class Site_Title extends Item{

        static function get_type(){
            return 'post';
        }

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

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

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

        static function item_class($settings){
            return 'pixe-heading';
        }

        static function render_content($settings){

            $settings['link'] = empty($settings['link'])? array(): $settings['link'];
            $title = get_bloginfo('name');

            $ret = '';
            if( !empty($title) ){

                $link_tag = pixe_get_link_tag($settings['link'], array(
                    'class' => 'pixe-inline',
                    'default-link-to' => 'none'
                ));

                // icon
                $icon_data = empty($settings['icon'])? '': $settings['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'];

                // get variables
                $tag = empty($settings['text-tag'])? 'h1': $settings['text-tag'];

                $atts = array();
                if( !empty($settings['text-typo']['preset']) ){
                    $atts['typo-preset'] = $settings['text-typo']['preset'];
                }

                // print
                $ret  = '<' . $tag . ' class="pixe-text' . (empty($link_tag)? ' pixe-inline': '') . '" ';
                $ret .= pixe_get_data_atts($atts);
                $ret .= '>';
                $ret .= $link_tag;
                $ret .= $icon && in_array($icon_position, array('left', 'left-block', 'left-stretch'))? $icon: '';
                $ret .= $title;
                $ret .= $icon && in_array($icon_position, array('right', 'right-block', 'right-stretch'))? $icon: '';
                $ret .= empty($link_tag)? '': '</a>';
                $ret .= '</' . $tag . '>'; 
            }

            return $ret;
        }

    }

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