<?php

namespace ModulesGarden\HostingQuotaNotifications\App\Helper;

use ModulesGarden\HostingQuotaNotifications\Core\ModuleConstants;

/**
 * Class Injection
 *
 * @author Artur Pilch <artur.pi@modulesgarden.com>
 */
class Injection
{
    public static function includeLib($file, $type)
    {
        $details = self::injectionDetails($type);
        $path    = self::getBasePath() . DIRECTORY_SEPARATOR . $details['dir'] . DIRECTORY_SEPARATOR . $file . '.' . $details['suffix'];

        if (file_exists($path))
        {
            $file = file_get_contents($path);
            return '<' . $details['htmlTag'] . ' type="text/' . $details['type'] . '">' . $file . '</' . $details['htmlTag'] . '>';
        }
    }

    public static function injectionDetails($type)
    {
        switch ($type)
        {
            case 'js':
                return [
                    'dir'     => 'js',
                    'htmlTag' => 'script',
                    'type'    => 'javascript',
                    'suffix'  => 'js',
                ];
            case 'css':
                return [
                    'dir'     => 'css',
                    'htmlTag' => 'style',
                    'type'    => 'css',
                    'suffix'  => 'css',
                ];
        }
    }

    public static function getBasePath()
    {
        return ModuleConstants::getModuleRootDir() . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'assets';
    }
}