/*
 * 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 React, { Component } from 'react';
import Tab from 'react-bootstrap/Tab';
import Tabs from 'react-bootstrap/Tabs';
import Container from 'react-bootstrap/Container';
import Form from 'react-bootstrap/Form';
import Button from 'react-bootstrap/Button';
// import Row from 'react-bootstrap/Row';
// import Col from 'react-bootstrap/Col';
import MapManageList from '../common/MapManageList'
import PubSub from 'pubsub-js';



function CreateMapForm(){
	let name = '';

	function createHandle(){
		if(name !== ''){
			PubSub.publish('editor.map.create', {id:window.editor_user.id, name: name});
		}
	}

	function changeHandle(e){
		name = e.target.value;
	}

	return (
		<>
			<Form>
				<Form.Group controlId="mapName">
					<Form.Label>地图名称</Form.Label>
					<Form.Control 
						type="text"
						placeholder=""
						aria-label="mapName"
						aria-describedby="mapName"
						onChange={e => {changeHandle(e)}} 
					/>
				</Form.Group>
				<Form.Label style={{color: 'red', fontSize: '12px'}}>请输入地图名称</Form.Label><br/><br/>
				<Button variant="primary" type="submit" onClick={createHandle}>
					创建
				</Button>
			</Form>
		</>
	)
}

class MapDashboardDialog extends Component {
	state = {
		list: null,
	}

	selectMode = (key, event) => {
		console.log(key);
	}

	render() {
		let activeTab = this.props.rightPanelTab;
		return (<div className="m-2">
				<h4>仪表盘</h4>
				{/* {console.log(activeTab)} */}
				<Tabs defaultActiveKey={activeTab}/*"manage"*/ className="dense-tabs" id="imagery-tab">
					<Tab eventKey="manage" title="地图管理">
						<Container className="mt-3 mb-3 p-0 d-flex overflow-hidden">
							<MapManageList />
						</Container>
					</Tab>

					<Tab eventKey="create" title="新建地图">
						<Container className="mt-3 mb-3 p-0 d-flex overflow-hidden">
							<CreateMapForm />
						</Container>
					</Tab>
				</Tabs>
			</div>);
	}
}

export default MapDashboardDialog;
