import { getRouteMap } from './route-map';
import { parseLocation } from './location';
import { createRoute } from './route';
import { _castString } from '../core/types';

/**
 * Match route against current path and assign params
 *
 * @param {RegExp} regex
 * @param {string} path
 * @param {Object} [params]
 * @returns {boolean}
 */
export function matchRoute (regex, path, params) {
	const match = path.match(regex);
	let i = 0;
	let length;

	if (! match) {
		return false;
	} else if (! params) {
		return true;
	}

	length = match.length;

	for (; i < length; i++) {
		const key = regex.keys[i - 1];
		const val = typeof match[i] === 'string' ? decodeURIComponent(match[i]) : match[i];

		if (key) {
			params[key.name] = _castString(val);
		}
	}

	return true
}

/**
 * Evaluate given path against registered route records
 *
 * @param {string} [path]
 * @returns {Object}
 */
export function match(path) {
	const { pathList, pathMap } = getRouteMap();
	const location = parseLocation(path);
	let i = 0;
	let routeCount = pathList.length;

	location.params = {};

	for (; i < routeCount; i++) {
		const record = pathMap[pathList[i]];

		// Add params to location object as part of check
		if (matchRoute(record.regex, location.path, location.params)) {
			return createRoute(location, record);
		}
	}

	// No match
	return createRoute(location);
}
@@ -372,24 +372,29 @@
 path, params
+ = %7B%7D
 ) %7B%0A%09const m
@@ -483,47 +483,8 @@
 ;%0A%09%7D
- else if (! params) %7B%0A%09%09return true;%0A%09%7D
 %0A%0A%09l

Remove early return/make params required