<?php

require(ABSPATH.'/routes.php');

function resolvePath() {
	
	if (!empty($_GET))
	{
		if (!empty($_GET['page']))
		{
			$query = array_filter(explode('/', $_GET['page']));
			$page = explode('?',rtrim($_GET['page'],"/"))[0];
			
			foreach(Routes::get() as $path=>$control) {
				$has_var = strpos($path, '?') === false? false : true;
				$path = str_replace('?', '', $path);
				
				$found = strpos($page, $path) === false? false : true;
				$pathway = explode('/', $path);
				
				if(!$has_var) {
					if(count($pathway) != count($query)) {
						$found = false;
					}
				}
				
				if($found) {
					$controller = $control;
					
					$params = array();
					foreach($query as $param) {
						if(!in_array($param, $pathway)) {
							$params[] = $param;
						}
					}
				}
			}
		}
	}
	
	if(isset($controller)) {
		return array('controller' => $controller, 'params' => $params);
	} else {
		if (!empty($_GET))
		{
			if (!empty($_GET['page']))
			{            
				return return_404();
			}
		}
	}
	
    return false;
}