import DialogTitle from "@material-ui/core/DialogTitle";
import DialogActions from "@material-ui/core/DialogActions";
import Button from "@material-ui/core/Button";
import Dialog from "@material-ui/core/Dialog";
import * as React from "react";
import {Inverter} from "../InverterConnectionPageTypes";

type MonitoredAreaDialogProps = {
    handleClose: () => void
    handleSubmit: (inverter: Inverter) => void
    dialogOpen: boolean
}


type MonitoredAreaDialogState = {
    newInverter: Inverter
}


export class NewInverterDialog extends React.Component<MonitoredAreaDialogProps, MonitoredAreaDialogState> {
    readonly state: MonitoredAreaDialogState = {
        newInverter: {
            id: 0,
            efficiency: 0,
            manufacturer: "",
            monitoredAreas: [],
        }
    };

    private handleClose = this.props.handleClose;

    private handleDialogChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
        this.setState({
            newInverter: {
                ...this.state.newInverter,
                [event.currentTarget.name]: event.currentTarget.value
            }
        });
    };


    render() {
        return <Dialog open={this.props.dialogOpen} onClose={this.handleClose}
                       aria-labelledby="form-dialog-title">
            <DialogTitle id="form-dialog-title">Create a new inverter</DialogTitle>
            <DialogActions>
                <Button onClick={this.handleClose} color="primary">
                    Cancel
                </Button>
                <Button onClick={() => this.props.handleSubmit(this.state.newInverter)} color="primary">
                    Save
                </Button>
            </DialogActions>
        </Dialog>
    }

}


