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

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

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

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

        static function item_class($settings){
            return 'pixe-type-button';
        }
        
        static function render_content($settings){

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

            // data atts
            $atts = array();
            if( !empty($settings['typo']['preset']) ){
                $atts['typo-preset'] = $settings['typo']['preset'];
            }
            
            // icon
            $icon = empty($settings['icon']['icon'])? '': pixe_get_icon($settings['icon']['icon']);

            // print item
            $ret  = pixe_get_link_tag($settings['link'], array(
                'class' => 'pixe-text-link',
                'data-atts' => $atts,
                'default-link-to' => 'custom',
                'always-show' => true
            ));

            // text
            $ret .= (!empty($icon) && (empty($settings['icon']['position']) || $settings['icon']['position'] != 'right'))? $icon: '';
            $ret .= empty($settings['text'])? esc_html__('Read More', 'pixebuilder'): $settings['text'];
            $ret .= (!empty($icon) && (!empty($settings['icon']['position']) && $settings['icon']['position'] == 'right'))? $icon: '';
            $ret .= '</a>';

            return $ret;
        }

    }

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