/*
 * This file is part of OsmInEdit, released under ISC license (see LICENSE.md)
 *
 * Copyright (c) Adrien Pavie 2019
 * Copyright (c) Daimler AG 2019
 *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 */

// import request from 'request-promise-native';
// import LocationCard from './view/common/LocationCard';
import App from './view/App'
import updateMarkerPos from './view/utils/moveMarker'
import connectTestTool from './view/utils/connectTestTool'
import uploadMapData from './view/utils/uploadMapdata'


/*
 * Global variables definition
 */
window.EDITOR_URL = window.location.origin + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/";
window.UNUSABLE_ICONS = new Set();


/*
 * Global variables definition
 */

window.EDITOR_URL = window.location.origin + window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + "/";
console.log("EDITOR_URL", window.EDITOR_URL)
window.UNUSABLE_ICONS = new Set();

// Dynamically load config file
// request(window.EDITOR_URL + "/config.json")
// 	.then(configTxt => {
// 		console.log(configTxt)
// 		window.CONFIG = JSON.parse(configTxt);
// 		window.EDITOR_NAME = window.CONFIG.editor_name;

// 		// Create app
// 		new App();
// 	})
// 	.catch(e => {
// 		console.error(e);
// 		alert("Can't load configuration file, please report this issue.");
// 	});

window.CONFIG = JSON.parse(`{
	"editor_name": "编辑器",
	"hash": "GIT_HASH",
	"data_min_zoom": 18,
	"map_initial_zoom": 18,
	"map_initial_latlng": [39.8729, 116.5141],
	"providers": {
		"bing": "AhsSQakuHuX3ozMBXC60w-hPk0KD_smZZbHLjb7mBFfeIwDKJnJn2_qK3qQfYfPZ"
	},
	"osm_api_url": "https://master.apis.dev.openstreetmap.org",
	"oauth_consumer_key": "sJF3Cp7VSQ-SVgy8UoNdMcVDl85-HW1IOZU6-Ec-ZiE",
	"oauth_secret": "hiapy7lMj09J7BHs4xjEmHG-JEOUMxpmx_C3QN-nCYQ",
	"always_authenticated": false
}`);

console.log(window.CONFIG)
window.EDITOR_NAME = window.CONFIG.editor_name;

// Create app
// new App({ el: 'root', id: '123' }).init();


const ThreeXMAP = {
	MAP: App,
	moveMarker: updateMarkerPos,
	connectTestTool: connectTestTool,
	uploadMap: uploadMapData,
}
export { ThreeXMAP }