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/Dropdown.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 Dropdown extends Bootstrap
{
    public function display()
    {
        // data - 
        // config - trigger_text, trigger_class, trigger_icon, dropdown_tag

        $tag = isset($this->config['dropdown_tag']) && $this->config['dropdown_tag'] ? $this->config['dropdown_tag'] : 'div';  
        
        $output = '<' . $tag . ' class="dropdown">';

            $output .= $this->dropdown_trigger();

            $output .= '<ul class="dropdown-menu">';
            foreach ($this->data as $item)
            {
                $output .= $this->get_menu_item($item);
            }
            $output .= '</ul>';

        $output .= '</' . $tag . '>';

        return $output;
    }

    public function dropdown_trigger()
    {
        $output = '';
        
        $output .= '<a class="' . $this->config['trigger_class'] . ' dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">';
            if (isset($this->config['trigger_icon']) && $this->config['trigger_icon'])
            {
                $output .= '<i class="' . $this->config['trigger_icon'] . '"></i> ';
            }
            $output .= $this->config['trigger_text'];
        $output .= '</a>';

        return $output;
    }

    public function get_menu_item($item)
    {
        $output = '<li>';

        $link = $item->flink ?? $item->url ?? '';
        $title = $item->title ?? '';
        $icon = $item->menu_icon ?? $item->icon ?? '';
        $type = $item->type ?? '';

        if ($type == 'separator')
        {
            $output .= '<li><hr class="dropdown-divider"></li>';
        }
        elseif ($type == 'heading')
        {
            $output .= '<li><h6 class="dropdown-header">' . $title . '</h6></li>';
        }
        else
        {
            $output .= '<a href="' . $link . '" class="dropdown-item">';
            if ($icon)
            {
                $output .= '<i class="' . $icon . '"></i> ';
            }
            $output .= $title;
            $output .= '</a>';
        }

        $output .= '</li>';

        return $output;
    }
}