<?php

if (!defined('BASEPATH')) {
    exit('No direct script access allowed');
}

/**
 * CSS parser
 *
 * @author Igor Ratsun
 */
class parser_add_css
{

    protected $ci;
    protected $aliases = array();
    protected $items = array();

    public function __construct($aliases = array())
    {
        $this->ci = & get_instance();
        $this->ci->config->load('config_assets');

        $default_aliases = array(
            'jquery_ui'             => $this->ci->config->item('css_jquery_ui'),
            'css_jquery_ui'         => $this->ci->config->item('css_jquery_ui'),
            'css_twitter_bootstrap' => $this->ci->config->item('css_twitter_bootstrap'),
        );

        $this->aliases = (is_array($aliases)) ? array_merge($default_aliases, $aliases) : $default_aliases;
    }

    public function parse()
    {
        $numargs = func_num_args();
        if ($numargs > 0) {
            foreach (func_get_args() as $file) {
                if (isset($this->aliases[$file])) {
                    $file = $this->aliases[$file];
                }

                if (!empty($file)) {
                    $this->items[] = $file;
                }
            }
            
            $js_css = $this->ci->load->library('js_css');
            $js_css->set_css_list(array_merge($this->items, $js_css->get_css_list()));
        }

        return;
    }

}
