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

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

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

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

        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'];
            }
            if( !empty($settings['button-preset']) ){
                $atts['button-preset'] = $settings['button-preset'];
            }
            
            // background filter
            if( !empty($settings['background']) ){
                pixe_set_background_color_filter($settings['background']);
            }

            // icon
            $icon_data = pixe_get_button_icon(
                empty($settings['icon'])? array(): $settings['icon'],
                empty($settings['button-preset'])? '': $settings['button-preset']
            );
            $icon = empty($icon_data['icon'])? '': pixe_get_icon($icon_data['icon']);

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

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

            return $ret;
        }

    }
    
    \Pixe_Builder::register_element('Pixebuilder\Element\Button');
    
