<?php

namespace Helpers\Additional;

use Helpers\Additional\Specifique\Specifique;
use Helpers\Additional\Externe\Externe;
use Helpers\Outil\ArrayHelper;
use Skeleton\Router;

final class Additional
{

    private Specifique $specifique;
    private Externe $externe;
    private Router $router;
    private \PDO $pdo;
    
    public function __construct(\PDO $pdo, Router $router)
    {
        $this->specifique = new Specifique();
        $this->pdo = $pdo;
        $this->router = $router;
        $this->externe = new Externe($this->pdo);
    }
    
    /**
     * getMenuLeft
     *
     * @param  string $module
     * @param  string $class
     * @param  string $function
     * @return array<mixed>
     */
    public function getMenuLeft(string $module, string $class, string $function)
    {
        
        $args = func_get_args();

        unset($args[0]);
        
        $argsWork = ArrayHelper::refactorArray($args);
        $menuInterne = $this->specifique->getMenuLeft($class, $function, $argsWork);
        $menuExterne = $this->externe->getMenuLeft($this->router, $args[5] ?? '', $module);
        
        return array_merge(
            !$menuInterne?[]:$menuInterne,
            is_array($menuExterne)?$menuExterne:[]
        );
    }

    /**
     * getMenuLeft
     *
     * @param  string $module
     * @param  string $class
     * @param  string $function
     * @return string
     */
    public function getMenuTop(string $module, string $class, string $function)
    {
        $args = func_get_args();

        unset($args[0]);

        $argsWork = ArrayHelper::refactorArray($args);

        $menuInterne = $this->specifique->getMenuTop($class, $function, $argsWork);
        $menuExterne = $this->externe->getMenuTop($this->router, $args[5] ?? '', $module);
        
        return $menuInterne.$menuExterne;
    }
}
