﻿import React, { memo, Fragment } from 'react'
import { withRouter } from 'react-router-dom';
import CajaTexto from '../../components/UI/cajaTexto/cajaTexto.jsx';
import { Notificacion } from '../../components/Util/Notificacion/Notificacion.jsx';
import { Registrar_DatosNotificacion, Obtener_ParamGenerales } from "../../request/MantenimientosRequest.jsx"
import { validarInt } from '../../components/Util/Util.jsx';
import TextArea from '../../components/UI/textArea/textArea.jsx';
class TabNotificaciones extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            defaultValueDias: 15,
            valueDias: 0,
            Datos: {
                Dias: { value: 15, attributes: { readOnly: false, focus: false, max: 365, min: 0, maxLength:3 } }
            },
            textoCorreoNotificacion: "",
            _isMounted: false
        }
        this.handleChangeTextArea = this.handleChangeTextArea.bind(this);
    }
    //Eventos
    onChangeInputInt = (e) => {
        const name = e.target.name;
        const value = e.target.value;
        let valido = false;

        valido = validarInt(value);
        if (valido) {
            let newAttributes = this.state.Datos[name].attributes;
            const Datos = Object.assign({}, this.state.Datos, { [name]: { value: value, attributes: newAttributes } })
            this.setState({ Datos });
        }
    }


    handleChangeTextArea(event) {
        this.setState({ textoCorreoNotificacion: event.target.value });
    }
    componentDidMount = async () => {

    }
    onFormatoInt = (valor) => {
        let _formato = "0,0";
        return this.formatearMontos(valor, _formato);
    };
    render() {
        const { Datos } = this.state;
        return (
            <Fragment>
                <div className="content">
                    <div className="content-box">
                        <div className="content-box box-secondary">
                            <div className="row">
                                <div className="col-md-12">
                                    <h3>Días para estimación de cupones consumibles</h3>
                                    <div className="row">
                                        <CajaTexto id="TextoDias"
                                            col="4"
                                            type="number"
                                            value={this.props.Datos.TextoDias.value}
                                            attributes={this.props.Datos.TextoDias.attributes}
                                            onChangeInput={this.props.handleChangeTextArea}
                                        />
                                    </div>
                                </div>
                            </div>
                            <h3>Correo notificación estimación de cupones</h3>
                            <div className="row">
                                <TextArea
                                    id='TextoNotificacion'
                                    col="12"
                                    value={this.props.Datos.TextoNotificacion.value}
                                    attributes={this.props.Datos.TextoNotificacion.attributes}
                                    onChangeInput={this.props.handleChangeTextArea}
                                    rows='3' />
                            </div>
                            <br />
                        </div>
                    </div>
                </div>
            </Fragment >
        );
    }
};
export default withRouter(memo(TabNotificaciones));