Your IP : 216.73.216.240


Current Path : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/
Upload File :
Current File : /home/juvelize/saulnois/tmp/install_695d2cf0b4957/src/View/Sky/Button.php

<?php
/*
* @package		Tech Fry Library
* @license		https://www.gnu.org/licenses/gpl-3.0.en.html
*/

namespace TechFry\Library\View\Sky;

defined('_JEXEC') or die;

class Button extends Bootstrap
{
    public $class_options = array('button_class', 'type', 'size', 'border_radius', 'shadow', 'hover', 'transition');

    public $attributes = [];

    public function display()
    {
        // data - text/title, url, icon, target, download
        // config - outline
        
        $this->data = (array) $this->data;
        
        // Change type for outline button
        if (isset($this->config['outline']) && $this->config['outline'])
        {
            $this->config['type'] = str_replace('btn', 'btn-outline', $this->config['type']);
        }

        $button_class = '';
        if (isset($this->config['button_class']) && $this->config['button_class'])
        {
            $button_class = str_contains($this->config['button_class'], 'btn ') ? '' : 'btn ';
        }

        $button_class .= 'btn ' . $this->get_class();

        // If $button_class is empty, set to default
        $button_class = $button_class ?: 'btn btn-primary';

        $button_text = $this->data['text'] ?? $this->data['title'] ?? $this->config['text'] ?? '';

        // If $button_text is empty, set to default
        $button_text = $button_text ?: 'Read More';
        
        // Add icon
        $icon = $this->data['icon'] ?? $this->config['icon'] ?? '';
        if ($icon)
        {
            $button_text = '<i class="' . $icon . '"></i>' . $button_text;
        }

        $url = $this->data['url'] ?? '#';
        $target = $this->data['target'] ?? $this->config['target'] ?? '';

        $output = '<a href="' . $url . '"';
        $output .= ' class="d-inline-flex align-items-center gap-1 ' . $button_class . '"';
        $output .= $target ? ' target="' . $target . '"' : '';

        foreach ($this->attributes as $k => $v)
        {
            $output .= ' ' . $k . '="' . $v . '"';    
        }

        $output .= (isset($this->data['download']) && $this->data['download']) ? ' download' : '';

        $output .= '>';
            $output .= $button_text;
        $output .= '</a>';

        return $output;
    }

    public function set_attributes($attributes)
    {
        $this->attributes = $attributes;
    }
}