/* 
 * JSweet - http://www.jsweet.org
 * Copyright (C) 2015 CINCHEO SAS <renaud.pawlak@cincheo.fr>
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package source.candies;

import static def.angularjs.Globals.angular;
import static jsweet.util.Lang.array;
import static jsweet.util.Lang.union;

import java.util.function.Consumer;

import def.angularjs.ng.route.IRoute;
import def.angularjs.ng.route.IRouteProvider;
import def.js.Array;

public class Angular {

	public static void main(String[] args) {

		Array<String> modules = new Array<>("app.controllers", "app.directives", "app.filters", "app.services", "Model");
		modules.forEach(module -> angular.module(module, new String[0]));
		modules.push("ngRoute");
		modules.push("ngAnimate");
		modules.push("ngMaterial");
		modules.push("socket-io");

		angular.module("app", array(modules));

		// ROUTING
		angular.module("app").config(new Object[] { "$routeProvider", (Consumer<IRouteProvider>) (IRouteProvider $routeProvider) -> {
			$routeProvider.when("/", new IRoute() {
				{
					templateUrl = union("../views/login.html");
					controller = union("app.controllers.LoginController as ctrl");
				}
			}).when("/chatroom", new IRoute() {
				{
					templateUrl = union("../views/chatroom.html");
					controller = union("app.controllers.ChatController as ctrl");
				}
			}).otherwise(new IRoute() {
				{
					redirectTo = union("/");
				}
			});
		} });
	}

}
