// Copyright 2020 Thomas Hintz
//
// This file is part of the Alpha Centauri Farming project.
//
// The Alpha Centauri Farming project is free software: you can
// redistribute it and/or modify it under the terms of the GNU General
// Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// The Alpha Centauri Farming project is distributed in the hope that
// it will be useful, but WITHOUT ANY WARRANTY; without even the
// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE.  See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with the Alpha Centauri Farming project.  If not, see
// <https://www.gnu.org/licenses/>.

import React from 'react'
import { connect } from 'react-redux'

import SpaceNode from './SpaceNode.jsx'

import { setMessagePanelSpace, mpMouse } from './actions.js'

class MessagePanel extends React.Component {
    render () {
        if (this.props.space !== null) {
            const panel = document.getElementById('message-panel'),
                  mpDims = this.props.mpDims;
            panel.style.top =
                (Math.min(Math.max(mpDims.mouseY, mpDims.minHeight + mpDims.padding),
                          mpDims.maxHeight)) + 'px';
            panel.style.left =
                (Math.min(Math.max(mpDims.mouseX, mpDims.minWidth + mpDims.padding),
                          mpDims.maxWidth)) + 'px';
            return (
                    <SpaceNode space={this.props.space} height='210px'
                               showtitle={true} orientation={''} />
            );
        } else {
            return null;
        }
    }
}

export default connect(
    state => state.farm,
    null
)(MessagePanel);
